betting_combat.models.price_simulator
price_simulator — what each market would have shown at every round start, for every fight since 2015
(Sam 2026-11-15): PriceSimulator, two stages in one class, one saved model, one refit.
STAGE 1, THE LEVEL: our fair price per market at each round start, as a range (10 / 25 / 50 / 75 / 90 %).
The target: Kalshi’s MID, (bid + ask) / 2, in the last minute before the round starts (round 1: 3 minutes
before the first bell; round k+1: the break after round k), learned on the real quotes (winner from 2025-05,
the others from 2026-01). Each market framed as the side we price (SPECS):
winner fighter A wins (an A / B mirror: A's price and B's add to 1)distance the fight goes the distancerounds no finish in the coming round (1 - 'ends before round k+2'); two rounds or more leftnoko it does not end by KO / TKO (1 - 'ends by KO / TKO')Inputs: only what every fight since 2015 has at that round start - the books’ pre-fight lines (book_,
up_book_), the round just fought and the fight so far (prev_, sofar_), the card slot
(fight_), the round context, and for the other markets our winner level. Never a venue’s price, a
model’s chance, an outcome or the date. build_inputs shapes them as each market’s symmetry needs (the
winner from A - B differences, no intercept; the others from A + B and |A - B|); process_inputs drops
the constant and duplicate ones on the training rows. Per market and round start (rounds 1, 2, 3 on their
own, 4-5 on every break’s rows): the books’ line on the log-odds scale (least squares, never shrunk), an
elastic net on what it leaves (cross-validated over whole cards in time), the range from the out-of-fold
misses (conformal: the 80 % range holds ~80 % of new prices).
STAGE 2, THE BID / ASK: what the market would have quoted around that level - the informed market. Per market and round start, on the real two-sided quotes against stage 1’s OUT-OF-SAMPLE level:
mid logit(mid) = logit(level) + a + b x (outcome - level) + size x shock b: how much the market knew the outcome beyond our level (0 at round 1: the books; winner ~0.5 at round 2, ~1 at round 3); size: the leftover miss's scale by how one-sided the fight isspread log(spread) = an elastic net on |logit(level)| and the same inputs + its own shockthe two shocks drawn TOGETHER from one real quote of the latest ``RECENT`` cards (today's market)bid = mid - spread / 2, ask = mid + spread / 2, in cents; ``DRAWS`` draws per row, seededassess_quotes gates it: fitted on the cards before the latest GATE_CARDS, simulated on those from
their level alone, a market passes when the median spread is within 2c and the real rule’s bets and money
a contract (buy at the ask CUSHION under our level, after the fee) fall inside the simulated 10-90 %.
A failing market is still simulated and flagged ({m}_sim_ok).
GUARD: the simulated quotes use the fight’s real outcome (that is how the market’s knowledge enters), so they are for testing buy rules and sizing and as the yardstick - NEVER an input to an outcome model.
OUT OF SAMPLE (Sam 2026-11-19, models.folds): the training cards are the cards with a real Kalshi quote in any
market. Each of them gets both stages from fits on ALL THE OTHER cards (out_of_sample: one card held out at a time;
its rows src ‘oos’, fold the card); the final fit on every training card forecasts every other row (all the
history: src ‘forecast’, fold ‘final’). A new card (update): the saved model predicts it (fold
‘saved:
PriceInputs the raw reads: features.final, every venue's quote at every round start (the clock from ``features.market.clock``, made exact by Kalshi's rounds tape), features.labelsquotes bid / ask / last / mid per fight x round start x market x venuePriceSimulator stage 1: fit / predict / out_of_sample / assess / check; stage 2: fit_quotes / simulate / assess_quotes; save / load / save_db / load_dbPriceModels ``features.price_level_models``: every fitted simulator, by version (with its training cards)refresh the build: out of sample for every training card, the final fit, gate, save, write the tableupdate the job's step after a card: the saved model predicts the new cards, then the refitPriceTable ``features.prices``: one row per fight x round start - the books' lines, our 10-90 % level, the simulated bid / ask ranges and one draw, each venue's real quote and its gaps, the sourceResearch: data/ufc/cito/assess/final_v1 (l01-l06 stage 1; l07 López’s minute paths - rejected: no reversion inside a round; l08-l09 stage 2).
Classes
PriceInputs
The raw reads PriceSimulator and PriceTable use (read), or handed in (tests):
final = features.final, quotes = every venue’s quote at every round start, labels =
features.labels (the outcomes stage 2 needs).
read
read(db: DBClient, schema: str = 'ufc', final: pd.DataFrame | None = None) -> PriceInputsPriceModels
Bases: FeatureTable
features.price_level_models: every fitted PriceSimulator, by version.
PriceSimulator
The level of each market at every round start, as a range (module doc). target ‘mid’ (the
line’s weight learned) or ‘move’ (the line’s weight fixed at 1: the model learns the move from
it); pool ‘core’ or ‘wide’; pooled False = rounds 1-3 on their own and 4-5 together, True =
every start after round 1 in one model with the round as an input; weight ‘none’ or ‘spread’
(a quote counts 1 / (spread + 2c)); exact train on break quotes timed by Cito or the tape only
(scores are always judged on those: the truth);
winner_input the other markets also see our winner level (how one-sided, how far it moved from
the books’ line: the winner model fitted on the same cards); offset stage 2’s mid keeps an offset
from our level (the fitted a and the recent cards’ shocks as they are) - False: the mid centred on
our level (a = 0, the recent shocks centred), the market’s knowledge and its noise kept.
assess
assess(inputs: PriceInputs, markets: tuple[str, ...] = tuple(SPECS), venue: str = VENUE) -> pd.DataFrameHalf and half: each market’s cards split in time, fit on one half, scored on the other, both ways. The held-out rows with their quote and the 10-90 % prices.
assess_quotes
assess_quotes(inputs: PriceInputs, levels: pd.DataFrame, gate_cards: int = GATE_CARDS, n: int = DRAWS) -> pd.DataFrameThe gate: stage 2 fitted on every card before the latest gate_cards (stage 1 out of sample),
simulated on those from their level alone; per market the real spread and rule against the draws
(module doc). Sets sim_ok and gate; returns the table.
check
check(inputs: PriceInputs, cards: set[str], venue: str = VENUE) -> pd.DataFrameThe saved model on cards’ real quotes (run on each new card before refitting): per
market and round start, the score.
fit
fit(inputs: PriceInputs, markets: tuple[str, ...] = tuple(SPECS), venue: str = VENUE, cards: set[str] | None = None) -> PriceSimulatorFit every market on the venue’s quotes (only on cards when given); the winner first.
fit_quotes
fit_quotes(inputs: PriceInputs, levels: pd.DataFrame, cards: set[str] | None = None) -> PriceSimulatorStage 2 on the quotes of cards (all when None) against levels (stage 1 out of sample).
from_json
from_json(b: dict[str, Any]) -> PriceSimulatorload
load(name: str) -> PriceSimulatorload_db
load_db(db: DBClient, version: str | None = None) -> tuple[PriceSimulator, pd.Timestamp] | NoneThe saved model (the latest, or version) and when it was saved; None when none is.
out_of_sample
out_of_sample(inputs: PriceInputs, venue: str = VENUE, n: int = DRAWS, n_jobs: int = 1, inner: int = INNER) -> dict[str, pd.DataFrame]Steps 3-4 (module doc): every training card priced by BOTH stages with the card in NO fit behind them. Per card:
stage 1 fitted on all the other cards prices the card (levels: bout_id, brk, market, line, q10..q90, fold the
card held out); stage 2 fitted on the other cards’ quotes against THEIR levels made out of sample among themselves
(inner runs of the other cards, the held-out card in none: one simulator’s output feeding the next is out of
sample too), drawn on the card from its own level: sims (the n-draw ranges, as simulate) and draw
(one draw a row: bout_id, brk, market, draw, level, bid, ask). Each card’s draws are seeded by the card.
predict
predict(final: pd.DataFrame, markets: tuple[str, ...] | None = None) -> pd.DataFrameEvery market’s 10-90 % prices for final’s rows: bout_id, brk, market, line, q10..q90.
quote_rows
quote_rows(inputs: PriceInputs, levels: pd.DataFrame, venue: str = VENUE) -> pd.DataFrameThe real two-sided quotes stage 2 learns from: per fight x round start x market (round 1, or a
break on an exact clock), bid / ask / mid / spread, our level (levels: bout_id, brk, market,
q50 - out of sample for these fights), the outcome (y), the card and date.
rows
rows(inputs: PriceInputs, market: str, venue: str = VENUE) -> pd.DataFramefeatures.final rows of market (enough rounds left, a books’ line) with the venue’s
usable quote where there is one (price, spread).
save
save(name: str | None = None) -> PathTo a file beside this module (research; the job keeps its models in the database: save_db).
save_db
save_db(db: DBClient) -> dict[str, int]Into features.price_level_models (one row per version: when, the setup and every fit as JSON).
score
score(pred: pd.DataFrame, price: pd.Series) -> dict[str, float]score_levels
score_levels(inputs: PriceInputs, levels: pd.DataFrame, venue: str = VENUE) -> pd.DataFrameLevels (out of sample) against the venue’s real mids on the exact clock (round 1, or a break Cito / the tape timed): per market and round start, the score (n, off_c, bias_c, cov80, cov50, width80_c).
simulate
simulate(final: pd.DataFrame, levels: pd.DataFrame, labels: pd.DataFrame | None, n: int = DRAWS, seed: int = 0, raw: bool = False, real: pd.DataFrame | None = None) -> pd.DataFramen bid / ask draws per row of levels (bout_id, brk, market, q50) - the same seed and rows,
the same draws. The outcome (labels) carries the market’s knowledge; a fight to come draws with
none. raw: every draw (bout_id, brk, market, draw, bid, ask); else per row the 10 / 50 / 90 % of the
bid and the ask and the median spread, and with real (bout_id, brk, market, ask) the share of
draws asking less than the real ask (ask_pct).
to_json
to_json() -> dict[str, Any]training_cards
training_cards(inputs: PriceInputs, venue: str = VENUE) -> set[str]The cards a fit learns from: every card with a usable quote on venue in any market.
PriceTable
Bases: FeatureTable
features.prices: one row per fight x round start since 2015. Per market m: book_{m} (the books’ line
for it, and for the winner its open), {m}_q10 .. {m}_q90 (ours), {m}_src ‘oos’ (a training card: priced by
fits that held its card out - fold the card, or ‘saved:fold ‘final’), {m}_gap_close (our middle less the books’ close; the
winner also _gap_open), per venue {venue}_{m}_bid / _ask / _mid / _spread (Polymarket: its last) and
{venue}_{m}_gap (the venue less our middle), and clock (who timed the round start the venues’ quotes were read
at: cito / tape / derived). Stage 2 per market, from the same fits as the level: {m}_sim_bid_q10 / _q50 / _q90,
{m}_sim_ask_q10 / _q50 / _q90, {m}_sim_spread (the median), {m}_sim_ok (passed the gate), {m}_draw_bid /
{m}_draw_ask (one simulated draw: the block prices’ bell), and where Kalshi quoted it kalshi_{m}_ask_pct (the
share of draws asking less than the real ask) and kalshi_{m}_ask_gap_sim (the real ask less the draws’ median
ask). src / fold (the row’s, the same for every market), version (the run). The simulated quotes used the
fight’s real outcome: never an input to an outcome model (module doc).
build
build(db: DBClient, base: Base | None = None) -> dict[str, int]Every row (the base is not read: the inputs are in hand).
compute
compute(base: Base | None = None) -> pd.DataFrameread_table
read_table(db: DBClient) -> pd.DataFramewrite_rows
write_rows(db: DBClient) -> dict[str, int]The rows of only (a new card’s: the update).
Spec
One market: odd (the A / B mirror: built from differences, no intercept) and the fewest
rounds left it trades with.
Functions
build_inputs
build_inputs(final: pd.DataFrame, spec: Spec, pool: str = 'core') -> pd.DataFrameThe candidate inputs for spec (deterministic: the same columns for any rows): the winner
from A - B (pairs differenced, the odd columns as they are); the others from A + B, |A - B| and
the columns without a side. Plus the round context (the others only: it has no sign).
group_of
group_of(brk: Any) -> np.ndarraynumbers
numbers(final: pd.DataFrame) -> pd.DataFrameThe round numbers (DIFF + BOTH) and each market’s books’ line (line_<market>) of
features.final rows, on their key. Before round 1 the round numbers are zero.
process_inputs
process_inputs(X: pd.DataFrame, max_corr: float = 0.98, min_unique: float = 0.01) -> list[str]The selection from training rows X: drop columns that are blank, constant or nearly so (the
commonest value on more than 1 - min_unique of rows), then of any pair correlated above
max_corr keep the first.
quotes
quotes(wanted: pd.DataFrame, at: pd.DataFrame) -> pd.DataFrameOur side’s bid / ask / last / mid per fight x round start x market x venue (wanted with its
read at, joined on the row number i); age_min = minutes since the venue last changed;
ok = a mid inside MAX_SPREAD and PRICE_RANGE (a venue with no book: its last).
read_at
read_at(w: pd.DataFrame) -> pd.SeriesWhen each wanted quote is read: the round’s start (round 1: PRE_OFFSET before it).
refresh
refresh(db: DBClient, n_jobs: int = 4) -> dict[str, Any]THE BUILD (module doc): read the inputs; every training card priced out of sample by both stages (one card held
out at a time); the final fit on every training card (stage 1, then stage 2 on the out-of-sample levels, gated
first); saved; features.prices written whole - the training cards’ rows out of sample, every other row forecast
by the final fit - through the guard.
round_starts
round_starts(clk: pd.DataFrame) -> pd.DataFrameEach fight’s round starts from the market table’s clock (features.market.clock, with the
rounds tape): brk 0 = the first bell, brk k = the start of round k+1; bout_id, brk, start,
flag_clock (its teller: 0 Cito told it, 3 the rounds tape, 1 derived from the settle).
update
update(db: DBClient) -> dict[str, Any]STEP 6, after a card (module doc): the saved model prices the cards it never learned from - those now with a quote
out of sample (fold ‘saved:features.prices;
those rows written (through the guard); then the final model refitted on every training card (stage 2 on the
out-of-sample levels: the table’s and the new ones), gated, saved. The history’s rows stay as they were priced.