Back

Negative Margin Remaining but IBKR Shows Positive Buying Power

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

Update Backtest







0

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.


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.

0

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)
 

0

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. 

0

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.


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

0

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)

0

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? 

0

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.


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

0

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

0

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

1

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.


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)

0

"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

0

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

0

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

0

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.


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)

0

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.

0

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.


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!

0

Quick update - sold the assets and started the algo again. Runs fine!

Thanks everyone!

1

Update Backtest





0

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.


Loading...

This discussion is closed