{"slug":"missed-the-best-days","qid":"by_year","label":"SPY's 20 best and 20 worst days since 2016, counted by year","post_title":"What Missing the Best Days Costs","post_url":"/blog/missed-the-best-days#q-by_year","columns":["year","best_20_days","worst_20_days"],"rows":[{"year":2016,"best_20_days":0,"worst_20_days":1},{"year":2017,"best_20_days":0,"worst_20_days":0},{"year":2018,"best_20_days":1,"worst_20_days":2},{"year":2019,"best_20_days":1,"worst_20_days":0},{"year":2020,"best_20_days":11,"worst_20_days":9},{"year":2021,"best_20_days":0,"worst_20_days":0},{"year":2022,"best_20_days":5,"worst_20_days":5},{"year":2023,"best_20_days":0,"worst_20_days":0},{"year":2024,"best_20_days":0,"worst_20_days":0},{"year":2025,"best_20_days":2,"worst_20_days":3},{"year":2026,"best_20_days":0,"worst_20_days":0}],"shape":"ranking","sql":"WITH daily AS (\n    SELECT toDate(toTimeZone(window_start, 'America/New_York')) AS dt,\n           argMax(toFloat64(close), toTimeZone(window_start, 'America/New_York')) AS c\n    FROM global_markets.delayed_stocks_minute_aggs\n    WHERE ticker = 'SPY' AND window_start >= '2016-01-01'\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 dt\n),\nrets AS (\n    SELECT dt, c / lagInFrame(c) OVER (ORDER BY dt) - 1 AS ret FROM daily\n),\nclean AS (\n    SELECT dt, ret FROM rets WHERE ret IS NOT NULL AND ret > -0.5 AND ret < 0.5\n),\nranked AS (\n    SELECT dt, ret,\n           row_number() OVER (ORDER BY ret DESC) AS best_rnk,\n           row_number() OVER (ORDER BY ret ASC) AS worst_rnk\n    FROM clean\n)\nSELECT toYear(dt) AS year,\n       countIf(best_rnk <= 20) AS best_20_days,\n       countIf(worst_rnk <= 20) AS worst_20_days\nFROM ranked\nGROUP BY year\nORDER BY year","computed_at":"2026-07-16T11:18:59.136509+00:00","elapsed":0.003393905}