Back

Option combo margin calculation

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:

https://tastyworks.desk.com/customer/en/portal/articles/2658392-short-credit-vertical-spread

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.

Update Backtest








0

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.


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.

0

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

0

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.


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

0

Is using self.Portfolio.MarginModel = MarginCallModel.Null a reasonable solution?
 Thanks
0

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"

0

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.


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.

0

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!

0

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.


Very important to solve this issue!  Cannot get accurate sharpe, algo valuation, etc as a result

0

Hi J. K.,

Thanks for your feedback. It is on our agenda. Stay tuned by following this Github issue page

0

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.


Update Backtest





0

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.


Loading...

This discussion is closed