Skip to content

betting_combat.rounds.live.joint

Joint Kelly for one fight (strategy 4’s execution ‘joint’, 2026-10-13): the whole fight’s position rebalanced at each round break and, in-round, at every minute end. Pure: one implementation for the card run (trading.rounds), the backtests (backtest.joint) and the replay. Research: data/ufc/experiments/exact_time/jk/jk_solver.py (the solver) and midround/jk_mid.py (the decision); backtest.joint reproduces the research’s P&L to the cent.

States (the fight’s remaining outcomes at the break after round r, round_idx r): A ends in round r+1 P = P(ends this round) (layer 2, else layer 1) B ends in a later round P = 1 - P(A) - P(C) (>= 0; 0 at the last break) Cw goes the distance, a winner P = P(C) (1 - d) Cd goes the distance, a draw P = P(C) d (d: the draw share) P(C) = the distance chain (decision.Finish.p_decision); the production shade at round_idx 1 moves min(shade, P(C)) from C to B.

Instruments (payoff per contract in A, B, Cw, Cd): RY rounds ‘ends before round r+2’ YES 1 0 0 0 RN rounds ‘ends before round r+2’ NO 0 1 1 1 DY distance YES 0 0 1 1 DN distance NO 1 1 0 0 PR decision pair (both ‘by decision’) 0 0 1 0 (nothing on a draw)

The problem: maximise sum_s p_s log W_s over buys b_i >= 0 (the decision’s candidate instruments, at the all-in ask c_i) and sells 0 <= s_j <= h_j (held instruments, at the net bid q_j), with W_s = W_now_s + sum_i b_i (pay_is - c_i) + sum_j s_j (q_j - pay_js), where W_now = the notional W0 (kelly x sizing bankroll) + the fight’s cash + its holdings’ payoffs, and linear caps: buys per market per decision <= the order cap, the open cost basis <= the fight cap (a sell frees its share of the basis), and in-round each order <= the volume share of its market’s recent dollars. A log-barrier interior point (damped Newton), mu from 1e-3 down; a strictly feasible start from a phase-1 LP.

In-round (clock_probs): the break’s probabilities conditioned on no finish in the first tau seconds of the round (FinishClock: when in a round UFC finishes come, fitted on the finishes before the cutoff): A’ = A (1 - F_k(tau)) / (1 - A F_k(tau)), the rest / (1 - A F_k).

Classes

Fill

One filled order of the fight (the run’s own orders): the A-framed market, the side bought, contracts, all-in cost (fees in) and when.

FinishClock

F_k(tau): P(the finish came by tau seconds into round k | the fight ended inside round k by KO/TKO or submission), per round bucket 1, 2, 3+ (5-minute rounds), tau 0..300 s.

at

at(round_no: int, tau_s: float) -> float

fit

fit(bouts: pd.DataFrame, before: Any) -> FinishClock

From features.RawData.bouts (method, finish_round, finish_secs, date, the TIME FORMAT test round_len_ok): every KO/TKO or submission inside a 5-minute round of a bout dated before before (research midround/finish_clock.py).

from_columns

from_columns(f1: Sequence[float], f2: Sequence[float], f3: Sequence[float], before: str) -> FinishClock

A clock from its three curves (tau 0..300 s each): the research’s finish_clock.csv.

Holdings

One fight’s position at a decision: contracts and cost basis per instrument (RY / RN: the CURRENT round’s rounds market only), the fight’s cash (every cost paid, every known payout: an earlier round’s rounds market, a YES and a NO of one market that cancel), and what cannot be sold as an instrument (other: its payoff per state and its basis — an uneven pair’s extra leg, counted as paying nothing).

add

add(inst: str, contracts: float, cost: float) -> None

A buy: contracts and their all-in cost.

open_basis

open_basis() -> float

payoff

payoff() -> np.ndarray

Per state: what every holding pays.

pnl

pnl() -> np.ndarray

The fight’s P&L per state if it ended now: cash + payoffs.

remove

remove(inst: str, contracts: float, proceeds: float) -> None

A sell: contracts and the net proceeds; the basis released pro rata.

JointRule

The joint execution’s knobs: notional W0 = kelly x bankroll; caps as shares of the bankroll (the order cap per market per decision, the fight cap on the open basis); the min edge a candidate’s own instrument must clear at its ask; the round-1 shade; sells at all (V2) or not (V1).

Price

One instrument’s price at a decision: buy at the all-in ask, sell at the net bid.

Problem

matrices

matrices() -> tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray, np.ndarray]

A (states x vars, per W0-dollar), w (states, in W0), p, G, g (constraints on z).

Trade

One order the rebalance wants: buy or sell contracts of an instrument (whole for a buy, sized at the limits’ worst all-in; a sell all of the holding or whole contracts) at the decision’s price unit (all-in ask c / net bid q); dollars: the solver’s.

Var

One decision variable: a buy (kind='buy', unit = all-in cost c per contract) or a sell (kind='sell', unit = net proceeds q per contract, at most max_contracts).

effect

effect() -> np.ndarray

Wealth change per dollar of the variable in each state.

Functions

book_prices

book_prices(books: Mapping[str, Any], round_idx: int, cushion: float) -> dict[str, Price]

