diff --git a/tests/test_perf_tracking.py b/tests/test_perf_tracking.py index e3ed169c..7f390c08 100644 --- a/tests/test_perf_tracking.py +++ b/tests/test_perf_tracking.py @@ -151,6 +151,17 @@ class TestSplitPerformance(unittest.TestCase): zp_math.tolerant_equals(8020, daily_perf['ending_cash'], 1)) + for i, result in enumerate(results): + for perf_kind in ('daily_perf', 'cumulative_perf'): + perf_result = result[perf_kind] + # prices aren't changing, so pnl and returns should be 0.0 + self.assertEqual(0.0, perf_result['pnl'], + "day %s %s pnl %s instead of 0.0" % + (i, perf_kind, perf_result['pnl'])) + self.assertEqual(0.0, perf_result['returns'], + "day %s %s returns %s instead of 0.0" % + (i, perf_kind, perf_result['returns'])) + class TestCommissionEvents(unittest.TestCase): diff --git a/zipline/finance/performance/period.py b/zipline/finance/performance/period.py index d154d475..a12a24d9 100644 --- a/zipline/finance/performance/period.py +++ b/zipline/finance/performance/period.py @@ -154,7 +154,11 @@ class PerformancePeriod(object): if split.sid in self.positions: # Make the position object handle the split. It returns the # leftover cash from a fractional share, if there is any. - leftover_cash = self.positions[split.sid].handle_split(split) + position = self.positions[split.sid] + leftover_cash = position.handle_split(split) + self._position_amounts[split.sid] = position.amount + self._position_last_sale_prices[split.sid] = \ + position.last_sale_price if leftover_cash > 0: self.handle_cash_payment(leftover_cash)