Slow access to history?

Hey there,
I am in the process of making a gap-on-open trading algorithm and I wanted to start (obviosly) with the gap-datection part. I wrote a class for detecting and evaluating a gap between two TradeBars, which works just fine. In the actual algorithm, I schedule two events, one at market close, one after market open.

So far, so good. As a universe, I chose the S&P500, but now there is the follwing problem:

First the AtMarketClose. It gets one 1-hour Tradebar from every security in the universe and stores it. This takes a huge amount of time while backtesting, around one minute per simlutated day, only with 150 securities. With all 500, the backtest crashes after a few days of simulation because of the 1GB memory limit (even if I call the Garbage Collector with GC.Collect()). If I only use 150 securities, the backtest runs a bit longer and then crashes after 11 minutes of runtime, because of a timeout by the lean backend.

The detection of the gaps works just fine, its only the large amount of memory and time, that is cosumed by the algorithm, for no apearent reason. Maybe it is the history access, but does anybody know for sure?

Here is the backtest, I cant embedd it, because of the error:

Hopefully someone is able to help me figure it out...

Update Backtest

Update Backtest


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.


This discussion is closed