Fixes trading day generation logic in test source.

This uses more of @fawce's original logic from record_var branch.

TODO: Add unit test to ensure that this function generates only
market days.
This commit is contained in:
Eddie Hebert
2013-01-31 13:06:15 -05:00
parent c298cfda03
commit 69b87b859b
+5 -3
View File
@@ -34,6 +34,7 @@ def date_gen(start=datetime(2006, 6, 6, 12, tzinfo=pytz.utc),
"""
Utility to generate a stream of dates.
"""
one_day = timedelta(days=1)
cur = start
# yield count trade events, all on trading days, and
@@ -50,9 +51,10 @@ def date_gen(start=datetime(2006, 6, 6, 12, tzinfo=pytz.utc),
cur = cur + delta
cur_midnight = cur.replace(hour=0, minute=0, second=0)
# skip over any non-trading days
if cur_midnight not in trading_days:
next_day_index = trading_days.searchsorted(cur_midnight)
cur_midnight = trading_days[next_day_index]
while cur_midnight not in trading_days:
cur = cur + one_day
cur_midnight = cur.replace(hour=0, minute=0, second=0)
cur = cur.replace(day=cur_midnight.day)
def mock_prices(count):