Runtime Error: Algorithm took longer than 10 minutes I’m encountering this runtime error on QuantConnect:
Algorithm took longer than 10 minutes on a single time loop.
I’ve already moved all of the heavy work—processing daily bars for ~700 universes and generating indicators—out of OnData() and into an End‑of‑Day scheduled event (1 minute after market close), but the error persists.
Proposed solution:
Split the daily‑bar processing into three smaller scheduled tasks:
Process the first ~250 symbols at 1 minute after close
Process the next ~250 symbols at 11 minutes after close
Process the remaining ~200 symbols at 21 minutes after close
Will this batching strategy help me stay within the 10‑minute loop limit and follow best practices for load‑balancing heavy work? I’m open to any other suggestions if this staggered schedule isn’t optimal.
def on_data(self, data):
"""Cache daily bars and update VIX values."""
if self.vix in data:def process_daily_bars_1(self):
"""Process cached daily bars after market close."""
if self.IsWarmingUp or not self.daily_bars:
return
batch = dict(islice(self.daily_bars.items(), batch_size))
self._process_slice(batch)
def process_daily_bars_2(self):
"""Process cached daily bars after market close."""
if self.IsWarmingUp or not self.daily_bars:
return
batch = dict(islice(self.daily_bars.items(), 251, 251 + batch_size))
self._process_slice(batch)
self.Schedule.On(
self.DateRules.EveryDay(),
self.TimeRules.AfterMarketClose("SPY", 1),
self.process_daily_bars_1
)
self.Schedule.On(
self.DateRules.EveryDay(),
self.TimeRules.AfterMarketClose("SPY", 11),
self.process_daily_bars_2
)
Mia Alissi
Here’s an in-depth answer for Dharmesh, including advice and an illustrative code sketch:
Yes, batching your daily bar processing into several scheduled events—each handling a distinct slice of your universe—is a well-established QuantConnect best practice for avoiding single-time-loop 10-minute runtime errors.
Why This Works
process_daily_bars_1, 2, 3will not add up their processing times—they have their own limits.How to Implement Correctly
Defining Clean Batches:
Example:
batch_size = ceil(N / K). Each batch operates on its[start:end]index range.Consistent State Checks:
self.IsWarmingUpanddaily_barsnon-emptiness in each scheduled handler.Diagnostics:
self.Debug) and batch size for each scheduled batch to monitor and tune performance.If you still encounter slowness:
Clean Code Sketch
Below is a pattern showing how to split your universe into 3 non-overlapping batches, each scheduled as a separate after-market-close event.
Additional Tips
In summary:
Your batching/scheduling strategy is the right direction. Just use dynamic batch boundaries and log each batch’s timing for monitoring. You’re on the right path!
Sources: Algorithm Engine - QuantConnect.com, Event Handlers - QuantConnect.com, Opening Range Breakout for Stocks in Play, Scheduled Events - QuantConnect.com, Key Concepts - QuantConnect.com
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.
Dharmesh Khalasi
what is the QuantConnect’s Training ?
Dharmesh Khalasi
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!