While trying to develop some strategies, I have noted my cash was always going negative. I have taken care of closing all open orders before any rebalance, and I am exclusively using order_target_percent (both tips I have found in this excellent community). After some debugging, I have discovered the cause for this was related to companies being acquired by another.
In the following backtest (which is a concise algo for replicating the case with minimum code), the company named RIN (RINKER GROUP LIMITED ADS) has been acquired at about June 2007. From this day on, RIN continues to exists in the portfolio and, for every order_target_percent later, the algo produced a negative cash equivalent to the value of the "dead" RIN positions.
The same happens to bankrupted companies, as in the LEH. The impact on cash is not that big, because such company slowly decrease value and almost zeroes out when delisted (see the return reducing from May 2008 to Sept 2008 due to LEH decline).
If you try to sell these companies after the merge/bankruptcy, the order is accepted but never completes.
I have made an workaround to avoid negative cash by doing an artificial leverage (smaller than 1.0, derived from the inactive stocks value) while calling all order_target_percent, in order to compensate the negative cash. But this is not realistic since I would never get the cash back from those acquisitions.
What would be the best way to handle these situations?