We now have full margin modelling! This makes QuantConnect more realistic than ever, giving you a dynamic amount of leverage depending on the model parameters. We have modeled margin calls so if you get some unexpected sells its because your algorithm is over leveraged and losing money!
Traditional brokerages give you 2x leverage, and 4x intraday. For simplicity we use 2x constantly. If your algorithm is ever fully leveraged and the price of the market drops - you'll be given a 10% buffer to correct your portfolio. If they aren't corrected your algorithm will have margin call orders placed against it! You can see the orders tagged with "Margin Call" flag in the trades tab.
We're super proud of how QuantConnect is evolving. Its becoming incredibly realistic and matches the behavior you'll see in live trading!
Arkady M
Is there any way to disable the margin calls feature?
For example, I have enconutered a situation when I am getting margin calls because of the bad data. In this situation it would be easier just to disable the feature instead of working around the bad data,
A specific example - reverse split adjusted prices are not always correct
Arkady M
Found this
Securities["XIV"].SetLeverage(1m);
Alexandre Catarino
We can disable margin calls by setting the margin call model to the NullMarginCallModel.
This can easily be done like this:
Securities["XIV"].MarginModel = MarginCallModel.Null;
Arkady M
Thanks
Sofyan Saputra
Securities["XIV"].MarginModel = MarginCallModel.Null;
This no longer seems to work. This returns an error saying you can't implicitly convert type IMarginCallModel to ISecurityMarginModel. Is there another way to disable margin calls?
Alexandre Catarino
Please try to disable margin calls at Portfolio level using:
// In Initialize Portfolio.MarginCallModel = MarginCallModel.Null;
Brett C.
Are the MarginCallModel.Null overrides still applicable? Maybe I need a Python version of the code.
I've tried
Securities["XIV"].MarginModel = MarginCallModel.Null
and
Portfolio.MarginCallModel = MarginCallModel.Null
Both return errors, "global name 'Securities' is not defined" and "global name 'Portfolio' is not defined" respectively.
Thanks to anyone who can help me eliminate the Quantconnect 2x leverage limit. QC team, may I humbly suggest this should only apply to backtests, not live trading.
Alexandre Catarino
Did you not forget self. before both Securities and Portfolio?
Brett C.
Algo doesn't allow > 2x leverage with
self.Portfolio.MarginModel = MarginCallModel.Null
or
self.Portfolio.MarginModel = PatternDayTradingMarginModel()
The goal is to set 4x leverage intraday like a normal brokerage account... and ideally override QC limits completely to trade a portfolio margin account. Thanks!
Jared Broad
From Docs:
self.Securities["AAPL"].MarginModel = PatternDayTradingMarginModel()
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.
Brett C.
Thanks guys! Both MarginCallModel.Null and PatternDayTradingMarginModel() working now. Had reversed them, and placed too early in the code sequence. Posted in backtest below for others. In list form looks like this:
# Add securities and indicators
self.bonds = ["SHY","IEF"]
for s in self.bonds:
self.AddEquity(s, Resolution.Minute)
self.Securities[s].MarginModel = PatternDayTradingMarginModel()
Can I relax overnight leverage constraints beyond 2x? A Portfolio Margin account (next level up from Reg-T) at IB and other prime brokers will allow more than 2x leverage, especially if you're holding bonds and forex, both of which have low volatility.
It would be great to have a way to opt out of QC leverage constraints, especially for live trading.
Jing Wu
Hi Brett, the default is IB's 2x margin accounts. If you want 4x intraday margin limits, you can use the PatternDayTradingMarginModel, This documentation explains the margin model in greater details.
You can also set the leverage for each stock with self.Securities[symbol].SetLeverage()
Please see this example
https://github.com/QuantConnect/Lean/blob/master/Algorithm.Python/MarginCallEventsAlgorithm.py
Jared Broad
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!