I don't quite understand the way Quantopian simulate the trade. Hope someone can help me.
Please look at the following algorithm and backtest result. The algorithm is very simple: buy XIV with all cash available. The backtest ran from 20140716 to 20140718. 20140717 was the day MH17 was shotdown in Ukraine, as a result price dropped significantly.
From the log, I can see the prices on each day are:
20140716 46.80
20140717 42.33
20140718 45.4716
On 16th, the algorithm try to buy 1000000/46.8 -> 23167 shares. If you click 'Transaction Details' page. The transaction on 16th is BUY 21367 shares of XIV @ 42.36, which seems to be the price of 17th, after MH17 was shot down.
Why? The price algo used to calculate order and the price system used to fulfill the order has 1 days gap. Just like we calculate the orders today at market close and place the order tomorrow at market close.
Why?
Ideally, the backtester should use the same price of 46.8 to fulfill the order immediately. I understand the price will move after the moment of calculation. But that should be accounted by slippage.