For the error below, what consists of “a single time loop”? I am having trouble understanding specifically where the 10 minutes starts counting from, and when the 10 minute timer stops counting. Tried searching the docs but was not able to locate the answer.
Runtime Error: Algorithm took longer than 10 minutes on a single time loop. CurrentTimeStepElapsed: 1.0 minutes
When timing my functions, it doesn't really look like I'm reaching 10 minutes total across all functions in any trading day before moving onto the next trading day (it's only at ~3 minutes), so perhaps I am misunderstanding the 10 minute timer.
Adam W
I think that error message may be a bit misleading.
IIRC, it's 10 minutes per time step (e.g. each call to `OnData()` has 10 minutes to complete). More expensive functions can be wrapped in `Train()`.
The caveat here is that during a backtest, the resource allocation (30-60 minutes?) is shared across all calls to `Train()` and Scheduled Events per backtest. So if each scheduled event takes ~3 minutes and it fires monthly, you would hit this error after 1-2 years of backtesting. In live trading, this will work just fine.
My suggestion would be to either move some of the logic into `OnData` instead of Scheduled Events, or split the backtest up into multiple backtests (use the ObjectStore if you need to retain states).
Big mak
Thanks Adam. Just to clarify something I'm confused about:
My suggestion would be to either move some of the logic into `OnData` instead of Scheduled Events,
I'm wondering why would this work? Does the backtester allow OnData to have more time to run than scheduled events? What's confusing me is that you also mentioned: e.g. each call to `OnData()` has 10 minutes to complete,
Big mak
Also, there's a chance I'm just hitting an upper resource limit since I'm roughly doing exactly what you described: quarterly calls, taking about 3-4 minutes each, and after 2.5 years it spits this error (even though each quarter is always under 10 minis). Total backtest time is roughly 30 minutes…but I've previously ran backtests over 2 hours without hitting any errors.
Any idea if there's a way to verify that this is truly the issue? I can't seem to find a limit to backtest time in the docs, only the number of nodes/RAM/processing speed etc.
Adam W
I'm wondering why would this work? Does the backtester allow OnData to have more time to run than scheduled events? What's confusing me is that you also mentioned: e.g. each call to `OnData()` has 10 minutes to complete,
Right, it's a bit subtle:
This means that in backtesting, you basically have 30-60 minutes (depending on server I think) to run all the Scheduled Events/Train per backtest. It's okay if the total backtest time is longer than this.In live trading, algorithm time is the same as real-time so as long as you are under the compute time allocation in the scheduled functions/training it's okay.
--For your specific case (<10 mins each scheduled event), it's a very simple workaround:
Big mak
Gotcha, I'll try to put my time-heavy code in OnData then at some point this coming weekend and I'll comment back the results. Hopefully it should work out. Thanks for the explanation Adam!
Big mak
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!