Skip to content

Commit c09f7ab

Browse files
author
John Ricklefs
authored
Revert "BUG: Capital change deltas rely on cash, not portfolio_value" (#1470)
This reverts commit 5b1aa5e. The paradigm is: we're calculating a new capital base for the performance period. We are therefore using the total portfolio_value, not just the cash, to calculate the difference from the specified target as the algorithm has meaningful holdings.
1 parent 9a301dc commit c09f7ab

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

tests/test_algorithm.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,7 +2167,7 @@ def make_equity_daily_bar_data(cls):
21672167
)
21682168

21692169
@parameterized.expand([
2170-
('target', 127000.0), ('delta', 50000.0)
2170+
('target', 153000.0), ('delta', 50000.0)
21712171
])
21722172
def test_capital_changes_daily_mode(self, change_type, value):
21732173
sim_params = factory.create_simulation_parameters(
@@ -2215,9 +2215,8 @@ def order_stuff(context, data):
22152215
capital_change_packets[0],
22162216
{'date': pd.Timestamp('2006-01-06', tz='UTC'),
22172217
'type': 'cash',
2218-
'target': value if change_type == 'target' else None,
2219-
'delta': 50000.0
2220-
})
2218+
'target': 153000.0 if change_type == 'target' else None,
2219+
'delta': 50000.0})
22212220

22222221
# 1/03: price = 10, place orders
22232222
# 1/04: orders execute at price = 11, place orders
@@ -2321,10 +2320,10 @@ def order_stuff(context, data):
23212320
)
23222321

23232322
@parameterized.expand([
2324-
('interday_target', [('2006-01-04', 1899.0)]),
2323+
('interday_target', [('2006-01-04', 2388.0)]),
23252324
('interday_delta', [('2006-01-04', 1000.0)]),
2326-
('intraday_target', [('2006-01-04 17:00', 908.0),
2327-
('2006-01-04 18:00', 1408.0)]),
2325+
('intraday_target', [('2006-01-04 17:00', 2186.0),
2326+
('2006-01-04 18:00', 2806.0)]),
23282327
('intraday_delta', [('2006-01-04 17:00', 500.0),
23292328
('2006-01-04 18:00', 500.0)]),
23302329
])
@@ -2487,10 +2486,10 @@ def order_stuff(context, data):
24872486
)
24882487

24892488
@parameterized.expand([
2490-
('interday_target', [('2006-01-04', 1899.0)]),
2489+
('interday_target', [('2006-01-04', 2388.0)]),
24912490
('interday_delta', [('2006-01-04', 1000.0)]),
2492-
('intraday_target', [('2006-01-04 17:00', 908.0),
2493-
('2006-01-04 18:00', 1408.0)]),
2491+
('intraday_target', [('2006-01-04 17:00', 2186.0),
2492+
('2006-01-04 18:00', 2806.0)]),
24942493
('intraday_delta', [('2006-01-04 17:00', 500.0),
24952494
('2006-01-04 18:00', 500.0)]),
24962495
])

zipline/algorithm.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,8 @@ def calculate_capital_changes(self, dt, emission_rate, is_interday,
862862
if capital_change['type'] == 'target':
863863
target = capital_change['value']
864864
capital_change_amount = target - \
865-
(self.updated_portfolio().cash - portfolio_value_adjustment)
865+
(self.updated_portfolio().portfolio_value -
866+
portfolio_value_adjustment)
866867
self.portfolio_needs_update = True
867868

868869
log.info('Processing capital change to target %s at %s. Capital '

0 commit comments

Comments
 (0)