Skip to content

calculation of Buy & Hold Return #327

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

Closed
zillionare opened this issue Apr 30, 2021 · 4 comments
Closed

calculation of Buy & Hold Return #327

zillionare opened this issue Apr 30, 2021 · 4 comments
Labels
bug Something isn't working good first issue Good for newcomers Hacktoberfest https://hacktoberfest.digitalocean.com

Comments

@zillionare
Copy link

this is how Buy & Hold Return is calculated:

        c = data.Close.values
        s.loc['Buy & Hold Return [%]'] = (c[-1] - c[0]) / c[0] * 100  # long-only return

so it's calced use day one and the day last.

Expected Behavior

Buy & Hold Return is used for compare with strategy gain. Therefore, I guess they should started at same time, since the strategy get enough data to work on.

Take cross ma strategy example, use 5 days for short line and 10 days for long line, the strategy can only works from 10th trade day. It's better to make comparision since this day

  • Backtesting version: 0.3
@eervin123
Copy link
Contributor

One thing that is nice about the backtesting.py framework is its generic nature. I have a number of strategies and many of them rely on the entire period for a representative benchmark.

Having said that, it would be nice if it were easier to specify a "warming period" for both the strategy and the benchmark. I haven't come up with a clean way to do that as of yet, though I haven't really dug into it.

As a feature, it would be kind of nice if there were a way to specify a warming_period as a number of candles to ignore for the plot and stats and thus the benchmark, etc.

eg.

bt = Backtest(df, smacross, warming_period=10)

Full disclosure, I've been away for a bit so this might have been implemented in a different fashion. I'm not sure.

@kernc
Copy link
Owner

kernc commented Aug 16, 2021

a way to specify a warming_period as a number of candles to ignore for the plot and stats

Done automatically like this for backtest and plots:

# Skip first few candles where indicators are still "warming up"
# +1 to have at least two entries available
start = 1 + max((np.isnan(indicator.astype(float)).argmin(axis=-1).max()
for _, indicator in indicator_attrs), default=0)

Therefore, you can extend the warming period by containing an indicator with sufficient leading np.nan values.

I like that it's done automatically. We should extended it more consistently into stats (Buy&Hold computation) — PR welcome.

@kernc kernc added enhancement New feature or request bug Something isn't working and removed enhancement New feature or request labels Aug 16, 2021
@flexelem
Copy link

I am also having a similar issue because of non configurable warming up period explained in #477

@kernc kernc added Hacktoberfest https://hacktoberfest.digitalocean.com good first issue Good for newcomers labels Oct 7, 2021
@Orchid420
Copy link

Orchid420 commented Oct 18, 2022

Has the feature "warming_period" been added to make sure that the strategy tested and the buy and hold strategy are calculated on the same timeframe?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers Hacktoberfest https://hacktoberfest.digitalocean.com
Projects
None yet
Development

No branches or pull requests

5 participants