Hi,
I have created a simple strategy that just collects prices for 11 tickers 5 mins before market close using a scheduled event. (The idea is that this is the template for “doing stuff” intra-day at specific times for specific symbols).
Resolution is 1 min, but only one event is happening per day (5 mins before close).
Time stats for length of backtest (B2-8 node, CPU is at 100%, but RAM < 200M )
- 1 month = 20 seconds (⅓ of a minute)
- 3 months = 180s = 3mins (time taken 10 x 1 month)
- 9 months = 30 mins (time taken 10 x 3 months)
I expect a 9 month back test to take (approximately) 9x the time of a 1 month back test. Even if it took 20x, that would be ok. But 100x??
I thought it must be memory/garbage collection but memory is fine (< 200M). (Some time improvement if I don't use self.Debug….but my main point still holds).
I can only assume that I am doing something fundamentally dumb. Can someone please make a suggestion on how to improve something so fundamental. Thanks.
Explanation of code:
This is all that is is doing (full code in attached back test):
def OnData(self, data):
self.Schedule.On(
self.DateRules.EveryDay("SPY"),
self.TimeRules.BeforeMarketClose("SPY", 5),
self.get_data
)
def get_data(self):
#now get latest prices
T=self.Time
price_list = []
for symbol in self.symbols:
price_list.append(self.Securities[symbol.Value].Price)
self.Debug(str(T) + ' ' + str(price_list))
Christopher mathew
This should be ignored.
The problem was my scheduled events were inside my OnData. (Thanks for Cole S for pointing this out).
But putting the scheduled event under Initialize 1 year now takes < 20s.
Correct result is attached.
Louis Szeto
Hi Christopher
You just need to put the schedule method under initialize method. If you put it under OnData, it'll schedule on every slice you receive. You have linearly increase 1 function to run everyday in every backtesting minute, so everyday 5 minutes before market close, you'll have 390+ functions to run compare to the previous trade day. This increase your backtest time linearly in day scale.
Cheers
Louis
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.
Christopher mathew
Thanks Louis.
Christopher mathew
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!