From dc11534d54532ff96786a209b7f77ef9bd056135 Mon Sep 17 00:00:00 2001 From: Ben McCann Date: Thu, 4 Apr 2013 12:18:19 -0700 Subject: [PATCH] ENH: Provide better defaults for load_from_yahoo. Set the default end date to current date, so that trading on 'fresh' data is the default case. Set the default begin date at 1/1/1990, since that is when the treasury benchmark data is first available. --- zipline/utils/factory.py | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/zipline/utils/factory.py b/zipline/utils/factory.py index 6acc7342..af72c80b 100644 --- a/zipline/utils/factory.py +++ b/zipline/utils/factory.py @@ -15,7 +15,7 @@ """ -Factory functions to prepare useful data for tests. +Factory functions to prepare useful data. """ import pytz import random @@ -334,28 +334,29 @@ def _load_raw_yahoo_data(indexes=None, stocks=None, start=None, end=None): http://wesmckinney.com/files/20111017/notebook_output.pdf """ - if indexes is None: - indexes = {'SPX': '^GSPC'} - if stocks is None: - stocks = ['AAPL', 'GE', 'IBM', 'MSFT', 'XOM', 'AA', 'JNJ', 'PEP', 'KO'] - if start is None: - start = pd.datetime(1993, 1, 1, 0, 0, 0, 0, pytz.utc) - if end is None: - end = pd.datetime(2002, 1, 1, 0, 0, 0, 0, pytz.utc) + assert indexes is not None or stocks is not None, """ +must specify stocks or indexes""" - assert start < end, "start date is later than end date." + if start is None: + start = pd.datetime(1990, 1, 1, 0, 0, 0, 0, pytz.utc) + + if not start is None and not end is None: + assert start < end, "start date is later than end date." data = OrderedDict() - for stock in stocks: - print stock - stkd = DataReader(stock, 'yahoo', start, end).sort_index() - data[stock] = stkd + if stocks is not None: + for stock in stocks: + print stock + stkd = DataReader(stock, 'yahoo', start, end).sort_index() + data[stock] = stkd + + if indexes is not None: + for name, ticker in indexes.iteritems(): + print name + stkd = DataReader(ticker, 'yahoo', start, end).sort_index() + data[name] = stkd - for name, ticker in indexes.iteritems(): - print name - stkd = DataReader(ticker, 'yahoo', start, end).sort_index() - data[name] = stkd return data