Should be simple but I'm hitting a block on this. The following code will pull all my equities but I cant figure out how to isolate QQQ from SPY. If I log the results of this and I own both QQQ and SPY it shows the following in the log: How do I isolate out QQQ from SPY from investedQQQequity?
investedQQQequity = [symbol for symbol, holding in self.Portfolio.items() if holding.IsLong and holding.Type == SecurityType.Equity]
Log:
investedQQQequity: [<QuantConnect.Symbol object at 0x7f3d277fbe00>, <QuantConnect.Symbol object at 0x7f3d277fc080>]
Yuri Lopukhov
you can add:
to list condition to only choose “QQQ”.
Or you can save SPY/QQQ symbol earlier when you add securities, like in initialization:
and compare symbol directly, without Value.
David Eldringhoff
I have the following code in my initialize section. I thought if I referenced your self.qqq_symbol and I owned a QQQ call, a QQQ put and QQQ stock that it would pull all three. Maybe it will just pull the equity only and not the options. I'll check that and see.
If I add that code I get an error, I tried to ("QQQ") also, same thing:
Build Error File: project/main.py Line:105 Column:120 - SyntaxError: invalid character in identifier
Yuri Lopukhov
I think your quotes around QQQ are not standard ones. Try typing them, not copy and paste from here. Maybe formatting here replaces regular quotes with non-standard ones.
David Eldringhoff
Good eye, thanks. I thought it was an error in the code but it was just the quotes, the cut and paste put in some weird quotes.
Thanks again for your help! worked great!
David Eldringhoff
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!