If I add symbol XYZ by using AddEquity()
And at the mean time, I also use Universal Selection.
And if the coarse function filter out XYZ (so XYZ is one of the "RemovedSecurities"), does the program still receive XYZ data in OnData()?
Don't have an account? Join QuantConnect Today
QuantConnect Community Discussions
QUANTCONNECT COMMUNITY
LEAN is the open-source algorithmic trading engine powering QuantConnect. Founded in 2012 LEAN has been built by a global community of 180+ engineers and powers more than 300+ hedge funds today.
Join QuantConnect's Discord server for real-time support, where a vibrant community of traders and developers awaits to help you with any of your QuantConnect needs.
The Open-Quant League is a quarterly competition between universities and investment clubs for the best-performing strategy. The previous quarter's code is open-sourced, and competitors must adapt to survive.
No, Universal Selection won't remove securities added by AddEquity(); data for removed securities won't be received in OnData().
Continue ReadingRefer to our Research Guidelines for high quality research posts.
Create an account on QuantConnect for the latest community delivered to your inbox.
Sign Up Today
|
|
|||||||
|
|
||||||||
|
Would Universal Selection remove the security I added by AddEquity()?
JL Lord | March 2020
If I add symbol XYZ by using AddEquity()
And at the mean time, I also use Universal Selection.
And if the coarse function filter out XYZ (so XYZ is one of the "RemovedSecurities"), does the program still receive XYZ data in OnData()?
QuantConnectâ„¢ 2025. All Rights Reserved
Rahul Chowdhury
Hey JL Lord,
If you add a symbol using AddEquity, and that symbol has also been added and then removed in universe selection, you will still receive data from that symbol.
This is this case because QCAlgorithm has a UniverseManager that handles each universe in our algorithm separately. When we add a security using AddEquity, that security will belong to the "user defined" universe. On the other hand, the securities added by coarse universe selection belong to the "coarse universe". So when a symbol is removed from the "coarse universe", it isn't removed from the "user defined" universe, which means we still receive data from it.
You will receive data for a symbol added using AddEquity for the duration of the entire algorithm, unless you use RemoveSecurity(symbol)
to remove that symbol from your data subscriptions. Keep in mind RemoveSecurity(symbol) only works for securities in the "user defined" universe.
Here's an example which illuminates this. We added AMZN with AddEquity, and on the first day AMZN is also added in universe selection. But on the second day AMZN is removed from universe selection, however we still find AMZN in the slice data.
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.
JL Lord
Hi Rahul,
Thanks for the detailed explanation. From my understanding(especially after your reply above), after a symbol is added by Universal Selection, I don't need to call "AddEquity" for it.
However, in my testing, if I don't call "AddEquity" for those added securities in "OnSecuritiesChanged", I don't get the data from OnData().
Please see the attached project. The Universal Selection added "SPY", and in OnData(), I don't get SPY data at all. You can see it from the log:
2019-09-10 00:00:00 : Launching analysis for f93c1eff9197d5b6df882feebe561b6b with LEAN Engine v2.4.0.0.7517 2019-09-10 00:00:00 : Main->OnSecuritiesChanged(0), RemovedSecurities: 2019-09-10 00:00:00 : Main->OnSecuritiesChanged(1), AddedSecurities: SPY 2019-09-10 09:31:00 : time=9/10/2019 9:31:00 AM, no SPY key 2019-09-10 09:32:00 : time=9/10/2019 9:32:00 AM, no SPY key 2019-09-10 09:33:00 : time=9/10/2019 9:33:00 AM, no SPY key 2019-09-10 09:34:00 : time=9/10/2019 9:34:00 AM, no SPY key 2019-09-10 09:35:00 : time=9/10/2019 9:35:00 AM, no SPY key 2019-09-10 09:36:00 : time=9/10/2019 9:36:00 AM, no SPY key ... ... ...
Why is that?
So in my programs, I always call AddEquity() for AddedSecurities in OnSecuritiesChanged although I think it's quite weird (And not consistent with your reply above either)
Hope you can shed some light on this too. Thanks.
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.
Rahul Chowdhury
Hey JL Lord,
When a security is added by universe selection, its symbol is used to identify it in the slice data. You can see that SPY R735QTJ8XC9X is in slice data by iterating through the keys of the slice data.
public override void OnData(Slice data) { foreach(var symbol in data.Keys){ Debug($"Symbol: {symbol}, Ticker: {symbol.Value}, Data Contains Ticker?: {data.ContainsKey(symbol.Value)}"); } } //LOG 2019-09-10 09:31:00 : Symbol: SPY R735QTJ8XC9X, Ticker: SPY, Data Contains Ticker?: False
When we add a security using AddEquity(ticker), both the symbol and ticker are used to reference the security in the slice data.
For more detailed information about this, please check out the Security Identifiers section in the documentation.
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.
JL Lord
Thank a lot, Rahul. Now I totally got it.
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!