Hello,
I realized that subscribing to options data update dramatically affects the execution time.
I only need it for first 30 minutes of trading day, rest of the day there is execution of orders based on on the first 30 minutes data. Also I use manual universe.
Is there a smart way to only allow options data to update first 30 minutes only?
Thanks,
Ahmed.
Vladimir
Ahmed Khattab,
If your algorithm subscribed to minute data and you put this line in OnData()
The OnData() for US Equities will run only in the first 30 minutes after market open (9:31- 9:59) like in attached backtest.
The best way to get help quickly is to attach a backtest.
If you are satisfied with my answer, please accept it and don't forget to like it.
Fred Painchaud
Hi Ahmed,
Just making sure I understand your post properly.
It affects execution time wrt what? If it is wrt subscribing to daily data, yes of course since there are many more data points…
You are using only the first 30 minutes of data each day for your trading but you trade all day right? Or do you also only trade during the first 30 minutes?
Fred
Ahmed Khattab
Thanks Vladimir and Fred.
So regardless of my algorithm in the OnData(), as I add self.AddOption(symbol, Resolution.Minute) in the initalize() method it causes an increase in time execution as I think the options data keep updating in the background all the time even if not used.
I did test this by keeping the OnData() function empty and comparing time with only added options in initialize or not adding them and there is a big difference.
So I was checking if there is a better solution like maybe allowing options data to update only in the background for first 30 minutes of each day. I found that there is self.RemoveOptionContract(), but the problem is that it causes liquidation and cancellation of orders which is not needed.
Fred Painchaud
Hi Ahmed,
After you call one of the Add*() method (like AddOptions), you subscribe to some data, i.e, you ask LEAN to feed that data to your algo. LEAN does that by calling OnData with whatever data there is for the current time slice.
If you only put code between 9 < hour ≤ 10 in OnData, that code is only going to be executed during that time. If that's where you trade, you won't trade at other times. If you unsubscribe, you can't trade that asset anymore either.
If you need help with some code in particular which you find too slow, you can post it if you like.
Keep reading on QC/Lean and happy backtesting/trading!
Fred
.ekz.
I believe calling RemoveSecurity() will unsubscribe.
Ahmed Khattab
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!