I'm experimenting with a strategy that uses limit orders to enter / exit positions at the bid and ask, and backtesting against tick data. 

I noticed that the limit orders will immediately fill on the next observed tick with either bid or ask at the limit price. Example, Limit Buy to enter at 4350.00 on the S&P500 EMini, where the last Bid is 4350.00 and the last Ask is 4350.25. The order appears to fill at the next tick with Bid ≤ 4350.00, which is not realistic as there is likely additional volume in the queue ahead of my Limit Order, and in reality my order might not have even made it to the exchange by the next tick only a few milliseconds later. Because of this, the backtest  exhibits unrealistically fast order placement and fill, thus taking significantly more trades than are realistically possible for my alpha and latency infrastructure, giving a false impression of the strategy's capacity. 

131331_1626543552.jpgSome orders fill as soon as they are submitted rather than queuing / delaying

A slippage and fees model won't accurately model what I am looking to show (since I am using limit orders). Rather, I need a way to model latency or queuing, but am unsure how to interface with the Limit Order fill model. Is there any way to:

  • Add a delay for limit orders to fill? ie - with tick data occurring many times per second, the limit order should be “active” for > N milliseconds before it can possibly be filled? example, I placed the order on the tick where self.Time = 2021-07-17 12:17:15.014, rather than allowing it to fill on the next timestamp if the price is right, I can force it to wait until, say, 600 ms have elapsed, so it will only fill if the price is right and self.Time ≥ 2021-07-17 12:17:15.614
  • Coerce limit orders to fill only if the price goes past the limit order price? ie - if you have a Limit Buy at 4350.00, you will only get filled if the Bid is observed at ≤ 4349.75 rather than ≤ 4350.00
  • Utilize any sort of latency model?
  • Impart some other form of constraint to limit order queuing / filling behavior?

 

My thinking is to use a CustomFillModel that overrides the LimitFill method, but because it looks like the FillModel takes the OrderEvent object, that it's simply transforming the fill into a slippage rather than taking in a Slice or Data or Tick in order to determine if the fill (OrderEvent) was allowed, so I'm not sure if that would work.

Author