Hi everyone!
I tried to use the following code:
self.Portfolio["AAPL"].GetBuyingPower
during live-trading with my IBKR account to get the buying power for AAPL, but I keep getting the cash available in my account, is there a way for us to get the cash + margin buying power?
Varad Kabade
Hi Li Cheng,
To get the buying power with a margin account we recommend using :
Best,
Varad Kabade
Li Cheng
Hi Varad, I've tried using the method that you suggested, but the value of the order is still equal to my portfolio cash.
Varad Kabade
Hi Li Cheng,
If self.Portfolio.MarginRemaining is equal to self.Portfolio.Cash indicates we do not have any open position. Alternatively, we recommend using:
to calculate our order size given the proportion of our margin we want to use.
For example, if we want to dedicate all of our margin with 100x leverage to one trade. We should use:
Using the above, the buying power will automatically get translated into shares, and we can multiply by the price of the security to get the order value.
Best,
Varad Kabade
Li Cheng
Hi Varad,
I am aware of the CalculateOrderQuantity function, the example that you gave above would trigger a “margin not available” error because IBKR only supports a maximum margin of 4 for pattern day trading accounts.
I guess what I'm really asking is how do I allocate 100% of cash + 100% of margin in my account without knowing how much leverage/margin is available, i.e. suppose I have a pattern day trading account, I should have 4* margin available for positions that close out during the day, how do I submit an order like that without triggering a “margin not available” error?
In addition, I've also noticed that the GetBuyingPower function does not reflect the “Buying Power Available” on my IBKR account.
Best regards
Cheng
Karsten Ø. Kristensen
Hi Li,
And your IB account is setup as a Margin account and not a cash account ?
Best regards
Karsten
Li Cheng
Hi Karsten,
I'm live-trading with my IBKR paper-trading account, setup with $100,000 cash, I believe that it is simulating a margin account environment because I do get to use margin.
Best regards
Cheng
Louis Szeto
Hi Cheng
IBKR has different margin ratios provided for different regions. In the US, the margin leverage is 2, which is also QC's default setting. To accommodate a different margin setting, you could set leverage for securities.
The "Buying Power Available" in IBKR is not a variable represented in QuantConnect/Lean, you may set that up by `self.Portfolio.MarginRemaining * leverage". Please find the attached backtest as an example.
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.
Li Cheng
Hi Louis, thanks for the information! I realized that the buying power for my account + margin is about 2-3 times cash available, I guess I will just set my algorithm to submit orders with 2x available buying power to be safe.
Li Cheng
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!