Skip to content

Issue when using next() #1184

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
ed5555 opened this issue Nov 26, 2024 · 2 comments
Closed

Issue when using next() #1184

ed5555 opened this issue Nov 26, 2024 · 2 comments
Labels
invalid This is not a (valid) bug report

Comments

@ed5555
Copy link

ed5555 commented Nov 26, 2024

When trying to run a simple 200 MA strategy, I want make a purchase at the onset of the data. However, the next function iterates only from the onset of the data+200 days.

Is there a way to do this?

Thank you

@sachaRfd
Copy link

sachaRfd commented Dec 8, 2024

When implementing a strategy with 200 MA, you need to account for the initial calculation period. For example with a 200-day MA, you need the data of the previous 200 days before you can generate a valid MA value. During the calculation period, the MA will be NaN - so no signal. This means the strategy will only work from 200 days onwards.

Quick fixes in your case would be to either:

  1. Collect more historical data to your desired start-date.
  2. Pick a later start date where you already have the previous 200 data points.

Hope that makes sense.

@kernc
Copy link
Owner

kernc commented Jan 28, 2025

Indeed, mind the warning on Backtest.run.

Welcome a better position where this note should be placed.

@kernc kernc closed this as completed Jan 28, 2025
@kernc kernc added the invalid This is not a (valid) bug report label Jan 28, 2025
mmortall pushed a commit to mmortall/backtesting-ext.py that referenced this issue Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This is not a (valid) bug report
Projects
None yet
Development

No branches or pull requests

3 participants