{"slug":"latency-models-in-hft-backtests","qid":"book_speed","label":"book_speed","post_title":"latency-models-in-hft-backtests","post_url":"/blog/latency-models-in-hft-backtests#q-book_speed","columns":["symbol","replaced_within_5ms_pct","replaced_within_50ms_pct"],"rows":[{"symbol":"SPY","replaced_within_5ms_pct":81.2,"replaced_within_50ms_pct":95.8},{"symbol":"AAPL","replaced_within_5ms_pct":77.4,"replaced_within_50ms_pct":88.1},{"symbol":"NVDA","replaced_within_5ms_pct":76.6,"replaced_within_50ms_pct":93.4},{"symbol":"KO","replaced_within_5ms_pct":72.8,"replaced_within_50ms_pct":83.9},{"symbol":"MSFT","replaced_within_5ms_pct":71.4,"replaced_within_50ms_pct":81.9}],"shape":"ranking","sql":"WITH gaps AS\n(\n    SELECT\n        ticker,\n        dateDiff('millisecond',\n                 lagInFrame(sip_timestamp) OVER (PARTITION BY ticker ORDER BY sip_timestamp, sequence_number\n                     ROWS BETWEEN 1 PRECEDING AND CURRENT ROW),\n                 sip_timestamp) AS gap_ms\n    FROM global_markets.cache_stocks_quotes\n    WHERE ticker IN ('AAPL', 'MSFT', 'NVDA', 'SPY', 'KO')\n      AND sip_timestamp >= '2026-09-15 14:00:00'\n      AND sip_timestamp <  '2026-09-15 15:00:00'\n      AND bid_price > 0\n      AND ask_price > bid_price\n)\nSELECT\n    ticker                                                       AS symbol,\n    round(100 * countIf(gap_ms BETWEEN 0 AND 5) / count(), 1)     AS replaced_within_5ms_pct,\n    round(100 * countIf(gap_ms BETWEEN 0 AND 50) / count(), 1)    AS replaced_within_50ms_pct\nFROM gaps\nGROUP BY ticker\nORDER BY replaced_within_5ms_pct DESC","computed_at":"2026-09-24T15:00:47.772962+00:00","elapsed":0.003139798}