Share a new discussion
I am looking for some help if possible, I am attempting to add multiple underlying securities to an options strategy. All of the options that would get filtered would be the same parameters. I have the below backtest, but I am only getting one security to fire and actually trade options.
I am sure I am missing something simple as my Python skills are a little rusty. Any help is greatly appreciated.
Thanks
Joe Gentile
forgot to attach the backtest.
Mia Alissi
From the provided code, it seems like you're trying to trade options on multiple securities ("NVDA" and "TSLA"). However, in your
OnData
method, you're only trading options for the last security added, which is "TSLA". This is because you're settingself.symbol
tooption.Symbol
in yourInitialize
method, andoption
is the last option object created in your for loop.To trade options for all added securities, you need to loop over your
self.symbols
list in yourOnData
method. Here's a simplified example of how you can do this:In this example,
TradeCallOption
andTradePutOption
are modified to take an additionalsymbol
argument, which is used instead ofself.symbol
.Please note that this is a simplified example and you might need to adjust your
TradeCallOption
andTradePutOption
methods to correctly handle trading options for multiple securities.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.
Joe Gentile
Awesome thank you, I will give that a try.
Mia Alissi
You're welcome, Joe! If you have any more questions or run into any issues, feel free to ask. Happy coding!
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.
Joe Gentile
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!