This seems like such an easy question but I can't locate the answer anywhere. I've tried self.Symbol which just returns <bound method, 'symbol'> and self.Portfolio.Key since self.Portfolio.Keys returns the entire list of symbols. Neither of those work. How can I get the current symbol that is present? In OnData, I believe it is possible to use data.Symbol? Is there something similar that I can use to get the current symbol in a Rebalancing function? Thanks for the help!
Note: I'm developing in python
Shile Wen
Hi Nathan,
I am not sure what you mean by the Current Symbol. However, if you’d like to convert a ticker string into a Symbol, use self.Symbol(ticker). You can also store the Symbol in initialize using self.symbolSPY = self.AddEquity('SPY', Resolution.Daily).Symbol. To get the list of all Symbols you can use symbols = [symbol for symbol in self.Securities.Keys], and to get just one Symbol from this list, do symbols[0]. If you’d like to iterate through the symbols, do for curr_symbol in symbols: …Â
Best,
Shile Wen
Nathan Miller
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!