Hi -
First, thanks to everyone working on Quantopian and Zipline, I think they have great potential and cannot believe how far they have come. Despite the inclusion of advanced features like pipeline and fundamentals, I still have some concerns about the very basic underlying trading simulation.
I think the attached backtest demonstrates an issue with inaccurate simulation of limit orders.
In the backtest there are only two days with trades:
- on one day we buy by putting in a (marketable) limit order, with a limit far above the market. As this is marketable when we insert it, it should fill just as a market order would, and it does.
- on every subsequent day, at start of day we insert a limit order to sell at a fixed price of 111. When the market eventually reaches this level, our order should fill at 111 (since we have inserted a passive limit order to sell at this level). However, all the fills come in level better than our limit (as in the first case). However, this case is different! If the market "goes through" the level of a limit order which is already in the market, we still only get the limit price.
I think this is important to address: it improves the reported backtest results of any strategy using passive orders, which makes strategies look more viable for real trading than may be the case.
To be clear: this has nothing at all to do with commissions and slippage. The above issue is purely with the price of market fills, before any commission or slippage is taken into account.
I hope the example and explanation is clear. The key point is that non-marketable limit orders "resting in the market" should get filled at the limit price, or not at all. The current simulation seems to treat them as if they were re-inserted at each bar, gaining the benefit of favourable price moves and biasing the trading results upwards. This gives incorrect simulation results, compared to real trading with the same orders.