mirror of
https://github.com/wassname/catalyst.git
synced 2026-07-18 12:20:12 +08:00
BUG: Update perf period state when positions are changed by splits
Otherwise, self._position_amounts will be out of sync with position.amount, etc. That value is used to calculate pnl and returns, so test for them.
This commit is contained in:
@@ -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):
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user