I am selling call and put options that expire on the same day. For some reason option got assigned even if price close way below the strike price. Specifically, in the attached backtes.
I sold one two options QQQ 211222P00372000 and QQQ 211222C00391000 on 21-12-21. I have checked intraday price of QQQ and is closed at $389.21 which way below of 391 strike price.
Can someone please take a look and let me know why this was assigned?
Mia Alissi
Here are the identified issues in the provided code that could lead to unexpected behavior, such as option assignment:
Symbol Assignment: The line
self.symbol = self.qqq.symbol
should beself.symbol = self.qqq.Symbol
.Consolidate Method: The
consolidate
method call should beself.consolidate(self.symbol, timedelta(days=1), self.consolidation_handler)
. Ensuretimedelta
is imported.Brokerage Name: Use
BrokerageName.QuantConnectBrokerage
instead ofBrokerageName.QUANTCONNECT_BROKERAGE
.Benchmark Setting: The
set_benchmark
method should be passed a function that returns a float, notself.symbol
.Datetime and Timedelta: Ensure
datetime
andtimedelta
are imported.Color Attributes: Use
Color.Red
andColor.Blue
instead ofColor.red
andColor.blue
.Option Chain Provider: The
get_option_contract_list
method should be called withself.symbol.Value
or simplyself.symbol
.Numpy Module: Ensure
numpy
is imported asimport numpy as np
.Data Access: Access data with
data.Bars[self.symbol]
or similar, depending on the data structure.Liquidate Method: The
liquidate
method should be called withself.symbol.Value
or simplyself.symbol
.Type Errors: Ensure correct types are used, particularly with list comprehensions and indexing.
By addressing these issues, the algorithm should function more reliably and avoid unexpected behavior such as incorrect option assignments.
Sources: Momentum Effect In Commodities Futures, Option Expiration Week Effect, Leveraged ETFs With Systematic Risk Management, Greeks and IV Implementation, Order Errors - QuantConnect.com
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.
Maksat Haytmyradov
This does not answer my question. I already fixed all suggested fixes.
Louis Szeto
Hi Maksat
The underlying price is $393.95, which is higher than the strike, so the shorted call is being assigned. I don't see any issue here. You may want to check the raw price of SPY with a third-party source but not the adjusted price.
Best
Louis
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.
Maksat Haytmyradov
Hi Louis Szeto ,
Thanks for checking this. Please see trading view price on Dec 21st.
$393.95 is actually next days closing price (Dec 22nd). For this particular day, option has not been closed at midnight even though it has expired (and was out of money).
Maksat Haytmyradov
Hi Jared Broad, Louis Szeto
Can you guys please help me to debug this issue? I have tried many things (such as disabling OptionAssignment Model, etc.) and can't find solution.
As I shown above (both from 3rd party and QuantConnect data), QQQ price indeed closed well below Call strike price of $391 on option expiration day. However, backtest still triggered early assignment.
Maybe, another information can be helpfull.
During backtesting, I realized options contract was not closed during the midnight, which was not the case on other days.
Louis Szeto
Hi Maksat
The order log shows that the option was assigned at midnight on 23 Dec using 22 Dec's close price of $393.95. The contract is indeed expiring on 22 Dec 2021 market close. There is no error here.
Best
Louis
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.
Maksat Haytmyradov
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!