Hi all,
I am trying to set custom slippage and fee for options. Here you can find the code
def Initialize(self):
self.SetStartDate(2024, 3, 1)
self.SetEndDate(2024, 4, 30)
self.SetCash(100000)
equity = self.AddEquity("AAPL", Resolution.Minute)
equity.SetDataNormalizationMode(DataNormalizationMode.Adjusted)
self.symbol = equity.Symbol
equity_1D = self.AddEquity("AAPL", Resolution.Daily)
equity_1D.SetDataNormalizationMode(DataNormalizationMode.Adjusted)
self.symbol_1D = equity_1D.Symbol
self.option = self.AddOption("AAPL", Resolution.Minute)
self.option.SetFilter(self.OptionFilter)
self.option.SetSlippageModel(ConstantSlippageModel(0.05))
self.option.SetFeeModel(ConstantFeeModel(1.62))
When I log that it shows the order fee still at 1 USD and the fill price remains unchanged
Order Event: Time: 03/01/2024 14:32:00 OrderID: 1 EventID: 2 Symbol: AAPL 240308P00175000 Status: Filled Quantity: -1 FillQuantity: -1 FillPrice: $0.44 OrderFee: 1 USD IsAssignment: False
Any pointers, what I am missing?
Mia Alissi
It seems like you are trying to set a custom slippage and fee model for options trading. However, the order fee and fill price are not reflecting your custom settings.
The issue might be related to the way you are setting the slippage and fee models. In QuantConnect, you should set the slippage and fee models on the security object, not on the option object.
Here is an example of how to set a custom slippage and fee model:
In your case, you should replace
MySlippageModel
andMyFeeModel
with your custom models and set them on the security object.Please note that the slippage model helps to calculate the order quantity and the fee model helps to calculate the order fee. However, the algorithm doesn't update the cash book with the fee from the fee model. The algorithm uses the actual fee from the brokerage to update the cash book.
For more information, please refer to the QuantConnect documentation and QuantConnect forum discussions.
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.
Kryz
Hi Mia, nice talking to you again ;)
But, in the case above, self.option is a security object. (To my understanding)
Mia Alissi
Hi Kryz,
You're correct that
self.option
is a security object, specifically it's an Option object. However, the slippage and fee models should be set on the specific security objects that are part of your portfolio, not on the Option object itself.In QuantConnect,
self.Portfolio
containsSecurityHolding
objects. It is a dictionary of Symbol → SecurityHolding. So when you iterate over it, depending on how you do it, you either iterate over Symbol objects, SecurityHolding objects or tuples of (Symbol, SecurityHolding). TheSecurityHolding
can be of any class (ie equity, forex, crypto, options etc.).Therefore, you should set the slippage and fee models on the specific securities that you are trading. For example, if you are trading AAPL options, you should set the models on the AAPL option security objects.
Here is an example of how you might do this:
I hope this helps! Let me know if you have any other questions.
For more information, please refer to the QuantConnect documentation and QuantConnect forum discussions.
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.
Kryz
Can you define in Initialize method the slippage for all options?
Mia Alissi
Yes, you can define the slippage for all options in the Initialize method by using the
SetSecurityInitializer
method. This method allows you to set a custom security initializer that will be applied to all securities added to your algorithm.Here is an example of how you might do this:
In this example, the
CustomSecurityInitializer
method sets the slippage and fee models for each security. This method will be called for each security added to your algorithm, including all options.For more information, please refer to the QuantConnect documentation and QuantConnect forum discussions.
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.
Kryz
This works. Thx!
Mia Alissi
You're welcome, Kryz! I'm glad to hear that the solution worked for you. If you have any more questions or need further assistance, feel free to ask. Happy coding!
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.
Kryz
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!