Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Limit buy order not filled even though limit price between high and low

Hi Everyone
At 9:31EST on 2017-01-04 I put in a limit order to buy CTSH at 56.61.
The open, high, low, close, vol, adj_close for CTSH on that date is:
2017-01-04 56.48 57.400002 56.200001 57.32 3572400 56.512562
The opening order and subsequent cancel of the order is shown below.
Does anyone know what price is used for a fill?
Is it data.current(stock, 'price') or data.current(stock, 'close')?
Any insight on how to determine what price in each minute bar is used to fill a buy order and sell order is very much appreciated.
Kind regards and a pleasant weekend
Savio

2017-01-04 09:31 handle_data:41 INFO Stk: Equity(18870 [CTSH]) Shares:    700 Limit Price: 56.61 Open: 56.48  
2017-01-04 16:00 WARN Your order for 700 shares of CTSH failed to fill by the end of day and was canceled.  
End of logs.  
3 responses

The price used to fill an order, and whether an order fills at all, is determined by the slippage model (see https://www.quantopian.com/help#ide-slippage ). One can select different models and even write a custom method. The default method however, looks the closing price at each minute and then fills the order at 5 basis points worse than that price. Look at the documents in the link above for a better explanation.

One other critical piece of info to understand about the Quantopian backtest engine (ie Zipline) is that orders are filled beginning at the next minute bar. So, while the limit order above was placed at time 9:31 it wasn't executed until time 9:32. Also note that the prices fetched at time 9:31 are really data from the previous minute (ie at minute 9:31 I can know the close price from the previous minute. I can't know the close price of the current minute because it hasn't happened yet).

The reason a limit order for 56.61, placed at 9:31, never fills is that the close price at minutes 9:32 and then the rest of the day was always higher than the limit price.

See attached notebook. Hope that helps.

Hello Dan
Thank you very much - that is most helpful.
As well for the notebook - that level is detail is awesome.
Much appreciate and happy Sunday
Savio

Hi Dan,

Thank you for always being so helpful!

Am I right in saying that the ‘price’ bar is forward filled so one has to be careful when using it to avoid any look ahead bias?