In some backtests I'm noticing a significant decrease in remaining margin, which I can't explain. For example, the attached backtest sells 2 bear credit spreads:
1. Sell SPXW 220105C04730000, Buy SPXW 220105C04780000 on 2022-01-032. Sell SPXW 220105C04760000, Buy SPXW 220105C04810000 on 2022-01-04
Both spreads are $50 wide, so, assuming a $100k account, I don't expect used margin to ever go below $90k ($100k - $50*100*2).
However, after trading both spreads, the final remaining margin is as low as $37k. But if trading only one of the spreads, they only take about $2k of margin:
_doSpread1 _doSpread2 Final remaining margin True False 98,690 False True 98,710 True True 37,828.30How can total margin required for both spreads be more than the sum of margin required for each of them?
From the logs it looks like remaining margin takes a huge hit when selling the second spread (goes down to $16k) and eventually restores to $37k:
1/3/2022 9:31:00 AM: remaining margin before spread 1: 100000.0
1/3/2022 9:31:00 AM: remaining margin after spread 1: 94950.0000
1/4/2022 9:31:00 AM: remaining margin before spread 2: 94245.0000
1/4/2022 9:31:00 AM: remaining margin after spread 2: 16649.25000000000000000000000
1/5/2022 4:15:00 PM: remaining margin final: 37828.300000000
How exactly do we arrive at such numbers, like dropping from $94k to $16k when trading a $50 spread? Am I missing something obvious in how required margin is calculated?
Mia Alissi
The margin requirements for options trading can be complex and may not be as straightforward as simply subtracting the spread width from your total account balance. The margin requirements can depend on various factors such as the underlying asset, the strike price, and the expiration date of the options.
In QuantConnect, the margin requirements are calculated by the security's buying power model. You can check if you have enough margin remaining to cover the initial margin requirements of an order by following these steps:
InitialMarginParameters
object with the security and quantity you want to trade.get_initial_margin_requirement
method of the security's buying power model with theInitialMarginParameters
.If you're still having issues with your margin calculations, it might be a good idea to reach out to the QuantConnect support team at support@quantconnect.com for further assistance. They might be able to provide more specific guidance based on your particular algorithm and trading strategy.
(Source: QuantConnect Forum)
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.
Dennis
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!