The instruments’ prices from the A-framed books (YES bid / ask; windows.Book or anything with bid and ask): RY / RN on ‘ends before round r+2’, DY / DN on the distance market (each only with a two-sided book), the pair on the two ‘by decision’ books (research jk_mid._minute_prices).

clock_probs

clock_probs(p4: np.ndarray, clock: FinishClock, round_no: int, tau_s: float) -> np.ndarray

(A, B, Cw, Cd) conditioned on no finish in the first tau_s of round round_no.

distance_adjusted

distance_adjusted(p_a: float, p_c: float, shift: float, skew: float, s: float) -> float

The break’s P(the fight goes the distance) corrected for the live odds (the ‘distance’ strategy, 2026-10-18): logit(p_c’) = logit(p_c) + shift + skew x s, s the winner market’s skew |mid_a - 0.5| at the break, at most 1 - p_a. Fitted walk-forward on the earlier cards’ breaks (study: data/ufc/experiments/post_1017/distance_skew): the pre-fight ‘later rounds’ factor never sees a one-sided fight, which goes the distance less than the model says (lopsided breaks -20 pp in the last 12 cards to 10-03). Breaks only: in-round, the clock-conditioned chances are calibrated against the skew already.

final_round_markets

final_round_markets(markets: Iterable[str], last: bool, on: bool) -> tuple[frozenset[str], frozenset[str]]

(the markets a decision may buy, the instruments it never buys) with the final-round switch (final_round_distance, the ‘rounds’ strategy, 2026-10-24): at the break before the fight’s last round (last) and in that round, a strategy without the distance market gets it, its YES only. In the last round “not over this round” IS “goes the distance” (the last break has no state B: state_probs), and Kalshi lists no rounds market for it (‘ends before round n+1’): the same bet, on the market that lists it, priced by the same probability. Off, elsewhere or with the distance market already its own: the strategy’s markets, nothing barred.

holdings_from_fills

holdings_from_fills(fills: Iterable[Fill], round_idx: int) -> Holdings

The fight’s Holdings at the decision of round_idx r (the break after round r, or a minute of round r+1) from its filled orders in time order.

Per market, a buy of the side held adds contracts and basis; a buy of the other side (Kalshi nets YES against NO: a sell) first cancels what is held — each cancelled pair pays 1 in every state (cash), and releases the held side’s basis pro rata (average cost) — any rest opens the other side. Then: a rounds market ‘ends before round k’ with k <= r+1 has resolved NO (the fight reached round r+1): its NO pays 1 (cash), its YES nothing; the current one (k = r+2) is RY / RN; distance YES / NO are DY / DN; the two ‘by decision’ YES legs, as many as both hold, are PR, the extra leg of an uneven pair pays nothing here (other; its basis stays in the fight cap), and a leg’s NO (never sought) pays in A, B and Cd only.

limit_price

limit_price(px: float, cushion: float) -> float

An IOC limit: the price + the cushion in whole cents (rounded up), at most 99c (backtest.working._limit).

loss_rows

loss_rows(p4: np.ndarray, holdings: Holdings, room: float) -> list[tuple[Any, float]]

The card cap as a bound on the fight’s loss in every live state: after the trades, -(the fight’s P&L in state s) <= room (the card’s loss room left for this fight). As rebalance’s extra rows (built for whichever variables it keeps).

pair_price

pair_price(a: float, b: float, ba: float, bb: float, cushion: float) -> Price

The decision pair: both legs’ asks (buy) and bids (sell).

rebalance

rebalance(p4: np.ndarray, prices: Mapping[str, Price], holdings: Holdings, buys: Sequence[str], rule: JointRule, sells: Sequence[str], buys_allowed: bool = True, vcap: Mapping[str, float] | None = None, allow_tp: bool = True, allow_cut: bool = True, markets: Iterable[str] = ('rounds', 'distance', 'decision_pair'), extra: Sequence[tuple[np.ndarray, float]] | None = None) -> tuple[list[Trade], dict[str, Any]]

One joint Kelly rebalance (research jk_mid._decide): the trades and why.

buys the decision’s candidate instruments (CANDIDATE_INST; their gate already passed): each bought only while its probability less its all-in ask clears rule.min_edge; a distance YES also opens the pair (its probability above its all-in ask) sells the instruments that may be sold (held, with a positive net bid); allow_tp False: never one priced at or above its cost per contract (taking profit); allow_cut False: never one below it (cutting a loss) vcap in-round: the most dollars each instrument may trade (its market’s recent dollars x the volume share); an instrument capped at no more than $1 drops out when any market had none extra more linear caps on the trade dollars (G row over the variables, bound in $) Sells come first in the list (the order they are sent).

single_price

single_price(ask: float, bid: float, cushion: float) -> Price

solve

solve(prob: Problem, tol: float = 1e-13) -> tuple[np.ndarray, dict[str, Any]]

The optimal trade in dollars per variable (prob.vars order) and diagnostics.

state_probs

state_probs(p_a: float, p_c: float, d: float, shade: float = 0.0) -> np.ndarray

(A, B, Cw, Cd) probabilities; the shade moves min(shade, P(C)) from C to B.