Hi all,
Has anyone experienced anything similar? Live algorithm threw log errors of being unable to do market orders due to insufficient funds (negative initial margin) but IBKR says I have a positive buying power (Margin account)
I am using <self.Portfolio.MarginRemaining> to obtain my buying power
Thanks,
Marc
Pcnpj
Will be re-running for 7/2 to see if the problem persists - had to tweak my code a bit because normally it runs at the beginning of each month.
Pcnpj
Same issue. Here is my snipping of code:Â
buyingPower = (self.Portfolio.MarginRemaining / 3) * .995 if buyingPower > 0: for symbol in symbols: if self.Securities[symbol].Price > 0: orderSize = buyingPower / self.Securities[symbol].Price self.MarketOrder(symbol, orderSize) else: self.Log("Insufficient Buying Power: " + str(self.Portfolio.MarginRemaining))
self.Portfolio.MarginRemaining comes out negative but in IBKR I have $XX,XXX buying power... (free cash and margin including)
Â
Jared Broad
HI Pcnpj! Please use the support tab of the IDE to submit the live algorithm logs for support. Without the full logs it's stabling in the dark as it depends heavily on IB and your account.Â
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.
Pcnpj
Thanks for the response, I submitted the support tickets for each run. Hopefully this can be sorted out quickly because the algorithm trades infrequently (monthly), and while I can probably do this month manually I want to aim to automate this by July! :-)
Will update this thread of any answers that may help the community
Pcnpj
I haven't gotten a response to my ticket yet - I confirmed that I am still able to buy if I did it manually. QC isn't seeing my actual IBKR buying power and looks like it is looking at my settled cash instead (which is in a negative for when I trade while my account was a Cash Account but now it has been upgraded to a Margin Account)
Alexandre Catarino
Hi pcnpj ,
We have received your email on July 1st and replied to you asking to stop the algorithm to be able to access the system logs. It's market as "Not seen yet". Could you please verify you got our message?Â
Pcnpj
Hey Alexandre,
I have not received that reply. Does it come through email? I did get the ticket received email and even the response to this thread as an email.
I have stopped the algorithm, please let me know what else I can do on my end.
Thanks!
Marc
Pcnpj
Ran it again and compared it to my IBKR account...
self.Portfolio.MarginRemaining is taking my Settled Cash Amount of -X,XXX where I am expecting it to take my Buying Power of XX,XXXX
My settled cash amount is negative because I have a IBKR Margin account where I am able to borrow money additional to my actual cash balance...
Because of this, self.Portfolio.MarginRemaining on IBKR Margin Accounts should never work if borrowing more than what you have.
Is this the intention of self.Portfolio.MarginRemaining? Is there another way to get my actual buying power?
Thanks
Alexandre Catarino
Hi pcnpj,
Yes, I sent this answer through email with the right values.
When the algorithm is deployed, it fetches the current position in your account. On July 1st, you had N assets with a combined market value of $XXXXX.XX and a negative cash balance of $XXXX.XX. When Lean reconstructs the portfolio, it assumes that the cash balance is the MarginRemaining, so it's value if -XXXX.XX.
Since this is a universe selection algorithm, I would recommend to deploy it with a "clean" portfolio. The securities that exist in your account will be added to the algorithm as used-defined securities and it will require some logic to handle them with universe selection. For instance, if universe selection does not select HOFT, what happens with HOFT that exists in your portfolio? What should happen to HOFT if it is added then removed by universe selection?
Best regards,
Alex
Pcnpj
Thanks Alex,
And sorry you have to type the answer out twice - I'm not getting non-community thread emails...
Does "Clean" mean with a positive settled cash amount? Meaning I could sell some assets to bring my cash amount up? Or does it mean with completely no assets? (Sell everything)
Pcnpj
"When Lean reconstructs the portfolio, it assumes that the cash balance is the MarginRemaining, so it's value if -XXXX.XX."
Still kinda hazy on why LEAN would choose the negative unsettled cash balance over the buying power in this scenario? And why resetting my assets would help?
Thanks
Pcnpj
As for the universe scenario, currently held securities in the portfolio are held regardless of the unvierse and sold at the start of the month
Derek Melchin
Hi Pcnpj,
A "clean" portfolio holds no securities. It is in all cash.
Resetting the assets helps because then the MarginRemaining on your IB account will equal the account's total cash available for trading.
Best,
Derek Melchin
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.
Pcnpj
Derek MelchinÂ
Thanks, it should help recalculate how much cash balance I have + the margin amount that is available to borrow right? (If I recall correctly, IBKR will let you borrow up to 100% of your cash, 10k in cash, 20k in buying power)
Jared Broad
What IB allows you to borrow depends on your account type. Portfolio margin accounts can borrow up to 4x intraday, or 2x overnight to my knowledge but it has been a while =) they might have updated it.
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.
Pcnpj
Thanks Jared
Here's what I am going to do - I will clean my assets when I hit my goal or the end of the month comes and have my algorithm do it's thing and I am going to expect stocks being bought at more than 1x my balance (I have a portfolio margin account).
If there's any other issues at that time I will ping this thread again.
Thanks everyone for the help!
Pcnpj
Quick update - sold the assets and started the algo again. Runs fine!
Thanks everyone!
Pcnpj
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!