Hi there,

I'm getting "Runtime Error: Algorithm took longer than 10 minutes on a single time loop" in the algorithm that does nothing but universe selection and runs for just one day. I'm attaching the source code.

The algorithm needs to warm up some indicators, so it performs a History call inside the coarse universe selection function. This History call is rather sizable: over 7K symbols, 30 daily bars each. It runs for around 6 minutes and returns successfully.

The fine universe selection function returns just a 100 symbols. It runs fine.

There is a function scheduled to run 10 minutes prior to market open. It runs okay.

Then the algorithm just hangs. It sits there for 10 minutes and exits with the Runtime Error. If I register another scheduled function to be called, say, 1 hour after the market open, it is never called.

Here is the log output:

05:53:58: Launching analysis for ... 06:00:16: Warmed up 7329 stocks 06:00:16: Fine collection is 5287 long 06:00:16: Today's universe: OPHT, PRTO, FFHL, CERC, CVM, ANY, RXII, ARDM, CLSN, CETC, RGSE, HTBX, NVLS, ARWR, SHIP, RVP, PACB, CLSD, DCTH, SCON, GEVO, XGTI, PFMT, OVAS, INOV, OHRP, OSG, FOLD, NURO, ATOS, ROSG, XBIT, FNCX, GALE, LIFE, CYTR, ONS, OHAI, YECO, MBOT, AIRG, ESES, BAS, ORPN, ATEC, MBRX, MGNX, MACK, CLRB, CTRV, VHC, ABEO, JAKK, HOTR, CAPN, SHLD, DTEA, ALBO, IFON, SIF, DXTR, BLCM, ABIL, IBIO, PLX, FCSC, RPRX, TEAR, OBLN, IMUC, QTM, PSIX, STAF, AMRS, NVIV, APHB, AGIO, WVE, XLRN, DLTH, PTX, SYMX, TVIA, PRKR, SBBP, MYOK, SELB, FTK, ETRM, RDUS, INSY, MXPT, STRM, ALN, FOSL, RKDA, LONE, PN, CLBS, TROV 06:01:40: before_trading_start: 51 06:01:40: Data for symbol DCIX has been limited due to numerical precision issues in the factor file. The starting date has been set to 7/4/2017. 06:02:03: Data for symbol DRYS has been limited due to numerical precision issues in the factor file. The starting date has been set to 1/21/2017. 06:10:20: Runtime Error: Algorithm took longer than 10 minutes on a single time loop.

Weird things:

  • before_trading_start function logs the size of Securities collection. For some strange reason, it is 51. This number seems to have nothing to do with the size of the universe. In the attached code it is 100, but if I change it to 10, the size of Securities collection is still 51 at this point.
  • Those "Data for symbol ..." warnings complain about the symbols that are not in the universe. What's going on?
  • In order to perform that History call in the coarse universe selection function, I have to call AddEquity() for each of the symbols. Initially, I was just calling RemoveSecurity() on them after I was done, but I noticed that "before_trading_start" was reporting that the Securities collection length was 7K+. So I added an additional Securities.Remove() call which brought the size of the Securities collection to this weird 51.
Things that snap it out of it:
  • If I pre-filter the coarse collection prior to the warm up step, it helps. This is not an option for me however since I must have the indicators calculated for the broadest collection of symbols.
  • If I comment out the lines 42 and 43 ("self.AddEquity" and "self.Schedule.On") it also helps. If I leave the line 42 intact and comment out only the "Schedule" line, it would hang still. Pretty weird.

Author