Files
vyndr/scripts/pwin-timeforward.sql
builtbykev e29ab6fd6a Takeable enforcement: verified on real rows, 1,006 tagged, re-stamp call ready
PART 1 verified by inducing the REAL rowsFromSnapshot over REAL lock_lines
rows from prod. Three cases, 0 non-takeable anchors:
  Narvaez  (dabble/kalshi/prizepicks/smarkets, NO takeable book)
           -> book=null, price=null, takeable=null  [honest absent]
  Schwarber(bovada/dabble/novig/PINNACLE before draftkings)
           -> draftkings +102  [pinnacle SKIPPED, proving TAKEABLE not MODEL]
  Ohtani   (dabble/onexbet before draftkings) -> draftkings -266
Narvaez is the case that matters: pre-fix he was stamped dabble +104
takeable=true; he is now honestly absent.

A HARNESS BUG RECORDED: my first verification pulled live /api/odds/mlb,
which returned {"error":"Odds data temporarily unavailable"}. The script
read that as 0 props and printed "all from takeable books? true" -- a
VACUOUSLY TRUE pass. I caught it only because I also printed the book list
and it was empty. Same family as the silent-false traps: a probe that finds
nothing looks identical to a probe that finds nothing wrong.

PART 2: 1,006 rows tagged via the purpose-built quarantine_reason at ROW
level with three sub-cases (recoverable_same_line 936, no_takeable_quote
49, takeable_line_differs 21). getModelAggregate ALREADY excluded
quarantined rows, so the public record and the n>=20 gate were clean
automatically; all five committed holdout scripts now carry the exclusion
explicitly.

PART 3 -- the re-stamp call is now fact-based. The takeable LOCK-TIME price
is recoverable for 936/1,006 (93.0%) from lock_lines, the correct
instrument. Only 431 appear in closing_captures, which is the wrong timing
for a lock price anyway.

LINE CONTAMINATION ANSWERED (previously unverified): the stored line
MATCHES a takeable book's line on 936 (93.0%), DIFFERS on 21 (2.1%), and is
unverifiable on 49 (4.9%) where no takeable book quoted the prop at all.

That makes it cleanly row-level: re-stamp the 936 as an honest JOIN and
recover 886 pending rows for the holdouts, or leave all 1,006 excluded.
Either way the 21 + 49 stay out -- re-stamping those would invent a lock
price, or a line, we never captured. Nothing re-stamped; Kev's call.

Gates: 4,111 tests / 330 suites green; next build exit 0.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QJs13VsyiSKYQP6rj3NNmc
2026-08-02 14:24:28 -04:00

43 lines
2.3 KiB
SQL

-- pwin-timeforward.sql — calibration refresh on the CURRENT MLB sample (2026-08-01)
-- MEASURE-ONLY. Time-forward: earlier games fit/observe, later games prove.
--
-- Deliberately RULER-INDEPENDENT, and that is the finding: reliability
-- (predicted vs actual hit rate) and resolution (does higher p_win hit more)
-- are both p_win-vs-outcome measures. No fair_prob appears anywhere below,
-- because none can. This is why the consensus ruler cannot change the
-- calibration verdict.
--
-- reliability = n-weighted mean |predicted - actual| across deciles. NOTE:
-- mean|p - outcome| on 0/1 rows is NOT calibration -- it is noise-dominated
-- individual error. Bucket first.
--
-- MLB only. WNBA abstains on its own data and is not re-litigated here.
--
-- CONTAMINATION EXCLUSION (2026-08-02, MANDATORY). Rows whose price/book/takeable
-- were stamped from a NON-TAKEABLE book (DFS / offshore / exchange) between
-- 2026-08-01 and the write-path fix are tagged `quarantine_reason LIKE
-- 'nontakeable_book%'`. They are EXCLUDED here and must never be pooled with
-- clean rows: their locked price -- and therefore the `takeable` flag computed
-- from it -- describes a market you could not have bet.
with base as (
select sport, game_date, p_win::numeric p, (outcome='hit')::int won,
ntile(2) over (order by game_date, id) half
from public.ledger_entries
where sport='mlb' and user_id is null
and (quarantine_reason is null or quarantine_reason not like 'nontakeable_book%') and outcome in ('hit','miss') and p_win is not null),
s as (select *, case when half=1 then 'train' else 'holdout' end split from base),
b as (select split, width_bucket(p, 0.0, 1.0, 10) bkt,
count(*) n, avg(p) pred, avg(won::numeric) actual
from s group by 1,2)
select split,
sum(n) total_n,
count(*) buckets,
round(sum(n*abs(pred-actual))/sum(n),4) reliability_mean_abs_dev,
round((select corr(p, won::numeric) from s s2 where s2.split=b.split)::numeric,4) resolution_corr,
round((select avg(won::numeric) from s s3 where s3.split=b.split)::numeric,4) base_rate,
(select min(game_date) from s s4 where s4.split=b.split) first_game,
(select max(game_date) from s s5 where s5.split=b.split) last_game
from b group by split order by split desc;