Skip to content

betting_combat.strategies.rounds_bars

rounds_bars — the rounds strategy on the information bars (Sam 2026-11-20): buy NO on ‘the fight ends before round r + 1’ when Kalshi’s NO is at least cushion under our fair value, hold to the round’s end. Everything from the venue’s own trades: the rounds group’s bars (features.group_bars: ‘ends before round r + 1’ with ‘A / B wins in round r’ pooled, features.price_bars), no stats feed, no simulation.

1 rows ``read_rows`` (the stored bars -> a row a bar of each fight-round, every member's columns, the label, the
anchor, the decision price); ``make_rows`` the same from bars already in hand (the live path's)
2 inputs ``design``: the anchor (the ends-before market's VWAP over the round's break - EXPANDING through the break's
own bars, whole for the round's; fallback the last NO print before the bell) sliding down the clock, the
clock, the bars' information (the group's flow and runs, the parts' prices and flow - never Kalshi's current
rounds price); ``events``: López's CUSUM on the group's price, ``is_event`` on the rows
3 primary ``fit`` / ``cross_fit_cards`` (PURGED: each card's rows predicted by a fit on every other card) for
``model`` 'logistic' (inputs standardised, mild ridge) or 'lgbm'; ``p_ends`` / ``fair``
4 rule ``trade``: at every bar (``act`` 'every') or at the trigger bars only ('triggers'), an order at
min(fair - cushion, max_price) from ``entry_lag`` after the bar's close to the next row's close (or the
round's end), every NO print at or under it a fill, held to the round's end; decision = the ends-before
market's last NO print at the bar
5 backtest ``fill_on_tape`` / ``money`` / ``report`` / ``backtest``: the fixed table on the real cards
6 live ``prepare_card`` (the card's rounds groups, their pre-fight trades and bar sizes), ``on_trade`` (every print
of the card into its group's stream), ``tick`` (the bars rebuilt from the whole stream - the same functions
as the table, so the live bars ARE the stored bars - tagged by the clock, the fair at the latest bar / trigger),
``plan`` (at round k's bell: round k + 1's Plan, its rule the limit from the latest fair), ``close``
7 save/load ``to_json`` / ``from_json``, ``save_db`` / ``load_db`` (features.strategy_models, strategy 'rounds_bars')
8 refresh Sam's process for any model: ``refresh(db)`` a build = every card's rows predicted by a fit on every OTHER card
(features.rounds_bars_oos: the out-of-sample fair of every training row), then the final fit on all of them
saved; ``update(db, since)`` a new card = the SAVED fit scores its rows (its out-of-sample rows, written), then
the fit redone on everything and saved. The settings fitted: ``FINAL`` (the input set + C, 11-21).

Classes

LiveBarLog

Bases: FeatureTable

features.rounds_bars_live: every bar the live run priced and every limit it held, for the card’s replay.

OosTable

Bases: FeatureTable

features.rounds_bars_oos: every training row’s out-of-sample fair (the fit that never saw its card), by version.

RoundsBars

The rounds strategy on the bars (module doc).

backtest

backtest(db: DBClient, rows: pd.DataFrame, bars: pd.DataFrame, cards: list[str] | None = None) -> tuple[pd.DataFrame, pd.DataFrame]

PURGED out-of-sample on the real cards: the fair from cross_fit_cards, the rule (self.act), the fills from the tape. Returns (the bets with their fills and money, the fixed table’s row as a one-row frame).

close

close() -> None

The card’s end: every bar priced and every limit held, written (features.rounds_bars_live).

cross_fit_cards

cross_fit_cards(rows: pd.DataFrame, cards: list[str] | None = None) -> np.ndarray

PURGED, one card at a time: each card’s rows predicted by a fit on every OTHER card’s labelled rows.

design

design(rows: pd.DataFrame, inputs: list[str] | None = None) -> pd.DataFrame

The inputs, one row a row: the anchor and the anchor x the share of the round fought, the clock (share fought, the break, the round, the last round, a five-rounder), the bars’ information (prices as log-odds).

events

events(rows: pd.DataFrame, bars: pd.DataFrame) -> pd.DataFrame

rows with is_event: López’s CUSUM (self.h, span, floor, min_bars) on each GROUP’S whole bar series (bars: the groups’ bars of this bar type, every round - a trigger needs the bars before the round).

failures

failures() -> dict[str, int]

fair

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

Our NO price: 1 - p_ends.

fill_on_tape

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

Each bet’s fills: every NO buyer’s trade at or under the limit while its order lives (trade), the cost with the fee; none after the round’s finish print + cancel_lag.

fit

fit(rows: pd.DataFrame) -> RoundsBars

On rows (labelled): the inputs (self.inputs or the design’s) standardised on these rows, the model.

from_json

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

info_columns

info_columns(rows: pd.DataFrame, prices: bool = False) -> list[str]

The bars’ information: the rounds group’s flow (r_group_), the main’s / A’s / B’s flow, the break state (brk_), the winner’s flow (w_), the normalised flows (n_). Never the group’s own price nor the main market’s price (Kalshi’s current rounds price: the fair would follow the market). prices: the in-round prices of the parts and the winner too.

label

label(bouts: pd.DataFrame) -> pd.DataFrame

A fight’s ending as the rows need it: finish (a KO / sub / DQ), end_round, scheduled.

load_db

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

make_rows

make_rows(bars: pd.DataFrame, members: pd.DataFrame, rounds: pd.DataFrame, bouts: pd.DataFrame, bar_type: str = 'dollar_runs', winner: pd.DataFrame | None = None, winner_markets: pd.DataFrame | None = None) -> pd.DataFrame

The rows from bars in hand: bars / members (features.group_bars’ columns, the rounds groups of the fights, any bar type), rounds (features.market_blocks’ rounds: bout_id, round, break_at, bell_at, round_end_at), bouts (label). A row a bar of the group ‘rounds_{r + 1}’ tagged to round r (its break’s bars too), the members as r_main_* / r_part_a_* / r_part_b_* (this round’s parts), the label y (the fight ends in round r by a finish), the clock, the anchor x_brk and its fallback, the decision price (fin_bid / fin_ask = the ends-before market’s last NO / YES prints), at = the bar’s end. Added: the BREAK STATE of the round (brk_: how the group, the main, the parts and the winner market settled in the break - fixed for the round, known at the bell), the WINNER market’s blocks over each bar (w_: its flow and runs, its price - winner: the winner group’s stream as group_stream gives it, winner_markets its markets), and NORMALISED flows (n_*: dollars over the bar size).

money

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

on_trade

on_trade(market: Market, trade: Trade) -> None

A print of the card: into every rounds group its market belongs to.

p_ends

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

The chance the fight ends this round, a row a row (blank where the anchor is blank).

plan

plan(bout_id: str, k: int, clock: FightClock, lines: Any = 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): round k + 1’s Plan per venue - buy NO on ‘ends before round k + 2’ by the rule at every moment: the limit from the latest fair (every bar, or the latest trigger), from its bar’s close + entry_lag, once the round is on; nothing after round k + 2 starts; the finish is the execution’s.

prepare_card

prepare_card(db: DBClient, bouts: list[str], **_: Any) -> None

Once a card, before its first bell: the card’s rounds groups (every ‘ends before round k’ with its parts), their trades so far (the warm-up), the bar sizes (the stored flows of the cards before x each group’s pre-fight flow).

read_rows

read_rows(db: DBClient, bouts: list[str] | None = None, cards: list[str] | None = None, bar_type: str = 'dollar_runs') -> pd.DataFrame

The rows from the stored tables (make_rows), with each round’s finish print stamp (the first YES print at FINISH_PRINT+ on the ends-before market after the break began: the rows stop there) and fin_at the fight’s end.

read_tape

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

The NO buyers’ trades of the bets’ markets, by market.

report

report(bets: pd.DataFrame, cards: list[str], col: str = 'one') -> dict[str, Any]

save_db

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

select_inputs

select_inputs(rows: pd.DataFrame, folds: int = 10, log: Callable[[str], None] | None = None) -> RoundsBars

López’s selection (strategies.inputs.InputSelector: near-copies out, ONC clusters, clustered MDA over purged card folds against 20 probes) for the outcome beyond the anchor (base: x_brk, the fair’s start) on the labelled rows; keeps inputs. Rows need event_id, date, fighter_a_id, fighter_b_id (read_rows adds them).

set_clock

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

table_row

table_row(name: str, bets: pd.DataFrame, cards: list[str]) -> dict[str, Any]

The fixed table’s row.

tick

tick(now: dt.datetime) -> None

Every tick: each live round’s group rebuilt when a print came in.

to_json

to_json() -> dict[str, Any]

trade

trade(rows: pd.DataFrame, p_end: np.ndarray) -> pd.DataFrame

The buys: the rows acted on (every bar, or the triggers), fair = 1 - p_end, the NO price = 1 - fin_bid (the last NO print), limit = min(fair - cushion, max_price), a buy where the NO price is at or under the limit (a quote on both sides, its mid inside 2-98c). Each buy’s order lives from at + entry_lag to the next acted row’s at + entry_lag (the round’s end, or the finish print + cancel_lag, if sooner).

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).

Functions

final_inputs

final_inputs(rows: pd.DataFrame) -> list[str]

The settled input set (FINAL): the rounds group’s flow, part A’s and part B’s flow, the parts’ info, the parts’ bar prices (A’s and B’s own prices, the parts’ sum) - no main, no winner, no break state, no normalised columns.

refresh

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

A BUILD (Sam’s steps 1-5): the rows of every card with bars; each card’s rows predicted by a fit on every other card (written to features.rounds_bars_oos, src ‘oos’); the final fit on every row saved as a new version. Returns the counts and the out-of-sample log loss.

update

update(db: DBClient, since: dt.date, log: Callable[[str], None] | None = None) -> dict[str, Any]

A NEW CARD (Sam’s step 6): the saved fit scores the rows of the cards from since on (their out-of-sample rows, written with src ‘saved:’), then the fit is redone on every row and saved as a new version.