Back

Getting Option Contract Info From Portfolio Holding Objects in Python

I am trying to get the information about the option contracts: namely the expiry date and the type (whether they are puts or calls), straight from the Portfolio holding object.  So far in backtesting I have had to save the option contracts that I trade to my own list and access that contract info later on to check the expiry.  The idea is I want to be able to close out the trade before the option expires.  I am trying to improve the algo so that it doesn't need to "remember" the contracts from when they are traded.  The algo should be able to tell the expiry of the contracts just from accessing them in the Portfolio object.  

 

The way I am currently accessing the portfolio holdings is like this:

 

for sym in self.Portfolio.Keys:
holding = self.Portfolio[sym]
if holding.HoldStock and holding.Symbol.SecurityType == SecurityType.Option:
'''We have an Option'''

 

I would like to find attributes in the holding object like holding.Symbol.Type ( put or call ) and holding.Symbol.Expiry.  Does something like this exist?  It doesn't seem like it according to the documentation here: https://www.quantconnect.com/lean/documentation/topic7826.html

 

I am afraid that storing my traded options in my own list will not work when I need to take the live strategy offline and restart, etc.  The algo should be able to know the details of the option without having to save them from the time of the trade, imo.  

 

Thanks!

Update Backtest








Update Backtest





0

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.


Loading...

This discussion is closed