Query editor
-- Summary: Average calibration error by horizon-- Excludes 0-10% and 90-100% buckets (extreme prices distort)WITH accuracy_data AS (SELECToutcome,price_4h_before, price_1d_before, price_1w_before, price_1m_before,CASE WHEN lower(outcome) = 'yes' THEN 1.0 ELSE 0.0 END as actualFROM dune.polymarket.result_polymarket_dataWHERE lower(outcome) IN ('yes', 'no')),all_horizons AS (SELECT '1: 4 hours' as horizon, price_4h_before as price, actualFROM accuracy_data WHERE price_4h_before IS NOT NULLUNION ALLSELECT '2: 1 day', price_1d_before, actualFROM accuracy_data WHERE price_1d_before IS NOT NULLUNION ALLSELECT '3: 1 week', price_1w_before, actualFROM accuracy_data WHERE price_1w_before IS NOT NULLUNION ALLSELECT '4: 1 month', price_1m_before, actualFROM accuracy_data WHERE price_1m_before IS NOT NULL),-- Only look at "interesting" price range (10-90%) where calibration mattersfiltered AS (SELECT * FROM all_horizonsWHERE price >= 0.10 AND price < 0.90),bucketed AS (SELECThorizon,FLOOR(price * 10) / 10 as bucket_floor,AVG(price) as avg_price,AVG(actual) as actual_rate,ABS(AVG(actual) - AVG(price)) as abs_error,COUNT(*) as nFROM filteredGROUP BY horizon, FLOOR(price * 10) / 10)SELECThorizon,SUM(n) as total_markets,ROUND(AVG(abs_error) * 100, 1) as avg_abs_calibration_error_pp,ROUND(MAX(abs_error) * 100, 1) as worst_bucket_error_pp,ROUND(AVG(POWER(abs_error, 2)) * 10000, 1) as mean_squared_error_x10kFROM bucketedGROUP BY horizonORDER BY horizon