IB Rebalancing Errors


Recently, I've encountered a problem with rebalancing using an IB account. Whenever a rebalance occurs, I get an error stating there's not enough cash. I think this is because the cash "required" is equal to the current equity holdings + the new purchase. For example:

I start with $125.

A stock is currently trading at $20. I previously bought and currently own 5 shares ($100 value). I now have $25 left in my account balance.

self.SetHoldings(sid, some_percent)

The SetHoldings method does a rebalance, to a total of 6 shares. This means it should only need to purchase one additional share for $20, requiring $20 in cash. However, the error received looks like this (prices changed to match example):

New Order Event: Time: 11/1/2017 1:40:12 PM OrderID: 3 Symbol: AGG Status: Invalid Message: 201 - Order rejected - reason:CASH AVAILABLE (SETTLED CASH): 25; CASH NEEDED FOR THIS ORDER AND OTHER PENDING ORDERS: 120. Origin: IBPlaceOrder: STK AGG USD Smart

It appears that the cash requirement is set to all 6 shares, even though 5 are already bought.

Of course, in real life the stock would change in value from $20. This is only fixed in the example for simplicity.

This does not happen if positions are first liquidated.

Any ideas on how to fix this problem?


Update Backtest

Update Backtest


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.


This discussion is closed