I've seen this issue brought up a couple of times (https://www.quantopian.com/posts/one-problem-with-interactive-brokers) but have not seen a resolution, at least publicly in the forums yet. It seems context.portfolio.cash is currently pulling data from the IB "cash" field. The problem with this is IB includes unsettled cash in that value. This is a pretty big issue if you are trading using a non margin account and do not want to keep a 100% cash reserve to cover unsettled cash. It also affects backtest performance as algo's are able to spend cash that is not really "available" yet. I would assume the solution would be as simple as Quantopian adding another option to pull the "buying power" field from IB or something similar which excludes unsettled cash.
If that is not possible for whatever reason, or as an interim solution, can anyone think of a way to account for unsettled cash? Maybe something like summing the prior 4 days sells and subtracting that from context.portfolio.cash?