Currently, this is a common / advisable way to perform universe selection using indicator signals. You manually seed a SymbolData class with history data, and check for indicator signals in your fine selection function.
In detail:
- Coarse selection function
- Make initial selection with fundamental data
- Fine selection function
- Call history() to get data
- For each coarse symbol, create a SymbolData instance (contains indicators)
- Seed SymbolData with historical data
- Check for indicator signal
- If indicator fired, add to universe
- My Trading Function
- Process stocks that were added to my universe
This is good because we don't subscribe to securities data for all stocks; only ones that fire the signal. However, I don't like that i have to call history() all the time, since i've heard that it is not performant. I'd like to avoid calling history at all.
Would it be advisable to do this instead: use *only* Coarse selection, then AddEquity, check for signal, then call RemoveSecurity if no signal.
In detail:
- Coarse selection function
- Make initial selection with fundamental data
- My Custom selection Function
- For each coarse symbol, create a SymbolData instance (contains indicators)
- Use AddEquity to subscribe to data in EVERY SymbolData
- Once we have enough warmup data, check indicator for signal
- If indicator fired signal, add to my local dictionary
- If indicator did NOT fire signal, call RemoveSecurity()
- My Trading Function
- Process stocks that were added to my local dictionary
- Process stocks that were added to my local dictionary
Would this be a good idea? or would this run slower?
Louis Szeto
Hi .ekz
We would recommend following the "common/advisable way". Your suggestion would subscribe to a large amount of redundant data, causing both speed and memory problems. It will drastically increase your backtest time as every OnData/Alpha Model Update instance will process/loop through too much data. Instead of subscribing to the Security object, using .AdjustedPrice attribute in coarse objects is a better way to update the indicators. Please check this algorithm as an example.
Also, waiting for the completion of warm-up is not desirable. We would suggest manually warming up all indicators needed using the original way.
Best,
Louis Szeto
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.
.ekz.
Thanks for the response. I've decided to stick with the original way. Unfortunately I'm facing other issues, where I cannot send custom History bars (eg 5min bars) without using a consolidator --which is asking me to use AddEquity.
I think i will solve that by writing my own consolidator. Will share with the forum if/when done.
Christopher Phillips
Hi .ekz., Would you be able to provide an example of this best practice, programmatically?
Best,
Christopher
Louis Szeto
Hi .ekz
It is possible to create an indicator using consolidated bars without subscribing to the Security object. We suggest using a consolidator handler method to manually update your indicator. You may found the attached backtest as an example.
Best,
Louis Szeto
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.
.ekz.
Thanks Louis Szeto this is perfect.
Christopher Phillips : Unfortunately no examples that I can share. However, there are many examples in the forum. this google search should give you some useful results.
You could also start a new forum thread and i'm sure you'll get some responses.
.ekz.
I spoke to soon, Louis Szeto . The algo you shared was actually subscribing to the security object on line 10.
Modified it a bit, and with some help from Alexandre Catarino , i got it working.
See attached.
.ekz.
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!