Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
How can the submitted order be filled immediately?

When I review the back-testing results, I find that the orders are always been filled in the next trading day. This may effect the performance of the trading strategy.

For example, the trading signal tells that the portfolio should be re-balanced on 2003/1/6. By "History" function, I am able to get all the data on and before 2003/1/6. Also, I calculate the trading amount of each securities based on that. However, the back-testing results shows that the order is made on 1/6, but filled on 1/7, at the price on 1/7. So, my confusion is all the trading amount is calculated on 1/6, but the transaction is actually made on the next trading day. I wonder if it is possible to make orders be filled in the same day in zipline, or there is another way to fix this problem.

In addition, there is a optional parameter "instant_fill" in class "TradingAlgorithm", which is to determine whether to fill orders immediately or on next bar. The default value is False. However, I don't find the declaration and any usage of this parameter. I wonder if this parameter is no longer used in Zipline, and if there is another similar parameter to use.

I really appreciate your opinions on the issue. Thank you!

1 response

Orders shouldn't be getting filled on the next trading day. On the Quantopian platform "All open orders are cancelled at the end of the day, both in backtesting and live trading" (see the documentation https://www.quantopian.com/help#ide-ordering). So, if you place an order today it will try to get filled today and then cancelled at the end of the day. It won't fill the following day.

Secondly, if you want to change how orders are filled during backtesting, one should specify the slippage function. By default (if no slippage is explicitly set) the backtest engine will fill an order by allocating a max of 2.5% of the minute bar volume to the order. If one places an order for 100 shares of XYZ and the next 4 bars (minutes) of volume are 1000, then the order would be filled with 25 shares at each bar (for a total of 100 shares). See the documentation https://www.quantopian.com/help#ide-slippage).

If one wants to "instant fill" an order then explicitly set slippage to FixedSlippage. This mode completely fills an order at the first non-zero volume bar (again see the documentation).

Maybe attach an algorithm/backtest to highlight the order fill behavior you are seeing if you are still confused?