In attached backtest that trades SPX bull put spread there is a huge dip in account equity on Jan 24. From the logs it seems to be due to early assignment:
Simulated option assignment before expiration - Automatic Assignment.
But what does early assignment even mean in this case, given SPX has no shares to assign?
If early assignment is disabled in the backtest, the huge dip doesn't occur, and everything works as expected.
Should QC avoid trying to simulate early assignment for index options?
Mia Alissi
In the context of options trading, early assignment refers to the situation where the option holder exercises their option before its expiration date. This typically happens when the option is in-the-money, meaning the underlying stock's price is beyond the strike price of the option. In such cases, the QuantConnect backtesting engine simulates an assignment event to reflect this real-world scenario (source).
However, for index options like SPX, early assignment doesn't quite apply in the same way. This is because index options are cash-settled, meaning there are no actual shares to be assigned. Instead, the holder of an in-the-money index option will receive a cash payment. The error message you're seeing suggests that the backtesting engine is trying to simulate an assignment event for an index option, which isn't realistic (source).
To avoid this issue, you can disable early assignment in your backtests by setting the option assignment model to the
NullOptionAssignmentModel
. Here's how you can do this in Python:(source)
Please note that while this will prevent the simulated early assignment from occurring, it may not fully reflect the real-world behavior of index options. It's always a good idea to thoroughly debug your algorithm and understand the implications of the models you're using.
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.
Dennis
I think the main issue is that the other leg of the spread (long put) doesn't seem to be exercised automatically when early assignment happens. Is this a bug or expected behavior?
If early assignment is disabled, both options are exercised correctly, and there is no unexpected dip in the account.
Mia Alissi
In QuantConnect, when an option is in-the-money, the backtesting engine will trigger an assignment event to simulate the real-world scenario where the option holder may choose to exercise the option. However, this automatic exercise/assignment only applies to in-the-money options. If the other leg of your spread (the long put) is not in-the-money, it won't be automatically exercised (source).
If you want to exercise the other leg of the spread when early assignment happens, you can do so manually in the
OnOrderEvent
method. Here's an example of how you can do this in Python:(source)
In this code,
orderEvent.IsAssignment
will beTrue
if the order event is an assignment (i.e., one of your short options got assigned). You can then add your logic to exercise the other leg of the spread in the# do stuff
section.Please note that exercising an option manually will require sufficient buying power in your account. If you're seeing insufficient fund errors, it could be because your account doesn't have enough buying power to exercise the option. You may need to adjust your algorithm or add more funds to your account to avoid these errors.
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.
Dennis
In this case both options are in the money. But the other option is not getting exercised even on expiration (if early assignment simulation is enabled).
Another confusing thing is that the time of the early assignment is 12:00 on expiration day. How is that even possible? These options should be settled after hours, so what exactly does this time represent?
confusing time of early assignment
After disabling early assignment simulation, both options are exercised as expected:
both options are exercised
However, it's also not clear why does it say 01:00 as the exercise time? Should these options be settled after hours on expiration day, so should this time be “2022-01-24 16:00:00” or something like that?
Mia Alissi
The time of the early assignment you're seeing (12:00) is likely due to the way QuantConnect's backtesting engine simulates option assignments. The engine doesn't necessarily reflect the exact timing of real-world option assignments, which can occur at any time before expiration for American style options. The simulated assignment time is not meant to represent the actual time an assignment would occur in live trading (source).
As for the other leg of the spread not getting exercised, this could be due to the way your algorithm is set up. If you want to ensure that both legs of the spread get exercised, you may need to manually exercise the other leg in the
OnOrderEvent
method, as I mentioned in the previous response.Regarding the exercise time of 01:00, it's important to note that the S&P 500 Index Option contracts market trades in the
America/Chicago
time zone (source). This could explain the discrepancy you're seeing in the exercise time. However, without more specific information about your algorithm and its settings, it's hard to provide a more detailed explanation.If you continue to experience issues, I recommend posting a more detailed question on the QuantConnect forum where the community and the QuantConnect team can provide more targeted assistance.
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.
Dennis
I have a backtest attached in my original message. To summarize, here are my questions that I hope someone can answer after reviewing the code:
Mia Alissi
The issue with the long put option not being exercised at expiration, even though it's in the money, could be due to the way QuantConnect's backtesting engine simulates option assignments. The engine doesn't necessarily reflect the exact timing of real-world option assignments. If you want to ensure that both legs of the spread get exercised, you may need to manually exercise the other leg in the
OnOrderEvent
method (source).The early assignment time “2022-01-24 12:00:00” is likely due to the way QuantConnect's backtesting engine simulates option assignments. The simulated assignment time is not meant to represent the actual time an assignment would occur in live trading (source).
The exercise time shown as “2022-01-25 01:00:00” could be related to the time zone of the S&P 500 Index Option contracts market, which trades in the
America/Chicago
time zone (source). However, without more specific information about your algorithm and its settings, it's hard to provide a more detailed explanation.If you continue to experience issues, I recommend posting a more detailed question on the QuantConnect forum where the community and the QuantConnect team can provide more targeted assistance.
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.
Dennis
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!