Hello everyone, I am working on a strategy to backtest in NSE.
Strategy is Shorting the Straddles. Now the problem that I am facing is that whenever I use this line:
strategy_specs=OptionStrategies.ShortStraddle(self.option_symbol,contract_strikeprice, expiry)
self.Buy(strategy_specs,quantity=quantity)
I get self.Portfolio.MarginUsed value = StartingMargin-((call_price+put_price)*quantity), while it is wrong. In India there are a few measurements that are used to calculate the margin utilization for the straddle (short) but I am taking a thumb rule of call.UnderlyingLastPrice*lotsize*.12 as the margin required to short the straddle. (I know it is not precise but it is enough for my backtesting). Now the problem I am getting is that, I am not able to manage/manipulate/override the default PortfolioMarginManager. How can I do that? If my straddle needs a amrgin of 1000 then I want it to show me 1000 blocked instead of the (call_price+put_price)*quantity blocked.
Example:
I will place an order of shorting the straddle of quantity 1 and then it will more clear to you.
StratingMargin = 1,000,000
Callprice = 40
PutPrice = 30
UnderlyingPrice = 20000
lotsize = 50
quantity = 1 #(even I am fine if i have to provide quantity with lotsize multiplied)
MarginRequired = UnderlyingPrice * lotsize * quantity * 0.12 #(The one I want it to return)
MarginReturnedByDefault = Quantity * (CallPrice + PutPrice)
Case 1: When I place an order of Short Straddle with quantity 1 with the aforementioned values, then I will get the utilized margin as 70, and remaining Margin as 999,930.
Case 2: And If I give it the value of quantity as multiplied the lotsize then i will get the utilized margin as 3500, and remaing as 996,500.
While utilized Margin should have been 120,000, and remaing should have been 880,000.
Please help me out.
Things I have tried:
I have Implemented my custom BuyingPowerModel and MarginModel but they seem to have no effect on the Portfolio Level.
Thanks,
Chetan K Tyagi.
Mia Alissi
Hello Chetan,
It seems like you're trying to override the default margin model in QuantConnect to suit your specific needs for your strategy. You can indeed create a custom margin model in QuantConnect. However, it's important to note that the margin model is applied at the security level, not at the portfolio level.
Here's an example of how you can override the margin model for a specific security:
In this example, the
GetReservedBuyingPowerForPosition
method is overridden to return 0 if the option has been delisted. You can modify this method to return the margin requirement as per your calculation.You can also create a custom buying power model to override the
HasSufficientBuyingPowerForOrder
check:In this example, the
HasSufficientBuyingPowerForOrder
method is overridden to always return True, effectively disabling the check.Please note that these are just examples and you might need to adjust them to fit your specific needs.
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.
Chetan Tyagi
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!