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.
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!