Hey Eric, here is the log output I am getting with your algo. I added the number of shares to your log output. It appears that on only one of the dates (order placed on 02/05, filled at 02/06) the order executes for 99 shares of IBM rather than 100. On the next day, however, the algorithm "recovers" and buys 101 shares, correcting the net position. The algorithm executes correctly on all other bars.
2014-02-04handle_data:44INFOplacing market order for Security(24 [AAPL]) at price 508.62 at 2014-02-04 15:59:00-05:00
2014-02-04handle_data:46INFOplacing market order for Security(3766 [IBM]) at price 172.81 at 2014-02-04 15:59:00-05:00
2014-02-04process_order:18INFOexecuting order Security(24 [AAPL])total shares 100 stock bar price: 508.8 and trade executes at: 508.825 at 2014-02-04 16:00:00-05:00
2014-02-04process_order:18INFOexecuting order Security(3766 [IBM])total shares -100 stock bar price: 172.83 and trade executes at: 172.79 at 2014-02-04 16:00:00-05:00
2014-02-04handle_data:49INFOplacing market clear order for Security(24 [AAPL]) at price 508.8 at 2014-02-04 16:00:00-05:00
2014-02-04handle_data:51INFOplacing market clear order for Security(3766 [IBM]) at price 172.83 at 2014-02-04 16:00:00-05:00
2014-02-05process_order:18INFOexecuting order Security(24 [AAPL])total shares -100 stock bar price: 507.8001 and trade executes at: 507.7751 at 2014-02-05 09:31:00-05:00
2014-02-05process_order:18INFOexecuting order Security(3766 [IBM])total shares 99 stock bar price: 172.36 and trade executes at: 172.4 at 2014-02-05 09:31:00-05:00
2014-02-05handle_data:44INFOplacing market order for Security(24 [AAPL]) at price 512.61 at 2014-02-05 15:59:00-05:00
2014-02-05handle_data:46INFOplacing market order for Security(3766 [IBM]) at price 174.13 at 2014-02-05 15:59:00-05:00
2014-02-05process_order:18INFOexecuting order Security(3766 [IBM])total shares -100 stock bar price: 174.27 and trade executes at: 174.23 at 2014-02-05 16:00:00-05:00
2014-02-05process_order:18INFOexecuting order Security(24 [AAPL])total shares 100 stock bar price: 512.61 and trade executes at: 512.635 at 2014-02-05 16:00:00-05:00
2014-02-05handle_data:49INFOplacing market clear order for Security(24 [AAPL]) at price 512.61 at 2014-02-05 16:00:00-05:00
2014-02-05handle_data:51INFOplacing market clear order for Security(3766 [IBM]) at price 174.27 at 2014-02-05 16:00:00-05:00
2014-02-06process_order:18INFOexecuting order Security(24 [AAPL])total shares -100 stock bar price: 511.49 and trade executes at: 511.465 at 2014-02-06 09:31:00-05:00
2014-02-06process_order:18INFOexecuting order Security(3766 [IBM])total shares 101 stock bar price: 173.86 and trade executes at: 173.9 at 2014-02-06 09:31:00-05:00
2014-02-06handle_data:44INFOplacing market order for Security(24 [AAPL]) at price 512.8 at 2014-02-06 15:59:00-05:00
2014-02-06handle_data:46INFOplacing market order for Security(3766 [IBM]) at price 174.65 at 2014-02-06 15:59:00-05:00
2014-02-06process_order:18INFOexecuting order Security(3766 [IBM])total shares -100 stock bar price: 174.7 and trade executes at: 174.66 at 2014-02-06 16:00:00-05:00
2014-02-06process_order:18INFOexecuting order Security(24 [AAPL])total shares 100 stock bar price: 512.47 and trade executes at: 512.495 at 2014-02-06 16:00:00-05:00
2014-02-06handle_data:49INFOplacing market clear order for Security(24 [AAPL]) at price 512.47 at 2014-02-06 16:00:00-05:00
2014-02-06handle_data:51INFOplacing market clear order for Security(3766 [IBM]) at price 174.7 at 2014-02-06 16:00:00-05:00
2014-02-07process_order:18INFOexecuting order Security(24 [AAPL])total shares -100 stock bar price: 520.655 and trade executes at: 520.63 at 2014-02-07 09:31:00-05:00
2014-02-07process_order:18INFOexecuting order Security(3766 [IBM])total shares 100 stock bar price: 175.07 and trade executes at: 175.11 at 2014-02-07 09:31:00-05:00
2014-02-07handle_data:44INFOplacing market order for Security(24 [AAPL]) at price 519.909 at 2014-02-07 15:59:00-05:00
2014-02-07handle_data:46INFOplacing market order for Security(3766 [IBM]) at price 177.36 at 2014-02-07 15:59:00-05:00
2014-02-07process_order:18INFOexecuting order Security(24 [AAPL])total shares 100 stock bar price: 519.75 and trade executes at: 519.775 at 2014-02-07 16:00:00-05:00
2014-02-07process_order:18INFOexecuting order Security(3766 [IBM])total shares -100 stock bar price: 177.24 and trade executes at: 177.2 at 2014-02-07 16:00:00-05:00
2014-02-07handle_data:49INFOplacing market clear order for Security(24 [AAPL]) at price 519.75 at 2014-02-07 16:00:00-05:00
2014-02-07handle_data:51INFOplacing market clear order for Security(3766 [IBM]) at price 177.24 at 2014-02-07 16:00:00-05:00
2014-02-10process_order:18INFOexecuting order Security(3766 [IBM])total shares 100 stock bar price: 176.51 and trade executes at: 176.55 at 2014-02-10 09:31:00-05:00
2014-02-10process_order:18INFOexecuting order Security(24 [AAPL])total shares -100 stock bar price: 519.8 and trade executes at: 519.775 at 2014-02-10 09:31:00-05:00
2014-02-10handle_data:44INFOplacing market order for Security(24 [AAPL]) at price 528.685 at 2014-02-10 15:59:00-05:00
2014-02-10handle_data:46INFOplacing market order for Security(3766 [IBM]) at price 177.17 at 2014-02-10 15:59:00-05:00
2014-02-10process_order:18INFOexecuting order Security(24 [AAPL])total shares 100 stock bar price: 528.98 and trade executes at: 529.005 at 2014-02-10 16:00:00-05:00
2014-02-10process_order:18INFOexecuting order Security(3766 [IBM])total shares -100 stock bar price: 177.15 and trade executes at: 177.11 at 2014-02-10 16:00:00-05:00
2014-02-10handle_data:49INFOplacing market clear order for Security(24 [AAPL]) at price 528.98 at 2014-02-10 16:00:00-05:00
2014-02-10handle_data:51INFOplacing market clear order for Security(3766 [IBM]) at price 177.15 at 2014-02-10 16:00:00-05:00
2014-02-11process_order:18INFOexecuting order Security(3766 [IBM])total shares 100 stock bar price: 176.9 and trade executes at: 176.94 at 2014-02-11 09:31:00-05:00
2014-02-11process_order:18INFOexecuting order Security(24 [AAPL])total shares -100 stock bar price: 531.685 and trade executes at: 531.66 at 2014-02-11 09:31:00-05:00
2014-02-11handle_data:44INFOplacing market order for Security(24 [AAPL]) at price 535.7864 at 2014-02-11 15:59:00-05:00
2014-02-11handle_data:46INFOplacing market order for Security(3766 [IBM]) at price 179.51 at 2014-02-11 15:59:00-05:00
2014-02-11process_order:18INFOexecuting order Security(24 [AAPL])total shares 100 stock bar price: 535.96 and trade executes at: 535.985 at 2014-02-11 16:00:00-05:00
2014-02-11process_order:18INFOexecuting order Security(3766 [IBM])total shares -100 stock bar price: 179.59 and trade executes at: 179.55 at 2014-02-11 16:00:00-05:00
2014-02-11handle_data:49INFOplacing market clear order for Security(24 [AAPL]) at price 535.96 at 2014-02-11 16:00:00-05:00
2014-02-11handle_data:51INFOplacing market clear order for Security(3766 [IBM]) at price 179.59 at 2014-02-11 16:00:00-05:00
One idea is that there is not enough capital in the portfolio or liquidity available to order all 100 shares. We can try running the algo with an order size of 500 shares, but it only executes of 499 shares on the same date. So the issue appears to be that one less than the desired number of shares is ordered.
2014-02-05process_order:18INFOexecuting order Security(24 [AAPL])total shares -500 stock bar price: 507.8001 and trade executes at: 507.7751 at 2014-02-05 09:31:00-05:00
2014-02-05process_order:18INFOexecuting order Security(3766 [IBM])total shares 499 stock bar price: 172.36 and trade executes at: 172.4 at 2014-02-05 09:31:00-05:00
2014-02-05handle_data:44INFOplacing market order for Security(24 [AAPL]) at price 512.61 at 2014-02-05 15:59:00-05:00
2014-02-05handle_data:46INFOplacing market order for Security(3766 [IBM]) at price 174.13 at 2014-02-05 15:59:00-05:00
2014-02-05process_order:18INFOexecuting order Security(24 [AAPL])total shares 500 stock bar price: 512.61 and trade executes at: 512.635 at 2014-02-05 16:00:00-05:00
2014-02-05process_order:18INFOexecuting order Security(3766 [IBM])total shares -500 stock bar price: 174.27 and trade executes at: 174.23 at 2014-02-05 16:00:00-05:00
2014-02-05handle_data:49INFOplacing market clear order for Security(24 [AAPL]) at price 512.61 at 2014-02-05 16:00:00-05:00
2014-02-05handle_data:51INFOplacing market clear order for Security(3766 [IBM]) at price 174.27 at 2014-02-05 16:00:00-05:00
2014-02-06process_order:18INFOexecuting order Security(3766 [IBM])total shares 501 stock bar price: 173.86 and trade executes at: 173.9 at 2014-02-06 09:31:00-05:00
2014-02-06process_order:18INFOexecuting order Security(24 [AAPL])total shares -500 stock bar price: 511.49 and trade executes at: 511.465 at 2014-02-06 09:31:00-05:00
The problem appears to be unique to IBM, as when we use AMZN instead of IBM, the execution quantities are what we expect.
2014-02-04handle_data:44INFOplacing market order for Security(24 [AAPL]) at price 508.62 at 2014-02-04 15:59:00-05:00
2014-02-04handle_data:46INFOplacing market order for Security(16841 [AMZN]) at price 348.12 at 2014-02-04 15:59:00-05:00
2014-02-04process_order:18INFOexecuting order Security(16841 [AMZN])total shares -100 stock bar price: 347.94 and trade executes at: 347.9 at 2014-02-04 16:00:00-05:00
2014-02-04process_order:18INFOexecuting order Security(24 [AAPL])total shares 100 stock bar price: 508.8 and trade executes at: 508.825 at 2014-02-04 16:00:00-05:00
2014-02-04handle_data:49INFOplacing market clear order for Security(24 [AAPL]) at price 508.8 at 2014-02-04 16:00:00-05:00
2014-02-04handle_data:51INFOplacing market clear order for Security(16841 [AMZN]) at price 347.94 at 2014-02-04 16:00:00-05:00
2014-02-05process_order:18INFOexecuting order Security(24 [AAPL])total shares -100 stock bar price: 507.8001 and trade executes at: 507.7751 at 2014-02-05 09:31:00-05:00
2014-02-05process_order:18INFOexecuting order Security(16841 [AMZN])total shares 100 stock bar price: 345.086 and trade executes at: 345.126 at 2014-02-05 09:31:00-05:00
2014-02-05handle_data:44INFOplacing market order for Security(24 [AAPL]) at price 512.61 at 2014-02-05 15:59:00-05:00
2014-02-05handle_data:46INFOplacing market order for Security(16841 [AMZN]) at price 346.3 at 2014-02-05 15:59:00-05:00
2014-02-05process_order:18INFOexecuting order Security(24 [AAPL])total shares 100 stock bar price: 512.61 and trade executes at: 512.635 at 2014-02-05 16:00:00-05:00
2014-02-05process_order:18INFOexecuting order Security(16841 [AMZN])total shares -100 stock bar price: 346.45 and trade executes at: 346.41 at 2014-02-05 16:00:00-05:00
2014-02-05handle_data:49INFOplacing market clear order for Security(24 [AAPL]) at price 512.61 at 2014-02-05 16:00:00-05:00
2014-02-05handle_data:51INFOplacing market clear order for Security(16841 [AMZN]) at price 346.45 at 2014-02-05 16:00:00-05:00
2014-02-06process_order:18INFOexecuting order Security(24 [AAPL])total shares -100 stock bar price: 511.49 and trade executes at: 511.465 at 2014-02-06 09:31:00-05:00
2014-02-06process_order:18INFOexecuting order Security(16841 [AMZN])total shares 100 stock bar price: 349.5 and trade executes at: 349.54 at 2014-02-06 09:31:00-05:00
2014-02-06handle_data:44INFOplacing market order for Security(24 [AAPL]) at price 512.8 at 2014-02-06 15:59:00-05:00
2014-02-06handle_data:46INFOplacing market order for Security(16841 [AMZN]) at price 354.66 at 2014-02-06 15:59:00-05:00
2014-02-06process_order:18INFOexecuting order Security(24 [AAPL])total shares 100 stock bar price: 512.47 and trade executes at: 512.495 at 2014-02-06 16:00:00-05:00
2014-02-06process_order:18INFOexecuting order Security(16841 [AMZN])total shares -100 stock bar price: 354.63 and trade executes at: 354.59 at 2014-02-06 16:00:00-05:00
2014-02-06handle_data:49INFOplacing market clear order for Security(24 [AAPL]) at price 512.47 at 2014-02-06 16:00:00-05:00
2014-02-06handle_data:51INFOplacing market clear order for Security(16841 [AMZN]) at price 354.63 at 2014-02-06 16:00:00-05:00
2014-02-07process_order:18INFOexecuting order Security(24 [AAPL])total shares -100 stock bar price: 520.655 and trade executes at: 520.63 at 2014-02-07 09:31:00-05:00
2014-02-07process_order:18INFOexecuting order Security(16841 [AMZN])total shares 100 stock bar price: 357.85 and trade executes at: 357.89 at 2014-02-07 09:31:00-05:00
2014-02-07handle_data:44INFOplacing market order for Security(24 [AAPL]) at price 519.909 at 2014-02-07 15:59:00-05:00
2014-02-07handle_data:46INFOplacing market order for Security(16841 [AMZN]) at price 361.005 at 2014-02-07 15:59:00-05:00
2014-02-07process_order:18INFOexecuting order Security(16841 [AMZN])total shares -100 stock bar price: 361.0 and trade executes at: 360.96 at 2014-02-07 16:00:00-05:00
2014-02-07process_order:18INFOexecuting order Security(24 [AAPL])total shares 100 stock bar price: 519.75 and trade executes at: 519.775 at 2014-02-07 16:00:00-05:00
2014-02-07handle_data:49INFOplacing market clear order for Security(24 [AAPL]) at price 519.75 at 2014-02-07 16:00:00-05:00
2014-02-07handle_data:51INFOplacing market clear order for Security(16841 [AMZN]) at price 361.0 at 2014-02-07 16:00:00-05:00
We will continue to look into why the order from IBM is missing one share. Feel free to let us know about any other issues.