Hello.
I am new to Quantconnect and have very little experience with Python/programming.
I am having a bit of trouble understanding how to deal with stock splits in the underlying for open options positions. In my backtest, I have open options positions in two different underlyings. Since stock splits are not supported for options, the model attempts to automatically close my options on only the underlying for which the split is about to occur using a “MarketOnClose” order. I then get the following errors, telling me that a “MarketOnClose” order is invalid for options when using the IB brokerage model.
2021-01-08 15:44:00 :MarketOnClose order submitted for option contract 'SPXS 210115C00018000' due to impending SPXS split event. Option splits are not currently supported.
2021-01-08 15:44:00 :BrokerageModel declared unable to submit order: [7] Warning - Code: Unsupported order type for Option security type - InteractiveBrokers does not support Market-on-Close orders for other security types different than Future and Equity.
2021-01-08 15:44:00 :Time: 01/08/2021 20:44:00 OrderID: 7 EventID: 1 Symbol: SPXS 210115C00018000 Status: Invalid Quantity: 1 Message: BrokerageModel declared unable to submit order: [7] Warning - Code: Unsupported order type for Option security type - InteractiveBrokers does not support Market-on-Close orders for other security types different than Future and Equity. IsAssignment: False
I would like to override this behavior by liquidating all options positions on both underlyings, prior to a stock split in either of the two underlyings, and then wait and re-open positions after the split has occurred.
Is it possible to override this behavior? I tried to liquidate all the options when data contains a split with SplitType == SplitType.Warning for either underlying symbol, but again, I am getting an error saying that I can't place any orders when a split has occurred.
2021-01-08 00:00:00 :Warning: Options orders are not allowed when a split occurred for its underlying stock
I also have one other question. In the backtest you can see that I am attempting to open synthetic shorts on these two underlyings. I need to obtain the buying power requirements, per contract pair (-1 call, +1 put), per underlying, in order to calculate the multiple for the number of contracts to buy. Since there is no option strategy for synthetics, do I need to calculate this manually or is there an API function that can do this?
Thank you for your time.
Mia Alissi
Hello John,
To handle stock splits for underlying assets in options trading, you can use the
OnData
method in your algorithm. This method receives aSlice
object that containsSplits
data. You can check if a split is about to occur for a specific symbol by checking if that symbol is in theSplits
dictionary. Here is an example:This way, you can detect a split and liquidate your portfolio accordingly. However, please note that the split and dividends information is conferred after it happens. Yet, you can fetch upcoming split events by a conditional statement:
Regarding your question about buying power requirements for synthetic shorts, you can check if you have enough margin remaining to cover the initial margin requirements of an Option strategy. Here is an example:
You can create a list of
Position
objects from the strategy legs:Please note that the
OptionStrategies.NakedCall
andOptionStrategies.NakedPut
are used to define option strategies, not to buy or sell options directly. When you sell a naked call or put, you are selling an option that you do not own, which is different from buying an option.Sources:
I hope this helps! Let me know if you have any other questions.
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.
John
In the backtest I attached, I am attempting to catch SplitType == SplitType.Warning within OnData() and then liquidate the options prior to the split, however the engine appears to be preventing me from liquidating the options on the underlying that is about to split. Instead, it appears that the algorithm is forcefully entering a MarketOnClose order, which the IB brokerage model then rejects.
Mia Alissi
Hello John,
It seems like you're encountering an issue where the LEAN engine is automatically submitting a MarketOnClose order due to an impending split event, which is then rejected by the Interactive Brokers (IB) brokerage model because MarketOnClose orders are not supported for options.
In the current implementation of LEAN, when a split event is detected, it attempts to liquidate the options positions by submitting a MarketOnClose order. However, as you've noticed, this order type is not supported for options by the IB brokerage model.
One possible workaround could be to check for upcoming split events in the
OnData
method and liquidate your options positions before the split event occurs. However, it seems like you've already tried this approach and encountered an error that prevents you from placing orders when a split has occurred.Unfortunately, based on the information provided in the knowledge sources, it seems that there is currently no direct way to override this behavior in LEAN. The handling of split events and the submission of MarketOnClose orders is built into the engine and cannot be easily changed without modifying the source code.
As for your question about the buying power requirements for synthetic shorts, you would need to calculate this manually as there is no built-in API function for this in QuantConnect.
I would recommend reaching out to the QuantConnect support team at support@quantconnect.com for further assistance with this issue.
Sources:
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.
John
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!