BUG: Fix backwards compatibility in get_data_yahoo · pandas-dev/pandas@b921d1a (original) (raw)
`@@ -132,23 +132,23 @@ def get_quote_yahoo(symbols):
`
132
132
`return DataFrame(data, index=idx)
`
133
133
``
134
134
``
135
``
`-
def _get_hist_yahoo(name=None, start=None, end=None, retry_count=3,
`
``
135
`+
def _get_hist_yahoo(sym=None, start=None, end=None, retry_count=3,
`
136
136
`pause=0):
`
137
137
`"""
`
138
138
` Get historical data for the given name from yahoo.
`
139
139
` Date format is datetime
`
140
140
``
141
141
` Returns a DataFrame.
`
142
142
` """
`
143
``
`-
if(name is None):
`
``
143
`+
if(sym is None):
`
144
144
`warnings.warn("Need to provide a name.")
`
145
145
`return None
`
146
146
``
147
147
`start, end = _sanitize_dates(start, end)
`
148
148
``
149
149
`yahoo_URL = 'http://ichart.yahoo.com/table.csv?'
`
150
150
``
151
``
`-
url = yahoo_URL + 's=%s' % name + \
`
``
151
`+
url = yahoo_URL + 's=%s' % sym + \
`
152
152
`'&a=%s' % (start.month - 1) + \
`
153
153
`'&b=%s' % start.day + \
`
154
154
`'&c=%s' % start.year + \
`
`@@ -203,17 +203,18 @@ def _calc_return_index(price_df):
`
203
203
`return ret_index
`
204
204
``
205
205
``
206
``
`-
def get_components_yahoo(idx_sym='^DJI'):
`
``
206
`+
def get_components_yahoo(idx_sym):
`
207
207
`"""
`
208
``
`-
Returns DataFrame containing list of component information for index
`
209
``
`-
represented in idx_sym from yahoo. Includes component symbol
`
``
208
`+
Returns DataFrame containing list of component information for
`
``
209
`+
index represented in idx_sym from yahoo. Includes component symbol
`
210
210
` (ticker), exchange, and name.
`
211
211
``
212
212
` Parameters
`
213
213
` ----------
`
214
214
` idx_sym : str
`
215
``
`-
Index symbol, default '^DJI' (Dow Jones Industrial Average)
`
``
215
`+
Stock index symbol
`
216
216
` Examples:
`
``
217
`+
'^DJI' (Dow Jones Industrial Average)
`
217
218
` '^NYA' (NYSE Composite)
`
218
219
` '^IXIC' (NASDAQ Composite)
`
219
220
``
`@@ -256,44 +257,48 @@ def get_components_yahoo(idx_sym='^DJI'):
`
256
257
`return idx_df
`
257
258
``
258
259
``
259
``
`-
def get_data_yahoo(symbols=None, start=None, end=None, adjust_price=False,
`
260
``
`-
ret_index=False, chunk=25, pause=0, **kwargs):
`
``
260
`+
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):
`
261
262
`"""
`
262
263
` Returns DataFrame/Panel of historical stock prices from symbols, over date
`
263
264
` range, start to end. To avoid being penalized by Yahoo! Finance servers,
`
264
265
` pauses between downloading 'chunks' of symbols can be specified.
`
265
266
``
266
267
` Parameters
`
267
268
` ----------
`
268
``
`-
symbols : string, list-like object (list, tupel, Series), DataFrame
`
``
269
`+
symbols : string, list-like object (list, tupel, Series), or DataFrame
`
269
270
` Single stock symbol (ticker), list-like object of symbols or
`
270
``
`-
DataFrame with index containing of stock symbols
`
``
271
`+
DataFrame with index containing stock symbols.
`
271
272
` start : string, (defaults to '1/1/2010')
`
272
273
` Starting date, timestamp. Parses many different kind of date
`
273
274
` representations (e.g., 'JAN-01-2010', '1/1/10', 'Jan, 1, 1980')
`
274
``
`-
end : string, (defaults to today)
`
``
275
`+
end : string, (defaults to today)
`
275
276
` Ending date, timestamp. Same format as starting date.
`
``
277
`+
retry_count : int, default 3
`
``
278
`+
Number of times to retry query request.
`
``
279
`+
pause : int, default 0
`
``
280
`+
Time, in seconds, to pause between consecutive queries of chunks. If
`
``
281
`+
single value given for symbol, represents the pause between retries.
`
276
282
` adjust_price : bool, default False
`
277
``
`-
Adjust all prices in hist_data ('Open', 'High', 'Low', 'Close') via
`
278
``
`-
'Adj Close' price. Adds 'Adj_Ratio' column and drops 'Adj Close'.
`
279
``
`-
ret_index: bool, default False
`
280
``
`-
Include a simple return index 'Ret_Index' in hist_data.
`
281
``
`-
chunk : int, default 25
`
``
283
`+
If True, adjusts all prices in hist_data ('Open', 'High', 'Low', 'Close')
`
``
284
`+
based on 'Adj Close' price. Adds 'Adj_Ratio' column and drops
`
``
285
`+
'Adj Close'.
`
``
286
`+
ret_index : bool, default False
`
``
287
`+
If True, includes a simple return index 'Ret_Index' in hist_data.
`
``
288
`+
chunksize : int, default 25
`
282
289
` Number of symbols to download consecutively before intiating pause.
`
283
``
`-
pause : int, default 0
`
284
``
`-
Time, in seconds, to pause between consecutive chunks.
`
285
``
`-
**kwargs: additional arguments to pass to _get_hist_yahoo
`
286
290
``
287
291
` Returns
`
288
292
` -------
`
289
293
` hist_data : DataFrame (str) or Panel (list-like object, DataFrame)
`
290
294
` """
`
``
295
+
291
296
`def dl_mult_symbols(symbols):
`
292
297
`stocks = {}
`
293
``
`-
for sym_group in _in_chunks(symbols, chunk):
`
``
298
`+
for sym_group in _in_chunks(symbols, chunksize):
`
294
299
`for sym in sym_group:
`
295
300
`try:
`
296
``
`-
stocks[sym] = _get_hist_yahoo(name=sym, start=start,
`
``
301
`+
stocks[sym] = _get_hist_yahoo(sym, start=start,
`
297
302
`end=end, **kwargs)
`
298
303
`except:
`
299
304
`warnings.warn('Error with sym: ' + sym + '... skipping.')
`
`@@ -302,11 +307,16 @@ def dl_mult_symbols(symbols):
`
302
307
``
303
308
`return Panel(stocks).swapaxes('items', 'minor')
`
304
309
``
305
``
`-
#If a scalar (single symbol, e.g. 'GOOG')
`
``
310
`+
if 'name' in kwargs:
`
``
311
`+
warnings.warn("Arg 'name' is deprecated, please use 'symbols' instead.",
`
``
312
`+
FutureWarning)
`
``
313
`+
symbols = kwargs['name']
`
``
314
+
``
315
`+
#If a single symbol, (e.g., 'GOOG')
`
306
316
`if isinstance(symbols, (str, int)):
`
307
317
`sym = symbols
`
308
``
`-
hist_data = _get_hist_yahoo(sym, start=start, end=end, **kwargs)
`
309
``
`-
#Multiple symbols
`
``
318
`+
hist_data = _get_hist_yahoo(sym, start=start, end=end)
`
``
319
`+
#Or multiple symbols, (e.g., ['GOOG', 'AAPL', 'MSFT'])
`
310
320
`elif isinstance(symbols, DataFrame):
`
311
321
`try:
`
312
322
`hist_data = dl_mult_symbols(Series(symbols.index))
`