Hi
I have a question regarding how to remove the intraday data feed for tickers selected from universe selection. Here is an example to show my question.
I use universe selection to find equities that have fundamental data, have volume, have prices between 1 and 20, and have a market cap of less than 300MM. This part is done by Universe Selection. I request extended market hour data for the universe selection. In the OnData part, I summarize their pre-market volume and, at 9:31 EST, I check the open price for them. Based on conditions in the backtesting, I further reduce the universe to the ones that have at least 1MM pre-market volume and today's open is 19% higher than the previous day's close. This typically reduces my universe to a handful of tickers. However, because the universe selection returns me with more than 1k tickers, all their data is still fed into OnData. See log for details.
My question:
- Does the extra data points that are fed into the algorithm cause a longer running time in both backtesting and live trading?
- If yes for question 1, how can I avoid this by either re-structuring my codes or removing them from the data feed?
Really appreciate the help in advance!
Log from the attached backtesting:
2021-12-31 00:00:00 :Launching analysis for 276a4623d3bca7b441999f3e343bcf76 with LEAN Engine v2.5.0.0.134902021-12-31 00:00:00 :Coarse is run with 9406 tickers entered2021-12-31 00:00:00 :Fine is run with 3274 tickers entered2021-12-31 00:00:00 :OnSecuritiesChanged called with 1637 tickers in ActiveSecurities2021-12-31 00:00:00 :OnData with 1 tickers in data feed2021-12-31 05:00:00 :OnData with 155 tickers in data feed2021-12-31 06:00:00 :OnData with 200 tickers in data feed2021-12-31 07:00:00 :OnData with 243 tickers in data feed2021-12-31 08:00:00 :OnData with 384 tickers in data feed2021-12-31 09:00:00 :OnData with 545 tickers in data feed2021-12-31 09:31:00 :3 tickers are selected to trade2021-12-31 10:00:00 :OnData with 1447 tickers in data feed2021-12-31 11:00:00 :OnData with 1514 tickers in data feed2021-12-31 12:00:00 :OnData with 1541 tickers in data feed2021-12-31 13:00:00 :OnData with 1556 tickers in data feed2021-12-31 14:00:00 :OnData with 1570 tickers in data feed2021-12-31 15:00:00 :OnData with 1584 tickers in data feed2021-12-31 16:00:00 :OnData with 1596 tickers in data feed2021-12-31 17:00:00 :OnData with 1597 tickers in data feed2022-01-01 00:00:00 :OnData with 1 tickers in data feed2022-01-01 00:00:00 :Algorithm Id:(276a4623d3bca7b441999f3e343bcf76) completed in 37.61 seconds at 69k data points per second. Processing total of 2,594,663 data points.
Fred Painchaud
Hi Zinmin,
1- Yes. All subscribed data is subscribed so it must be processed, etc.
2- I believe you can unsubscribe from securities using self.RemoveSecurity(Symbol) on QCAlgorithm. It will certainly liquidate any holdings, that's in the doc, but I believe it may also unsubscribe from the data so it won't be in OnData anymore. Worth a try.
Fred
Xinmin Cai
Fred Painchaud Thanks Fred. I have tried RemoveSecurity. And it doesn't work. Based on what I know, RemoveSecurity only works for symbols that are added by AddEquity function call and doesn't affect the tickers selected by Universe.
Fred Painchaud
Hi Xinmin,
Ok. I looked around and did not find a way to explicitly remove a selection out of a Universe. It may be out there but well, did not find it. One way to maybe do it would be to flush any holdings you have with a security you want to remove and then add it to a list of security to remove and consult that list during the next Universe Selection to make sure you do not include any security from the list in the list returned by Universe Selection… I am not 100% sure but I guess that maybe then the security will not be in the Universe anymore. But I believe I read somewhere that securities stay in the Universe even though they are not returned by the filters anymore… Well, of course they do if you hold them but maybe even if you do not hold them. Anyway, not sure I read that or not and even less sure where 😊.
Another trick to try.
Fred
Xinmin Cai
@fred-painchaud Thanks for the info. I think it doesn't work out as the universe selection happens at midnight every day. What I really want is to reduce data feed load intraday after the market opens. Hope someone from the community has a solution for us. 😊
Xinmin Cai
Fred Painchaud
I think I found a way to do it. See attached backtesting. Essentially, as you mentioned, I return an empty list from fine selection to avoid subscribing to any data from universe selection. In the fine function, I subscribe to the selected tickers by using AddEquity(). Then, later remove them with RemoveSecurity. It looks like it is working fine. Just not sure if this way will cause any overhead for processing. Thanks for the tips.
Fred Painchaud
Glad to see you found a way and glad I helped.
Fred
Xinmin Cai
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!