I want to add the constituents of SPY into a list like the below, but so far I've only learnt how to do this manually line by line like the below. Is there a way which I can add them all at once?
symbols = []
symbols.append(self.AddEquity('AAPL', Resolution.Daily).Symbol)
symbols.append(self.AddEquity('MSFT', Resolution.Daily).Symbol)
symbols.append(self.AddEquity("AMZN", Resolution.Daily).Symbol)
Nico Xenox
Hey mcdawgzy,
you either have a list with all the symbols and add the QC symbols to a list:
or you just simply use QC 500 algorithm that should include all constituents automatically.
Best,
Nico
Mcdawgzy
Hi Nico XenoxÂ
Does this mean I can simply add the below two lines and then can store this in a symbol/list?
Apologies for the silly question, first time playing with UniverseSelection
Nico Xenox
Hey mcdawgzy,
guessing that you want the QC symbol in the list you could add the newly entered stocks in the OnSecuritiesChanged into your list and remove them if they leave the universe or access them like this:
Â
Best,
Nico
Yuri Lopukhov
You can also do it like this:
There are more details in documentation:Â
Mcdawgzy
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!