@Peter, thank you so much for scrutinizing our model so closely! Sharing your critique gives the community a chance to improve the system - this is exactly why we decided to opensource our backtester, Zipline. I wrote a bit about the behavior of the simulation here and you can see the code here. We will also be presenting Zipline at NYC PyData in October, we'll be sharing the slides after the talk and in the meantime you can see the abstract of Thomas Wiecki's Zipline talk.
To your questions:
- In Zipline, but we haven't exposed that to Quantopian's code editor yet. The backtester code is available here. You can see that it allows a "no slippage" simulation, which disables any price history modification.
- The simulation is not currently parameterized. This is something we need to do, and has been requested frequently.
- I am very grateful that you pointed out your findings about the bid/ask spread and that you took the time to share them with the community. We want everyone to know and chime in.
- You are right that we only provide market orders, and I agree that limit orders are a critical need.
At the moment, we use a default simulation style on all backtests, which is called PARTIAL_VOLUME. The theory for this model is to approximate what your trades would have done to the buy/sell balance at the point in history. To do so, the amount of the order is compared to the volume of booked trades in the current bar. The forumla we use is:
simulated_impact = (volume_share)**2 * .1 * direction * event.price
. In addition, we limit the volume_share, which is the order's fill amount as a percentage of the bar total volume. The limit is 25%.
In the case of FXA, the volume is very thin. The security appears to trade 100k-200k per week, or an average of 100 shares per minute. Given that we are trying to fill all your orders in the subsequent minute bar, that means your orders will very often be hitting the 25% volume limit. Our slippage model would then calculate your order's price impact as (estimating $100 price): (.25)^2 *.1 * $100 = $0.625
. We apply this by adding it when you place a buy, and substracting it when you sell, so that the total spread is $1.25. This is a perfect storm for our simulator - low volume, high price, maximum slippage on virtually every order.
I can think of two ways to look at this example:
1. The price impact model we have breaks down for high price, low volume securities.
2. Our order model, rather than our slippage model, is too naive.
It took me most of today to catch up with your thinking in the last sentence of your post, but I think it is dead on. The root cause of this behavior is that the order model is too aggressive and over-simplified, and it is the order model that breaks down in thinly traded stocks.
As you mentioned, we only handle orders as market orders. Furthermore, we assume that we should fill your order as quickly as possible. In a thinly traded issue, that tends to maximize the price impact. We chose to do it this way initially because it was simplest, and because we felt users could override the behavior by adjusting order amounts. In other words, we deferred the order management to the algo writer. My take, based on your feedback here, is that we should focus on enhancing the order module to be a bit more sophisticated so that your algorithm can place limit orders, provide a fill instruction (e.g. fill over the course of a time frame, buy at the vwap, etc).
In those more sophisticated order types, I would still apply the slippage model. One goal of opensourcing the backtester is to draw more people to work on the simulator. I really like the idea of parameterizing the model because it allows backtests to be quoted with the parameters, so that the intended behavior of the simulator is clear to those interpreting the backtest results.
Now, I write all this having spent a significant amount of time and effort on the existing system, which I know could be clouding my judgment. So, I really mean it when I say: please tell me if I am wrong. All that matters is that we end up with a world class backtest and trading system. I think that is far more likely with community members like you holding Quantopian to the highest standard.
Thank you again for your careful review, and thank you for sharing it. This is exactly the kind of feedback we hoped would come from the community. Please keep it coming, and think of yourself as part of the team!