From 44140d2de7d4ed34feeab7795ba6e2cbd7d6a042 Mon Sep 17 00:00:00 2001 From: Eddie Hebert Date: Wed, 30 Jan 2013 14:06:56 -0500 Subject: [PATCH] Fixes dates used in test factory for batch transforms. The test factory was creating non-market days. i.e. the date range spanned the weekend. Using pandas' BDay frequency so that only business days are created. This specific date range doesn't have holidays, so not accounting for holidays in the factory. Also, widens the range of the trading calendar to cover the test dates generated by the factory which include 1990. Previously the trading calendar began with 2002, meaning that holiday and weekend adjustments with the data exercised by the factory did not trigger when run with data in 1990. This does increase the memory footprint of the tradingcalendar module. However, only by a couple MB, so taking the hit there to enable correct behavior. --- tests/test_transforms.py | 12 ++++++++++-- zipline/utils/factory.py | 2 +- zipline/utils/tradingcalendar.py | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/tests/test_transforms.py b/tests/test_transforms.py index 26b01b27..233331c6 100644 --- a/tests/test_transforms.py +++ b/tests/test_transforms.py @@ -389,5 +389,13 @@ class TestBatchTransform(TestCase): expected_item = ((1, ), {'kwarg': 'str'}) self.assertEqual( algo.history_return_args, - [None, None, None, expected_item, expected_item, - expected_item]) + [ + # 1990-01-03 - window not full + None, + # 1990-01-04 - window not full + None, + # 1990-01-05 - window not full, 3rd event + None, + # 1990-01-08 - window now full + expected_item + ]) diff --git a/zipline/utils/factory.py b/zipline/utils/factory.py index 9ed25835..fa5822de 100644 --- a/zipline/utils/factory.py +++ b/zipline/utils/factory.py @@ -282,7 +282,7 @@ def create_test_df_source(trading_calendar=None): end = trading_calendar.last_close \ if trading_calendar else pd.datetime(1990, 1, 8, 0, 0, 0, 0, pytz.utc) - index = pd.DatetimeIndex(start=start, end=end, freq=pd.datetools.day) + index = pd.DatetimeIndex(start=start, end=end, freq=pd.datetools.BDay()) x = np.arange(0, len(index)) df = pd.DataFrame(x, index=index, columns=[0]) diff --git a/zipline/utils/tradingcalendar.py b/zipline/utils/tradingcalendar.py index 43a5e216..14b5a6a1 100644 --- a/zipline/utils/tradingcalendar.py +++ b/zipline/utils/tradingcalendar.py @@ -20,7 +20,7 @@ from datetime import datetime from dateutil import rrule from zipline.utils.date_utils import utcnow -start = datetime(2002, 1, 1, tzinfo=pytz.utc) +start = datetime(1990, 1, 1, tzinfo=pytz.utc) end = utcnow() non_trading_rules = []