Hello, new subscriber here,
I'm testing an opening range breakout trade, so I need minutely data… but only usually for the first hour or so of the day. By then my trade is finished. Is there a way to skip ahead to the next day in backtesting? It takes incredibly long to run the backtest with minutely data for any significant number of days.
Thanks in advance for any ideas or insights!
--Benjamin
Mia Alissi
Hello Benjamin,
You're correct that using minute-level data for a full trading day can slow down backtesting, especially if you're only interested in the first hour of trading. One way to speed up your backtest is to use the
Schedule.On
method to define a specific time period during which your algorithm should be active.Here's an example of how you might set this up:
In this example, the
EveryMarketOpen
function, which contains your trading logic, will only be called at market open. You can adjust theTimeRules
to specify the period during which your algorithm should be active.Please note that this approach will only speed up your backtest if your algorithm doesn't do any processing outside of the scheduled times. If your algorithm is still slow, it might be due to other computations that are being performed throughout the trading day.
For more information on scheduled events, you can refer to the QuantConnect documentation.
I hope this helps! Let me know if you have any other questions.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Benjamin
Hi Mia, thanks for the reply! In your example code, where would I place calls to add the minute-level data AddEquity/AddOptions calls? Would that still go in the Initialize routine?
And you said to put my algorithm logic in EveryMarketOpen, but I still need to use OnData to look at the minute data coming in, right?
Mia Alissi
Hello Benjamin,
Yes, you're correct. The calls to
AddEquity
orAddOptions
would still go in theInitialize
method. This is where you set up your data subscriptions. Here's an example:As for your second question, yes, you would still use the
OnData
method to process the incoming data. TheEveryMarketOpen
method is where you would place the logic that you want to execute at the market open. However, theOnData
method will be called for each data point that comes in. Here's an example:In this example, the
OnData
method checks if the data for "SPY" is available and then processes the data accordingly. You can adjust this to suit your specific needs.I hope this clarifies things! Let me know if you have any other questions.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Benjamin
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!