@@ -188,7 +188,7 @@ def _retry_read_url(url, retry_count, pause, name):
188188_HISTORICAL_YAHOO_URL = 'http://ichart.finance.yahoo.com/table.csv?'
189189
190190
191- def _get_hist_yahoo (sym , start , end , retry_count , pause ):
191+ def _get_hist_yahoo (sym , start , end , interval , retry_count , pause ):
192192 """
193193 Get historical data for the given name from yahoo.
194194 Date format is datetime
@@ -203,15 +203,15 @@ def _get_hist_yahoo(sym, start, end, retry_count, pause):
203203 '&d=%s' % (end .month - 1 ) +
204204 '&e=%s' % end .day +
205205 '&f=%s' % end .year +
206- '&g=d' +
206+ '&g=%s' % interval +
207207 '&ignore=.csv' )
208208 return _retry_read_url (url , retry_count , pause , 'Yahoo!' )
209209
210210
211211_HISTORICAL_GOOGLE_URL = 'http://www.google.com/finance/historical?'
212212
213213
214- def _get_hist_google (sym , start , end , retry_count , pause ):
214+ def _get_hist_google (sym , start , end , interval , retry_count , pause ):
215215 """
216216 Get historical data for the given name from google.
217217 Date format is datetime
@@ -322,14 +322,14 @@ def get_components_yahoo(idx_sym):
322322 return idx_df
323323
324324
325- def _dl_mult_symbols (symbols , start , end , chunksize , retry_count , pause ,
325+ def _dl_mult_symbols (symbols , start , end , interval , chunksize , retry_count , pause ,
326326 method ):
327327 stocks = {}
328328 failed = []
329329 for sym_group in _in_chunks (symbols , chunksize ):
330330 for sym in sym_group :
331331 try :
332- stocks [sym ] = method (sym , start , end , retry_count , pause )
332+ stocks [sym ] = method (sym , start , end , interval , retry_count , pause )
333333 except IOError :
334334 warnings .warn ('Failed to read symbol: {0!r}, replacing with '
335335 'NaN.' .format (sym ), SymbolWarning )
@@ -351,20 +351,20 @@ def _dl_mult_symbols(symbols, start, end, chunksize, retry_count, pause,
351351_source_functions = {'google' : _get_hist_google , 'yahoo' : _get_hist_yahoo }
352352
353353
354- def _get_data_from (symbols , start , end , retry_count , pause , adjust_price ,
354+ def _get_data_from (symbols , start , end , interval , retry_count , pause , adjust_price ,
355355 ret_index , chunksize , source ):
356356
357357 src_fn = _source_functions [source ]
358358
359359 # If a single symbol, (e.g., 'GOOG')
360360 if isinstance (symbols , (compat .string_types , int )):
361- hist_data = src_fn (symbols , start , end , retry_count , pause )
361+ hist_data = src_fn (symbols , start , end , interval , retry_count , pause )
362362 # Or multiple symbols, (e.g., ['GOOG', 'AAPL', 'MSFT'])
363363 elif isinstance (symbols , DataFrame ):
364- hist_data = _dl_mult_symbols (symbols .index , start , end , chunksize ,
364+ hist_data = _dl_mult_symbols (symbols .index , start , end , interval , chunksize ,
365365 retry_count , pause , src_fn )
366366 else :
367- hist_data = _dl_mult_symbols (symbols , start , end , chunksize ,
367+ hist_data = _dl_mult_symbols (symbols , start , end , interval , chunksize ,
368368 retry_count , pause , src_fn )
369369 if source .lower () == 'yahoo' :
370370 if ret_index :
@@ -377,7 +377,7 @@ def _get_data_from(symbols, start, end, retry_count, pause, adjust_price,
377377
378378def get_data_yahoo (symbols = None , start = None , end = None , retry_count = 3 ,
379379 pause = 0.001 , adjust_price = False , ret_index = False ,
380- chunksize = 25 ):
380+ chunksize = 25 , interval = 'd' ):
381381 """
382382 Returns DataFrame/Panel of historical stock prices from symbols, over date
383383 range, start to end. To avoid being penalized by Yahoo! Finance servers,
@@ -406,12 +406,17 @@ def get_data_yahoo(symbols=None, start=None, end=None, retry_count=3,
406406 If True, includes a simple return index 'Ret_Index' in hist_data.
407407 chunksize : int, default 25
408408 Number of symbols to download consecutively before intiating pause.
409+ interval : string, default 'd'
410+ Time interval code, valid values are 'd' for daily, 'w' for weekly,
411+ 'm' for monthly and 'v' for dividend.
409412
410413 Returns
411414 -------
412415 hist_data : DataFrame (str) or Panel (array-like object, DataFrame)
413416 """
414- return _get_data_from (symbols , start , end , retry_count , pause ,
417+ if interval not in ['d' , 'w' , 'm' , 'v' ]:
418+ raise ValueError ("Invalid interval: valid values are 'd', 'w', 'm' and 'v'" )
419+ return _get_data_from (symbols , start , end , interval , retry_count , pause ,
415420 adjust_price , ret_index , chunksize , 'yahoo' )
416421
417422
@@ -445,7 +450,7 @@ def get_data_google(symbols=None, start=None, end=None, retry_count=3,
445450 -------
446451 hist_data : DataFrame (str) or Panel (array-like object, DataFrame)
447452 """
448- return _get_data_from (symbols , start , end , retry_count , pause ,
453+ return _get_data_from (symbols , start , end , None , retry_count , pause ,
449454 adjust_price , ret_index , chunksize , 'google' )
450455
451456
0 commit comments