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

I tried working around this by passing in a set of dates corresponding to the time period I want to rebalance on #388

Closed
aelkholy opened this issue Oct 5, 2022 · 0 comments

Comments

@aelkholy
Copy link

aelkholy commented Oct 5, 2022

[Did not mean to close this adding my comment, so reopening]

So I have the following code:

strategy = bt.Strategy("strategy", [
                            bt.algos.RunDaily(),
                            bt.algos.SelectWhere(indicator_df),
                            bt.algos.WeighTarget(reset_to_datetime(weights_df)),
                            bt.algos.Rebalance()
                        ])
default_t = bt.Backtest(strategy, reset_to_datetime(stocks_df), initial_capital=initial_capital)
default_res = bt.run(default_t)

Stocks_df, indicator_df and weights_df all have daily data in them. Changing the line from bt.algos.RunDaily() to bt.algos.RunYearly gives me the same results when I was expecting the rebalancing frequency to change.

I tried working around this by passing in a set of dates corresponding to the time period I want to rebalance on

strategy = bt.Strategy("strategy", [
                                    bt.algos.RunOnDate(dates),
                                    bt.algos.SelectWhere(indicator_df),
                                    bt.algos.WeighTarget(reset_to_datetime(weights_df)),
                                    bt.algos.Rebalance()
                                ])

This throws an error here because it's checking if the date is in a list containing one element, which is a pd.datetimeindex I believe.

Originally posted by @aelkholy in #387 (comment)

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

No branches or pull requests

2 participants