Skip to content

betting_combat.strategies.rounds

rounds — the rounds strategy on the 30-second blocks (Sam 2026-11-19): buy ‘no finish this round’ (NO on Kalshi’s ‘ends before round r + 1’) at any block of the round - the break’s two and the round’s - when it is cheaper than our fair price, held to the round’s bell. ONE class, RoundsStrategy, one method per step, the proven way of each its _baseline:

1 rows ``read_rows``: every block row of the fight (features.inround_rows: the break's two and the round's,
everything as the live feed showed it by the block's end) + the label (y_ends_round: the fight ends
before this round's bell, any way but going the distance) + our price level at the round's bell
(features.prices: 1 - rounds_q50, the last round 1 - distance_q50; inside 1-99 %) + the round-start
table's pre-fight groups (join_prefight); ``traded``: rounds 2+ with a rounds contract after
2 inputs ``select_inputs``: López's (strategies.inputs.InputSelector) on rows drawn so every row has the same chance
(a block position drawn before looking at each round - never by how many rows a round has); the kept
inputs saved with the fit
3 primary ``fit_primary_baseline`` / ``p_ends``: LightGBM from the price - a discrete-time survival row per block
(the fight still on), the target y_ends_round, the starting point our level's log-odds (init_score),
the kept inputs + the time; the settings ``PRIMARY`` (purged research, 11-19); ``cross_fit``: each card
priced by fits that never saw it (purged card folds); ``fair``: 1 - p_ends (the NO side)
4 the rule ``trade_baseline`` (= ``compute_signals``): at every block end of a traded round, buy when the NO ask (1 - the finish bid) <= fair
- ``cushion`` and <= ``max_price``; variants beside it (``guard``: 'crash' - no new buy once the NO price
fell ``crash_drop`` under the round's first; 'knockdown' - none in the block after a knockdown)
5 backtest ``read_tape`` + ``fill_on_tape``: the order lives to the next block's end; every NO buyer's trade on
Kalshi's tape at or under the limit fills us too, at its price, up to ``order_cap`` a block, none after
the market saw a finish (a YES print at 97c+) + ``cancel_lag``; ``money`` / ``report``: one contract a
bet and the dollars, win rate, average win and loss, a card, Sharpe a card, PSR / DSR, the worst card
6 live ``prepare_card`` (once a card) and ``plan`` (at each round's bell): one Plan for the coming round's
contract whose rule re-prices at every block end from the fight's live blocks (live.blocks: the same
feature code on the live feed) - the execution holds the take at the limit between blocks
7 save/load ``to_json`` / ``from_json`` (the LightGBM model as text, the inputs, the settings), ``save_db`` /
``load_db`` (features.strategy_models); ``refresh``: the job's step (the saved fit checked on the cards
since it was fitted, refitted on every row, saved)

Research: data/ufc/cito/assess/inround_grain (g20-g28: the rows, the selection, the models, the tape, the meta).

Classes

LiveBlockLog

Bases: FeatureTable

features.rounds_live_blocks: the card run’s every block priced (p, fair, its moment) and every venue’s gate look (the limit or none, the quote then) - the card beside the backtest block by block.

RoundsStrategy

The rounds strategy on the blocks (module doc). Settings first, then what the fit learns (saved whole by save_db).

attach

attach(X: pd.DataFrame, pre: pd.DataFrame, lv: pd.DataFrame) -> pd.DataFrame

The model’s row from the block rows X (features.inround_rows’ - the training’s or the live feed’s): the round’s pre-fight groups (pre: features.final’s / LiveFinal’s round-start row by bout_id + brk, fight_ named event_, as float32), our level at the round’s bell (lv: levels’ - x, pf, last, lv_winner, lv_distance, lopsided; a row without one dropped) and the year. ONE function for the training rows and the card run’s.

check

check(rows: pd.DataFrame) -> dict[str, float]

The saved fit on rows it never saw (the cards since it was fitted, labelled, traded): its log loss against our level’s (the starting point alone).

close

close() -> None

The card’s end: every block priced and every gate’s look written (features.rounds_live_blocks), so the card can be put beside the backtest block by block.

cross_fit

cross_fit(rows: pd.DataFrame, k: int = 4, embargo_days: int = 28) -> pd.Series

Each labelled row’s p_ends from a fit that never saw its card (purged card folds by fight).

cross_fit_bayes

cross_fit_bayes(rows: pd.DataFrame, variant: str = 'v1', groups: list[list[str]], n_jobs: int = 1, **settings: Any) -> pd.Series

PURGED (strategies.bayes.cross_fit_cards): each group of cards (one card a group: one held out at a time) predicted by a Bayes fitted on every card outside it - the out-of-sample p_ends on rows’ index.

cross_fit_cards

cross_fit_cards(rows: pd.DataFrame, variant: str = 'v1', cards: list[str] | None = None, n_jobs: int = 1) -> pd.Series

PURGED, one card at a time (strategies.logistic.cross_fit_cards): each of cards (None: every card) predicted by a logistic fitted on every other card’s rows - the out-of-sample p_ends on rows’ index.

failures

failures() -> dict[str, int]

The live path’s failures this card (the card’s summary): the live blocks’ refreshes, each round’s pricing.

fair

fair(rows: pd.DataFrame) -> np.ndarray

Our fair price of ‘no finish this round’ (the NO side).

features

features() -> list[str]

The primary’s inputs: the kept + the time.

fill_on_tape

fill_on_tape(bets: pd.DataFrame, tape: dict[str, pd.DataFrame], fin: pd.Series) -> pd.DataFrame

Each bet’s fills (n contracts, cost with the fee): the order lives from the row’s moment (the block’s end + entry_lag, as live) for WINDOW_S; every NO buyer’s trade at or under the limit fills us too at its price, up to order_cap; none after the round’s finish print (the first YES print at 97c+ since the round opened) + cancel_lag.

fit_bayes

fit_bayes(rows: pd.DataFrame, variant: str = 'v1', **settings: Any) -> Any

One Bayesian round-hazard fit on rows (strategies.bayes.Bayes: ‘v1’ the starting price alone, ‘v2’ + the price features, ‘v3’ + the stats, ‘v4’ both): its p_ends(rows) the chance the fight ends in this round.

fit_logistic

fit_logistic(rows: pd.DataFrame, variant: str = 'v1') -> Any

One logistic fit on rows (labelled, priced): its p_ends(rows) the chance the fight ends in this round.

fit_primary_baseline

fit_primary_baseline(rows: pd.DataFrame) -> RoundsStrategy

LightGBM from the price on rows (labelled): init_score our level’s log-odds, trees trees, params.

fresh

fresh(**change: Any) -> RoundsStrategy

The same settings, nothing fitted (change: settings to change).

from_json

from_json(b: dict[str, Any]) -> RoundsStrategy

labelled

labelled(rows: pd.DataFrame) -> pd.DataFrame

level_at

level_at(bout_id: str, k: int, lines: dict[str, dict[int, dict[str, Any]]]) -> tuple[pd.DataFrame, pd.DataFrame]

Break k’s round-start row (LiveFinal.at_break on the lines at the bell) and our levels for round k + 1 by the training’s own levels (empty: outside 1-99 %). The row is kept (_card['finals']): the typicals of round k + 1 (and of round k + 2’s round before); the row of break k - 1 too when the card run gave no bell for it.

load_db

load_db(db: DBClient, version: str | None = None) -> tuple[RoundsStrategy, pd.Timestamp] | None

The saved strategy (the latest, or version) and when it was saved; None when none is (older kinds skipped).

logistic_inputs

logistic_inputs(rows: pd.DataFrame, variant: str = 'v1') -> pd.DataFrame

The logistic’s inputs of rows (strategies.logistic.design): ‘v1’ the round’s starting price, the block, the round; ‘v2’ + the finish market’s price at the block’s end and what it has done.

money

money(bets: pd.DataFrame) -> pd.DataFrame

Each bet’s money: one contract (paid 1 if no finish, less the ask and the fee) and, with fills, the dollars.

p_ends

p_ends(rows: pd.DataFrame) -> np.ndarray

The primary’s chance the fight ends before this round’s bell, per row.

pick_prices

pick_prices(R: pd.DataFrame, real_q: pd.DataFrame, sim_q: pd.DataFrame, real_price: bool, clock: pd.DataFrame | None = None) -> pd.DataFrame

R (the rows: bout_id, round, block, last, the level’s x / pf / lv_winner / lv_distance, sim_price_src) with each market’s prices from one source a fight: Kalshi’s real block quotes (real_q: {m}_bid / {m}ask) when real_price and Kalshi quoted that market in the fight - a block it showed no quote in: blank - else the simulated draw’s (sim_q). Adds: fin_bid / fin_ask (the finish market’s), price_src (its: ‘real’, else the simulated rows’ ‘oos’ / ‘forecast’), price_clock, the pxf features of the chosen path (features.price_features), and the round’s starting prices where the market’s are real - Kalshi’s actual middle at the bell (a round’s block: the last usable one of its break, -2 then -1; a break’s block: the last usable up to it, nothing later; usable: two-sided, its spread within START_MAX_SPREAD, inside START_RANGE - as the price level’s own target): x / pf from the finish market (the last scheduled round, which has none: 1 - the distance’s), lv_winner, lv_distance, lopsided; start_src ‘real’, or ‘level’ (our price level: no real market, or no usable quote by then).

pick_stats

pick_stats(real: pd.DataFrame, sim: pd.DataFrame, src: pd.DataFrame) -> pd.DataFrame

One row per block from the two draws’ rows: a round the live feed read (it is in real: draw 0’s rows) on its real rows, every other round on its simulated ones (sim: draw 1’s); stats_src ‘real’, else the simulated round’s own (‘oos’ / ‘forecast’: src - bout_id, round, stats_src, sim_price_src). A row is whole from one draw: its so-far and round-before stats are that draw’s.

plan

plan(bout_id: str, k: int, clock: FightClock, lines: BreakLines | None, now: dt.datetime, settings: dict[str, dict[str, Any]] | None = None) -> tuple[list[Plan], str | None, dict[str, Any]]

At round k’s bell (the break’s start): a plan per venue for round k + 1’s contract, or none and why. Its rule buys at each block’s row (priced by tick) from the row’s moment for WINDOW_S when the quote then passes the backtest’s gate. No stats at the bell, no trade (the inputs would not be the training’s).

prepare_card

prepare_card(db: DBClient, bouts: list[str], replay_lag_s: float | None = None) -> None

Once a card, before its first bell: the round-start rows (features.live_final: everything known before the fights, the typicals, the pre-fight groups), the saved price simulator (our levels at each bell), the live blocks’ reader (replay_lag_s: a replay on the archive - live.blocks).

read_real_quotes

read_real_quotes(db: DBClient) -> pd.DataFrame

Kalshi’s real ‘ends before’ quote at every real block’s end (features.market_blocks, every fight with a clock - Cito’s, the tape’s or the trades’): bout_id, round, block, fin_bid, fin_ask (the finish-this-round market’s YES).

read_rows

read_rows(db: DBClient, real_stats: bool = True, real_price: bool = True, inputs: list[str] | None = None, bouts: set[str] | None = None) -> pd.DataFrame

ONE row per block of every fight (Sam 11-19): real data where it exists and its switch is on, the simulators’ elsewhere (features.inround_blocks: draw 0 the real feed, draw 1 simulated - a real fight’s simulated rows out of sample), and every row says where each side came from.

real_stats True: a round the live feed read (Cito) has its real stats; False: every round the simulated ones (stats_src: ‘real’ / ‘oos’ / ‘forecast’; draw: 0 real stats, 1 simulated) real_price True: a fight Kalshi quoted has Kalshi’s real prices - per market: each block’s quote (blank where Kalshi showed none) and the round’s starting price; False: every fight our own (the price level at the round’s start, the simulated quotes in its blocks) (price_src: the finish market’s) Any of the four combinations (pick_stats / pick_prices).

The columns: KEY, brk, event_id, date, fighter_a_id, fighter_b_id, division, title; y (the label: the fight ends in this round, any way but the distance); x / pf (the round’s starting price: the chance it ends the fight, x its log-odds - Kalshi’s actual at the bell or our level, start_src ‘real’ / ‘level’), last; the finish market’s quote at the block’s end the rule trades against (fin_bid / fin_ask), price_clock (who timed a real quote’s blocks: cito / told / tape / derived); blk_kd; the TIME inputs; the model inputs (inputs: those; None: every one; []: none beyond the starting prices and the price features) - lv_winner / lv_distance / lopsided (the winner’s and the distance’s starting prices, by the same rule as x) and pxf_* (features.price_features: what each market’s price has done up to the block’s end, the same columns from real and simulated prices).

read_tape

read_tape(db: DBClient, bets: pd.DataFrame) -> tuple[pd.DataFrame, dict[str, pd.DataFrame], pd.Series]

The bets’ order windows (market_id, block_end_at) and the tape of their markets: (bets with the windows, the NO buyers’ trades by market, when each market saw the finish).

real_rows

real_rows(rows: pd.DataFrame, quotes: pd.DataFrame) -> pd.DataFrame

The rows a real backtest trades: a fight the live feed read on its real rows (draw 0), any other with a real quote on its simulated draws (each draw weighted 1 / draws); every row’s quote Kalshi’s real one (read_real_quotes). Adds w (the row’s weight).

report

report(bets: pd.DataFrame, cards: list[str], col: str = 'one', weight: str | None = None, trials: int = 1, var_sr: float = 0.0) -> dict[str, Any]

The bets told card by card (col: ‘one’ contract a bet, ‘dollars’; weight: a row weight, e.g. 1 / draws): bets, won, average win and loss, a contract, total, a card, Sharpe a card, PSR, DSR (trials / var_sr), worst card, cards up.

save_db

save_db(db: DBClient, keep: int = KEEP) -> dict[str, int]

Into features.strategy_models (one row per version); the latest keep versions stay whole.

score

score(rows: pd.DataFrame, p: Any, others: dict[str, Any] | None = None) -> dict[str, Any]

A prediction against what happened (strategies.logistic.score): rows, the finish rate, the mean prediction, the log loss - and others (the market’s own price, another model) on the same rows.

select_inputs

select_inputs(rows: pd.DataFrame, seed: int = 0, folds: int = 5, log: Callable[[str], None] | None = None) -> RoundsStrategy

López’s selection (InputSelector) for the primary’s outcome beyond the price (base: x) on one block a fight-round a draw at a position drawn before looking (every row the same 1 / 12 chance); keeps inputs.

set_clock

set_clock(now: Callable[[], dt.datetime]) -> None

The card run’s clock (the session’s: a replay’s own) for the live blocks’ reads.

tick

tick(now: dt.datetime) -> None

The card run’s tick: the live blocks re-read on the session’s clock (in their own task: never delaying the executor), then every new block of the rounds planned priced (once, here - never in a rule).

to_json

to_json() -> dict[str, Any]

trade_baseline

trade_baseline(rows: pd.DataFrame, fair: np.ndarray | None = None) -> pd.DataFrame

The rule at every block end: the rows it buys, with ask (the NO ask = 1 - fin_bid), fair, limit (min(fair - cushion, max_price)); traded rounds, the blocks window, a quote on both sides, its mid inside 2-98c.

traded

traded(rows: pd.DataFrame) -> pd.Series

The rows the rule may trade: rounds 2+ with a rounds contract after (never round 1, never the last round).

StrategyModels

Bases: FeatureTable

features.strategy_models: every fitted strategy, by strategy and version.

Functions

fee

fee(price: Any) -> Any

levels

levels(prices: pd.DataFrame, bouts: pd.DataFrame) -> pd.DataFrame

Our price level at each round’s bell (bout_id, brk): pf = our level’s chance the coming round ends the fight (1 - rounds_q50; the last scheduled round 1 - distance_q50), x its log-odds; only inside 1-99 % (a level outside is no row); our winner and distance levels there too (lv_winner, lv_distance; lopsided = |lv_winner - 0.5|) - model inputs.

refresh

refresh(db: DBClient, log: Callable[[str], None] | None = None) -> dict[str, Any]

The rounds strategy after new cards (the job’s step): the saved fit checked on the cards since it was fitted (before it sees them), the primary refitted on every labelled simulated row with the saved inputs and settings, saved.