{"slug":"learn-quant-trading-open-source-book","qid":"overnight_gap","label":"Average distance from one session's close to the next session's open, monthly","post_title":"Learn Quant Trading From an Open Source Book","post_url":"/blog/learn-quant-trading-open-source-book#q-overnight_gap","columns":["month","month_label","spy_gap_bps","nvda_gap_bps"],"rows":[{"month":"2024-08","month_label":"August 2024","spy_gap_bps":61.9,"nvda_gap_bps":232.7},{"month":"2024-09","month_label":"September 2024","spy_gap_bps":33.6,"nvda_gap_bps":131.1},{"month":"2024-10","month_label":"October 2024","spy_gap_bps":30,"nvda_gap_bps":96.7},{"month":"2024-11","month_label":"November 2024","spy_gap_bps":32.9,"nvda_gap_bps":102.6},{"month":"2024-12","month_label":"December 2024","spy_gap_bps":31.7,"nvda_gap_bps":103},{"month":"2025-01","month_label":"January 2025","spy_gap_bps":54.9,"nvda_gap_bps":238.7},{"month":"2025-02","month_label":"February 2025","spy_gap_bps":31.8,"nvda_gap_bps":132.2},{"month":"2025-03","month_label":"March 2025","spy_gap_bps":56.9,"nvda_gap_bps":174.9},{"month":"2025-04","month_label":"April 2025","spy_gap_bps":130.3,"nvda_gap_bps":288.4},{"month":"2025-05","month_label":"May 2025","spy_gap_bps":69.8,"nvda_gap_bps":174.2},{"month":"2025-06","month_label":"June 2025","spy_gap_bps":32.2,"nvda_gap_bps":71.3},{"month":"2025-07","month_label":"July 2025","spy_gap_bps":22.8,"nvda_gap_bps":78.4},{"month":"2025-08","month_label":"August 2025","spy_gap_bps":25.5,"nvda_gap_bps":59},{"month":"2025-09","month_label":"September 2025","spy_gap_bps":26.5,"nvda_gap_bps":102.1},{"month":"2025-10","month_label":"October 2025","spy_gap_bps":38.6,"nvda_gap_bps":114.2},{"month":"2025-11","month_label":"November 2025","spy_gap_bps":47.6,"nvda_gap_bps":189.1},{"month":"2025-12","month_label":"December 2025","spy_gap_bps":23.8,"nvda_gap_bps":81.6},{"month":"2026-01","month_label":"January 2026","spy_gap_bps":33.8,"nvda_gap_bps":89.4},{"month":"2026-02","month_label":"February 2026","spy_gap_bps":31.4,"nvda_gap_bps":103.9},{"month":"2026-03","month_label":"March 2026","spy_gap_bps":72.4,"nvda_gap_bps":100.6},{"month":"2026-04","month_label":"April 2026","spy_gap_bps":45,"nvda_gap_bps":86.1},{"month":"2026-05","month_label":"May 2026","spy_gap_bps":31.6,"nvda_gap_bps":94.8},{"month":"2026-06","month_label":"June 2026","spy_gap_bps":51.5,"nvda_gap_bps":116},{"month":"2026-07","month_label":"July 2026","spy_gap_bps":40.8,"nvda_gap_bps":107.4}],"shape":"series","sql":"WITH sessions AS (\n    SELECT ticker,\n           toDate(toTimeZone(window_start, 'America/New_York')) AS session,\n           argMin(open, window_start) AS session_open,\n           argMax(close, window_start) AS session_close\n    FROM global_markets.delayed_stocks_minute_aggs\n    WHERE ticker IN ('SPY', 'NVDA')\n      AND toDate(toTimeZone(window_start, 'America/New_York')) >= toDate('2024-08-01')\n      AND toDate(toTimeZone(window_start, 'America/New_York')) <= toDate('2026-07-31')\n      AND (toHour(toTimeZone(window_start, 'America/New_York')) * 60\n           + toMinute(toTimeZone(window_start, 'America/New_York'))) BETWEEN 570 AND 959\n    GROUP BY ticker, session\n),\ngaps AS (\n    SELECT ticker,\n           session,\n           toFloat64(session_open) AS open_px,\n           toFloat64(lagInFrame(session_close) OVER (PARTITION BY ticker ORDER BY session)) AS prev_close\n    FROM sessions\n)\nSELECT formatDateTime(toStartOfMonth(session), '%Y-%m') AS month,\n       formatDateTimeInJodaSyntax(toStartOfMonth(session), 'MMMM yyyy') AS month_label,\n       round(avgIf(abs(open_px / prev_close - 1) * 10000, ticker = 'SPY'), 1) AS spy_gap_bps,\n       round(avgIf(abs(open_px / prev_close - 1) * 10000, ticker = 'NVDA'), 1) AS nvda_gap_bps\nFROM gaps\nWHERE prev_close > 0\nGROUP BY month, month_label\nHAVING countIf(ticker = 'SPY') > 0 AND countIf(ticker = 'NVDA') > 0\nORDER BY month","computed_at":"2026-08-02T08:19:52.321917+00:00","elapsed":0.004390577}