Back

Automatic option assignment on expiration, Invalie status, and backtest issues

Hi,

I have a vertical spread strategy and it works fine until one of the short put options gets assigned. After the assignment no more trades happen, and the status for the assigned option is Invalid. And the unrealized proft is non-zero even after liquidity. 

Looks like the option assignment breaks the algorithm in diferent ways. Should the option assignment be treated differently?

Thanks

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 Nick, 

Please post your algorithm by attaching the backtest. This will allow the community and us to help address your questions more efficiently. 

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 Alethea, I have provided a picture of the option getting assigned. After this assignment all other orders will be invalid. for some reason I can't attach the algo here. and her eis the message in the console: Backtest Handled Error: The security with symbol 'SPY 170818P00243000' is marked as non-tradable.  Please let me know if I can provide more info. Thanks

70944_1568829648.jpg

0

Hi Nick,

We cannot figure out the exact issue without the backtest. You should be able to attach your backtest using the Attach Backtest button. If not, please copy and paste your code using the Insert Code Snippet button.

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 Alethea, I founda  workaround which is exercising the option few minutes before expiration/assignmnet.

0

Hi Nick,

I am glad you found a workaround for the issue. Would you mind still sharing your backtest or an example code that reproduces the bug with us? We would love to look into the issue so you and the community members can avoid the workaround in the future!

Thanks for your support.

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 Alethea,

I don't have the previous code anymore. but I think the main issue was using weeklyoption prices. After switching to setfliter most issues are gone.

Thanks

0

Hi,

Is there a way to find out if the option is assigned (on the sell leg), so that I can immediatley close the other position (buy leg)?  Thanks

0

Hi Nick,

Once an option is exercised, an order event will be created and passed to OnOrderEvent method where we can identified it by OrderType. Below is the example code you can try:
 

def OnOrderEvent(self, orderEvent):
order = self.Transactions.GetOrderById(orderEvent.OrderId)
if order.Type == OrderType.OptionExercise:
pass # do stuff

Attached backtest is a simple example of how to use OnOrderEvent. In the Log page, it outputs excercised options information.

Hope this helps!

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 Yiyun,

Thanks for your answer. Is there a way to be only informed of assignment.

OrderType.OptionExercise doesn't recognize between exercise and assignment. I am interested only when assignmnet happens.When looking at the Orders, here is how the Tag for the assigned option looks like: Simulated option assignment before expiration - Adjusting(or removing) the exercised/assigned option - Option Exercise/Assignment

But using self.log in orderEvent, it removes: 

Simulated option assignment before expiration

 

0

Hi Nick M ,

Sorry about the wait.

The OrderEvent object has a boolean attribute, IsAssignment, that can be used to distinguish the two:

def OnOrderEvent(self, orderEvent):
if orderEvent.IsAssignment:
order = self.Transactions.GetOrderById(orderEvent.OrderId)
if order.Type == OrderType.OptionExercise:
self.Log(str(order))

 

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.


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