diff --git a/tests/test_perf_tracking.py b/tests/test_perf_tracking.py index ca526942..8528d7ae 100644 --- a/tests/test_perf_tracking.py +++ b/tests/test_perf_tracking.py @@ -1075,3 +1075,12 @@ class TestPerformanceTracker(unittest.TestCase): # Check that transactions aren't emitted for previous events. self.assertEquals(0, len(messages[1]['intraday_perf']['transactions']), "The second message should have no transactions.") + + # Ensure that period_close moves through time. + # Also, ensure that the period_closes are the expected dts. + self.assertEquals(foo_event_1.dt, + messages[0]['intraday_perf']['period_close'], + messages[0]) + self.assertEquals(foo_event_2.dt, + messages[1]['intraday_perf']['period_close'], + messages[1]) diff --git a/zipline/finance/performance.py b/zipline/finance/performance.py index a5179f69..6ac8fad4 100644 --- a/zipline/finance/performance.py +++ b/zipline/finance/performance.py @@ -130,6 +130,7 @@ omitted). """ +import itertools import logbook import math @@ -205,7 +206,16 @@ class PerformanceTracker(object): """ Main generator work loop. """ - for date, snapshot in stream_in: + # Set the simulation date to be the first event we see. + peek_date, peek_snapshot = next(stream_in) + self.saved_dt = peek_date + + # Stitch back together the generator by placing the peeked + # event back in front + stream = itertools.chain([(peek_date, peek_snapshot)], + stream_in) + + for date, snapshot in stream: new_snapshot = [] for event in snapshot: