@@ -132,7 +132,7 @@ def parse_yahoo_historical(fh, adjusted=True, asobject=False):
132
132
return d .view (np .recarray ) # Close enough to former Bunch return
133
133
134
134
135
- def fetch_historical_yahoo (ticker , date1 , date2 , cachename = None ):
135
+ def fetch_historical_yahoo (ticker , date1 , date2 , cachename = None , dividends = False ):
136
136
"""
137
137
Fetch historical data for ticker between date1 and date2. date1 and
138
138
date2 are date or datetime instances, or (year, month, day) sequences.
@@ -143,6 +143,9 @@ def fetch_historical_yahoo(ticker, date1, date2, cachename=None):
143
143
cachename is the name of the local file cache. If None, will
144
144
default to the md5 hash or the url (which incorporates the ticker
145
145
and date range)
146
+
147
+ set dividends=True to return dividends instead of price data. With
148
+ this option set, parse functions will not work
146
149
147
150
a file handle is returned
148
151
"""
@@ -160,11 +163,17 @@ def fetch_historical_yahoo(ticker, date1, date2, cachename=None):
160
163
d2 = (date2 .month - 1 , date2 .day , date2 .year )
161
164
162
165
163
- urlFmt = 'http://table.finance.yahoo.com/table.csv?a=%d&b=%d&c=%d&d=%d&e=%d&f=%d&s=%s&y=0&g=d&ignore=.csv'
166
+ if dividends :
167
+ g = 'v'
168
+ verbose .report ('Retrieving dividends instead of prices' )
169
+ else :
170
+ g = 'd'
171
+
172
+ urlFmt = 'http://table.finance.yahoo.com/table.csv?a=%d&b=%d&c=%d&d=%d&e=%d&f=%d&s=%s&y=0&g=%s&ignore=.csv'
164
173
165
174
166
175
url = urlFmt % (d1 [0 ], d1 [1 ], d1 [2 ],
167
- d2 [0 ], d2 [1 ], d2 [2 ], ticker )
176
+ d2 [0 ], d2 [1 ], d2 [2 ], ticker , g )
168
177
169
178
170
179
if cachename is None :
0 commit comments