Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes backtest crash when attempting to estimate weights for expensive instruments #1483

Merged

Conversation

bug-or-feature
Copy link
Collaborator

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:

from systems.provided.futures_chapter15.basesystem import futures_system
from sysdata.config.configdata import Config
from systems.trading_rules import TradingRule
from systems.provided.rules.ewmac import ewmac

my_config = Config(dict(
    start_date="2015-01-01",
    use_instrument_weight_estimates=True,
    forecast_post_ceiling_cost_SR=0.13,
    instruments=["CRUDE_W", "BUND", "GOLD", "NASDAQ", "NZD", "V2X"]
))

ewmac_16 = TradingRule(dict(function=ewmac, data=["rawdata.get_daily_prices",
                                                  "rawdata.daily_returns_volatility"],
                            other_args=dict(Lfast=16, Lslow=64)))
ewmac_32 = TradingRule(dict(function=ewmac, data=["rawdata.get_daily_prices",
                                                  "rawdata.daily_returns_volatility"],
                            other_args=dict(Lfast=32, Lslow=128)))

system = futures_system(config=my_config, trading_rules=[ewmac_16, ewmac_32])
system.accounts.portfolio()

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?

@tgibson11
Copy link
Contributor

Reviewed & did some testing. Your change does seem to properly implement the intent of the original code.

@bug-or-feature bug-or-feature merged commit 9969fdb into robcarver17:develop Jan 15, 2025
2 checks passed
@bug-or-feature
Copy link
Collaborator Author

@tgibson11 thanks Todd, appreciate the time taken

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants