diff --git a/tests/test_perf_tracking.py b/tests/test_perf_tracking.py index 1cfacfcd..ca526942 100644 --- a/tests/test_perf_tracking.py +++ b/tests/test_perf_tracking.py @@ -1069,3 +1069,9 @@ class TestPerformanceTracker(unittest.TestCase): messages += tracker.process_event(foo_event_3) self.assertEquals(2, len(messages)) + + self.assertEquals(1, len(messages[0]['intraday_perf']['transactions']), + "The first message should contain one transaction.") + # 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.") diff --git a/zipline/finance/performance.py b/zipline/finance/performance.py index 5bbac867..5d5ad5c4 100644 --- a/zipline/finance/performance.py +++ b/zipline/finance/performance.py @@ -245,7 +245,8 @@ class PerformanceTracker(object): # its own configuration down the line. # Naming as intraday to make clear that these results are # being updated per minute - _dict['intraday_perf'] = self.todays_performance.to_dict() + _dict['intraday_perf'] = self.todays_performance.to_dict( + self.saved_dt) return _dict @@ -634,10 +635,13 @@ class PerformancePeriod(object): return rval - def to_dict(self): + def to_dict(self, dt=None): """ Creates a dictionary representing the state of this performance period. See header comments for a detailed description. + + Kwargs: + dt (datetime): If present, only return transactions for the dt. """ rval = self.__core_dict() @@ -647,7 +651,14 @@ class PerformancePeriod(object): # we want the key to be absent, not just empty if self.keep_transactions: - transactions = [x.__dict__ for x in self.processed_transactions] + if dt: + # Only include transactions for given dt + transactions = [x.__dict__ + for x in self.processed_transactions + if x.dt == dt] + else: + transactions = [x.__dict__ + for x in self.processed_transactions] rval['transactions'] = transactions return rval