In setting up a new algorithm I want to pull the margin remaining from Interactive Brokers.
I have found self.Portfolio.MarginRemaining
What does this return? I can't find documentation anywhere.
I have a feeling it will return Current Available Funds, however as I want to be able to hold trades overnight without a Reg-T Margin call I need to determine the amount in SMA available.
Is there anything built in to do this? Does anyone have a solution?
Jared Broad
You can set RegT margin by setting:
Securities["IBM"].MarginModel = new PatternDayTradingMarginModel();
This applies 4x intraday and 2x overnight. Margin remaining is available margin for trading. Its indirectly linked to cash/funds depending on the margin requirements of each asset (Initial and Maintenance margin requirements).
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.
Tim Butler
Jared,
Thanks for the response.
Let me see if I understood you correctly.
Just say there is $20000 in available overnight funds, and only $5000 available in SMA.
When I purchase shares I will be limited overnight by the available SMA, as it is lower, therefore I need to use that when calculating how many shares to purchase.
If I call Securities["IBM"].MarginRemaining what number would be returned? Or how would I be able to access the $5000 number?
Tim Butler
On the account I wish to deploy the algorithm to the initial/current maintenance margins requirements miniscule compared to the amount available in SMA. If I trade using maintenance margin requirements as the limiting factor I will be liquidated at EOD for being in negative SMA.
The account I wish to use is a sub account (each algo has it's own sub account) that has it's own maintenance margin requirements, however all of the accounts share a common SMA.
I imagine this is a standard setup for anyone running multiple algos on the same account.
Jared Broad
Securities["IBM"].MarginRemaining doesn't exist as margin remaining is portfolio wide and not restricted to a single asset; but self.Portfolio.MarginRemaining is calculated as below:
return TotalPortfolioValue - UnsettledCashBook.TotalValueInAccountCurrency - TotalMarginUsed;
I believe for margin portfolio's (the default in LEAN) we don't have unsettled cash so you can ignore that component. You can see the implementation here (link to SecurityPortfolioManager.cs:
In that link you can also see the "MarginUsed" calculation.
Equities have a variable "margin" (but a fixed leverage; where leverage = 1/margin). Other assets can have fixed margin (e.g. $500 per contract which equates to a variable leverage). To unify these concepts we use margin for purchasing decisions. This is modelled from IB's portfolio handling.
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.
Tim Butler
Jared,
Thanks for the response. Sounds like the margin is modelled in LEAN and there is no method to access the SMA on a live account is this correct? I would like to order based on the smaller of two numbers, margin remaining and SMA remaining. Is this currently impossible?
Jared Broad
Understood, I think you're right we don't have backtesting models or live support for this yet (just individual reg t). We would need to test it though. With a solid description of the problem and credentials to provide a test account we can implement this relatively quickly. Please send through an email to support and we'll add it to the roadmap.
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.
Tim Butler
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!