Back

Keeping Track of Options Assignments

This is a bit of a simple syntax question. I've been toying around with a simple strategy in Python where I sell options but I run into difficulty tracking when those short positions are assigned. I'm essentially looking for a way to return a boolean answer when my options are assigned so I can close the assigned position later down the line. I've searched through the docs but couldn't work out how to lay out the answer in code. The OptionPositionAssigned event seemed promising but calling Brokerage.OptionPositionAssigned.IsAssignment() doesn't seem to work

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.


Hi Jason.

To keep track of your options contract positions, use:

option_invested = [x.Key.Value for x in self.Portfolio if x.Value.Invested and x.Value.Type==SecurityType.Option]

In the attached backtest, I demonstrate how to select and short ATM Call option contract and subsequently list the contract name, quantity, and price at the end of each day.  You can close the short ATM Call option position by using self.MarketOrder().

1


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