I'm backtesting a strategy using a bull put spread and I'm finding that the margin calculations are incorrect and my orders are rejected as invalid.
The margin requirement is usually calculated as the max loss, which should be (high strike - low strike) * 100. Details here:
However it looks like LEAN doesn't support calculating the margin for a spread and treats it as if I'm trying to sell a naked put then buy a completely unrelated option. See attached backtest.
Am I doing something incorrectly here or does LEAN not support option spread margin calculation?
If the latter, is there somewhere to report it? And is it possible to turn off the margin checks to work around it? I know I can just set an obscenely high starting cash but that breaks profit calculations.
John Port
Hi, I am having the same issue - wondering if you found a solution?
The only "solution" I have found for backtesting is to set my starting cash to far, far above what I'm actually looking to trade with to avoid the margin rejection. Obviously this is not a sufficient solution for live trading.
Also, related, any chance you or anyone else knows how to set a limit order specifically on the spread of the 2 premiums? I.e. execute both orders simultaneously only if the (bid price of sold - ask price of bought) > X?
Thank you.
Alexandre Catarino
At the moment, Lean/QuantConnect only have margin models that treat orders separately. So, yes, LEAN not support option spread margin calculation.
I have create an issue in GitHub: Combo buying power model #2709
Coder
Hi Alex,
I have similiar issue when bullish on Vertical spread. While my portfolio is up 40% (about 200k) and unrealized profits is positive, the backtest complains about margin not available:
Insufficient buying power to complete order (Value:6480), Reason: Id: 76, Initial Margin: 6483.75, Free Margin: 0
Maybe a solution is to create a function for vertical spreads or combinatoin of options.
Thanks
Coder
Jared Broad
We don't have a null buying power model at the moment. We're aware of this feature request and have made a note of it on Github. https://github.com/QuantConnect/Lean/issues/3157
self.Portfolio.MarginModel = self.Portfolio.MarginModel will throw as "MarginCallModel.Null" is a for the "self.Portfolio.MarginCallModel"
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.
Coder
I see this issue in offline backtesting, not in LEAN or Live trading.
So is the solution to start with a large cash amount like 1 million? in this case it will be hard to find out the returns and sharpe ratio.
Link Liang
Hi Nick,
In fact, our trading engine, for both offline backtesting and live trading, is powered by Lean. And backtest is always a simulation for live trading. This is why we made github issue in Lean for live trading to address your issue. You are welcome to subscribe to that issue and get noticed when it is resolved.
Thank you for your support!
J. K.
Very important to solve this issue! Cannot get accurate sharpe, algo valuation, etc as a result
Alethea Lin
Hi J. K.,
Thanks for your feedback. It is on our agenda. Stay tuned by following this Github issue page!
Jackson Dude
Any progress on this please. This is the 5th strategy i have tried to code in QuantConnect and hit a platform limitation stopping further development. I love your platform, but the limitation are driving me nuts.
Derek Melchin
Hi Jackson,
For the latest updates, see the GitHub Issues above and this one.
Best,
Derek Melchin
Want to invest in QuantConnect as we build the Linux of quant finance? Checkout our Wefunder campaign to join the revolution.
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.
Dee Znut
I Have come across at least 50 different threads where people are complaining about QC not being able to handle the buying power of a simple vertical spread and keeps crashing the backtest with “insufficient buying power” and “margin calls”.
I have seen many posts from QC team members including Alex and Jared back in 2020 stating that they are working hard on making sure options and spreads can be easily handled. However, in 2024 I have the same issue and thers is nobody to offer any help.
I will stop now because I have posted this comment on two threads and I don't want to duplicate my complaint but hope somebody reads these.
Dee Znut
Still no luck with this… no matter how many guardrails I put around margin calculation and how big my account is, I always end up with lack of buying power errors.
I had to take my account to $100,000 and trade only $1000 of it to avoid these errors. Obviously this is not a solution especially when you are saying live and test both behave the same.
I am only trading SPY and have this code as well in addition of 100s of margin checks in my code, but nothing works
var option = AddOption(ticker, Resolution.Hour);
option.SetBuyingPowerModel(BuyingPowerModel.Null);
Louis Szeto
Hi Dee
We do not reproduce this issue. Please share with us a backtest for further debugging. Meanwhile, please refer to the option strategies helper method on absrtaction.
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.
_ _
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!