It still will not run, I think it has something to do with adding positions that it does not know about. I get these logs right before it fails. I know I shouldn't have shorts, and my leverage is kind of different to get the equal weights.
new_weight=1/(existing+new-stopped_out)
Then I rebalance it every day based on the amount of positions it has. That is why I append to the context.exist from context.portfolio.positions
The problem is it will never sell back the total amount of the initial position if I am always having to reweigh it.
2005-04-26 14:00 WARN Your order for -29 shares of MBG failed to fill by the end of day and was canceled.
2005-10-27 14:00 WARN Your order for -1 shares of PKZ failed to fill by the end of day and was canceled.
2005-12-21 14:00 WARN Your order for -2 shares of PHS failed to fill by the end of day and was canceled.
2005-12-23 14:00 WARN Your order for -1 shares of GP failed to fill by the end of day and was canceled.
2006-01-27 14:00 WARN Your order for 3 shares of IVX failed to fill by the end of day and was canceled.
2006-03-23 14:00 WARN Your order for -6 shares of CEPH failed to fill by the end of day and was canceled.
2006-03-23 14:00 WARN Your order for -1 shares of IMDC failed to fill by the end of day and was canceled.
2006-04-03 14:00 WARN Your order for -2 shares of ABGX failed to fill by the end of day and was canceled.
2006-04-10 14:00 WARN Your order for 1 shares of BR failed to fill by the end of day and was canceled.
2006-04-19 14:00 WARN Your order for 1 shares of BR failed to fill by the end of day and was canceled.
2006-04-20 14:00 WARN Your order for 1 shares of BR failed to fill by the end of day and was canceled.
2006-04-21 14:00 WARN Your order for 1 shares of BR failed to fill by the end of day and was canceled.
2006-05-02 14:00 WARN Your order for -1 shares of BR failed to fill by the end of day and was canceled.
End of logs.