Skip to content

Commit

Permalink
Merge pull request #1483 from bug-or-feature/bug_1482_mixed_index_df
Browse files Browse the repository at this point in the history
fixes backtest crash when attempting to estimate weights for expensive instruments
  • Loading branch information
bug-or-feature authored Jan 15, 2025
2 parents d1cd6ca + d50c197 commit 9969fdb
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions systems/portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,16 +727,20 @@ def _add_zero_weights_to_instrument_weights_df(
instrument_list_to_add = (
self.allocate_zero_instrument_weights_to_these_instruments()
)
weight_index = instrument_weights.index
new_pd_as_dict = dict(
[
(instrument_code, pd.Series([0.0] * len(weight_index)))
for instrument_code in instrument_list_to_add
]
)
new_pd = pd.DataFrame(new_pd_as_dict)

padded_instrument_weights = pd.concat([instrument_weights, new_pd], axis=1)
# weight_index = instrument_weights.index
# new_pd_as_dict = dict(
# [
# (instrument_code, pd.Series([0.0] * len(weight_index)))
# for instrument_code in instrument_list_to_add
# ]
# )
# new_pd = pd.DataFrame(new_pd_as_dict)
#
# padded_instrument_weights = pd.concat([instrument_weights, new_pd], axis=1)

padded_instrument_weights = copy(instrument_weights)
for zero_instr in instrument_list_to_add:
padded_instrument_weights[zero_instr] = 0.0

return padded_instrument_weights

Expand Down

0 comments on commit 9969fdb

Please sign in to comment.