fixes backtest crash when attempting to estimate weights for expensive instruments #1483
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposed fix for #1482
Scenario is you're running a backtest to estimate instrument weights, and attempting to exclude expensive instruments. So minimum working example to exhibit the problem:
It looks like the existing code in
systems.portfolio.py
lines 730 - 739 is supposed to create a new column series for the expensive instrument (V2X in the example) full of zeros, and append it to the dataframe of weights. But the datetime index does not get created properly, so the new column ends up adding a whole bunch of new rows, with integer keys instead of dates. That causes a crash later down the line when the weights df is used.My proposed solution (lines 741 - 743) uses a simpler method to add the column of zeros.
Could someone else review this and make sure I'm not missing anything, or doing something stupid? @tgibson11, @vishalg? @robcarver17 if you're around?