Query editor
-- Kalshi-implied WTI front-month price path (implied median per event)-- Median = strike where P(close > strike) = 0.5, linearly interpolated.WITH events AS (SELECT DISTINCTevent_ticker,expected_expiration_time AS resolution_tsFROM kalshi.market_detailsWHERE series_ticker = 'KXWTI'AND expected_expiration_time IS NOT NULLAND expected_expiration_time < now()AND expected_expiration_time >= now() - interval '90' day),markets AS (SELECTticker,event_ticker,floor_strike AS strikeFROM kalshi.market_detailsWHERE series_ticker = 'KXWTI'AND floor_strike IS NOT NULL),pre_settle_p AS (SELECTm.event_ticker,m.strike,SUM(t.yes_price_dollars * t.amount_usd) / NULLIF(SUM(t.amount_usd), 0) AS p_aboveFROM kalshi.market_trades tJOIN markets m ON t.ticker = m.tickerJOIN events e ON m.event_ticker = e.event_tickerWHERE t.created_time BETWEEN e.resolution_ts - interval '24' hour AND e.resolution_ts - interval '1' hourGROUP BY 1, 2),-- Find adjacent strike pair that brackets P = 0.5neighbors AS (SELECTevent_ticker,strike,p_above,LAG(strike) OVER (PARTITION BY event_ticker ORDER BY strike) AS lo_strike,LAG(p_above) OVER (PARTITION BY event_ticker ORDER BY strike) AS lo_p,strike AS hi_strike,p_above AS hi_pFROM pre_settle_p),crossings AS (SELECTevent_ticker,lo_strike,lo_p,hi_strike,hi_p,-- Linear interpolation: median = lo_strike + (0.5 - lo_p) / (hi_p - lo_p) * (hi_strike - lo_strike)CASEWHEN lo_p IS NOT NULLAND hi_p IS NOT NULLAND lo_p > 0.5AND hi_p <= 0.5AND lo_p <> hi_pTHEN lo_strike + (0.5 - lo_p) / (hi_p - lo_p) * (hi_strike - lo_strike)