@@ -133,7 +133,7 @@ def get_quote_yahoo(symbols):
133
133
134
134
135
135
def _get_hist_yahoo (sym = None , start = None , end = None , retry_count = 3 ,
136
- pause = 0 ):
136
+ pause = 0 , ** kwargs ):
137
137
"""
138
138
Get historical data for the given name from yahoo.
139
139
Date format is datetime
@@ -195,11 +195,22 @@ def _adjust_prices(hist_data, price_list=['Open', 'High', 'Low', 'Close']):
195
195
196
196
def _calc_return_index (price_df ):
197
197
"""
198
- Return a returns index from a input price df or series.
198
+ Return a returns index from a input price df or series. Initial value
199
+ (typically NaN) is set to 1.
199
200
"""
200
-
201
- ret_index = price_df .pct_change ().add (1 ).cumprod ()
202
- ret_index .ix [0 ] = 1
201
+ df = price_df .pct_change ().add (1 ).cumprod ()
202
+ mask = ~ df .ix [1 ].isnull () & df .ix [0 ].isnull ()
203
+ df .ix [0 ][mask ] = 1
204
+
205
+ #Check for first stock listings after starting date of index in ret_index
206
+ #If True, find first_valid_index and set previous entry to 1.
207
+ if (~ mask ).any :
208
+ for sym in mask .index [~ mask ]:
209
+ tstamp = df [sym ].first_valid_index ()
210
+ t_idx = df .index .get_loc (tstamp ) - 1
211
+ df [sym ].ix [t_idx ] = 1
212
+
213
+ ret_index = df
203
214
return ret_index
204
215
205
216
@@ -258,16 +269,17 @@ def get_components_yahoo(idx_sym):
258
269
259
270
260
271
def get_data_yahoo (symbols = None , start = None , end = None , retry_count = 3 , pause = 0 ,
261
- adjust_price = False , ret_index = False , chunksize = 25 , ** kwargs ):
272
+ adjust_price = False , ret_index = False , chunksize = 25 ,
273
+ ** kwargs ):
262
274
"""
263
275
Returns DataFrame/Panel of historical stock prices from symbols, over date
264
276
range, start to end. To avoid being penalized by Yahoo! Finance servers,
265
277
pauses between downloading 'chunks' of symbols can be specified.
266
278
267
279
Parameters
268
280
----------
269
- symbols : string, list -like object (list, tupel , Series), or DataFrame
270
- Single stock symbol (ticker), list -like object of symbols or
281
+ symbols : string, array -like object (list, tuple , Series), or DataFrame
282
+ Single stock symbol (ticker), array -like object of symbols or
271
283
DataFrame with index containing stock symbols.
272
284
start : string, (defaults to '1/1/2010')
273
285
Starting date, timestamp. Parses many different kind of date
@@ -290,7 +302,7 @@ def get_data_yahoo(symbols=None, start=None, end=None, retry_count=3, pause=0,
290
302
291
303
Returns
292
304
-------
293
- hist_data : DataFrame (str) or Panel (list -like object, DataFrame)
305
+ hist_data : DataFrame (str) or Panel (array -like object, DataFrame)
294
306
"""
295
307
296
308
def dl_mult_symbols (symbols ):
@@ -444,7 +456,8 @@ class Options(object):
444
456
445
457
# Fetch call and put data with expiry from now to 8 months out
446
458
>>> forward_calls, forward_puts = aapl.get_forward_data(8,
447
- ... call=True, put=True)
459
+ ... call=True, put=True)
460
+
448
461
"""
449
462
450
463
def __init__ (self , symbol ):
0 commit comments