Skip to content

betting_combat.rounds.execution.engine

The execution engine (2026-11-08): one joint Kelly decision for every strategy - the fight’s whole position in the strategy’s instruments rebalanced at a break or an in-round minute. Pure: the backtest runner (backtest.execution) and the card run call the same Execution.

the problem maximise sum_s p_s log W_s over buys b_i >= 0 (the decision's candidate
instruments at their all-in ask c_i) and sells 0 <= s_j <= h_j (held
instruments at their net bid q_j): W_s = W_now_s + sum_i b_i (pay_is / c_i - 1)
+ sum_j s_j (1 - pay_js / q_j), W_now = W0 (kelly x bankroll) + the fight's cash
+ its holdings' payoffs, on the coarsest state space the instruments and holdings
tell apart (``space``); linear caps: buys per market per decision <= the order
cap, the open cost basis <= the fight cap (a sale frees its share), in-round
each order <= its volume room, the card's loss rows (``extra``)
the solver ``live.joint.solve`` (log-barrier interior point from a phase-1 LP)
the trades sells first (all of a holding, or whole contracts), then buys in whole
contracts sized at the limit's worst all-in (``Execution.worst``: the quote +
the cushion, never above the price that still clears the min edge)

Without KN the decision is live.joint.rebalance’s exactly (the same four states, variables, caps and solver; tests/unit/test_execution_engine.py).

Classes

Execution

One strategy’s decisions (settings).

candidates

candidates(ch: Chances, prices: Mapping[str, Price], quoted: Iterable[str]) -> list[str]

The break’s candidate buys among the strategy’s instruments: quoted the break’s candidate bets (one side per market, positive edge at the decision’s quote; KN: its P(no KO) above its all-in ask).

decide

decide(ch: Chances, prices: Mapping[str, Price], pos: Position, buys: Sequence[str], sells: Sequence[str], buys_allowed: bool = True, vcap: Mapping[str, float] | None = None, allow_tp: bool = True, allow_cut: bool = True, extra: Sequence[tuple[Any, float]] | None = None) -> tuple[list[Trade], dict[str, Any]]

One rebalance: the trades and why (live.joint.rebalance’s rules on any instrument).

buys the decision’s candidates (candidates): each bought only while P(it pays) less its all-in ask clears the min edge; a distance YES also opens the pair (its edge above 0) when the strategy lists PR sells the instruments that may be sold now (held, a positive net bid); allow_tp / allow_cut False: never at / above, or below, the holding’s cost per contract vcap in-round: the most dollars each instrument may trade; an instrument with no more than $1 of room drops out when any market had none extra more linear caps on the trade dollars (a row over the variables, or a function of them, and its bound in dollars): the card’s loss rows

loss_rows

loss_rows(ch: Chances, pos: Position, room: float) -> list[tuple[Any, float]]

The card cap as a bound on the fight’s loss in every live state after the trades (live.joint.loss_rows), on the decision’s space.

worst

worst(inst: str, pr: Price, p_inst: float) -> float

The most one contract of a buy can cost, fee in: its limit is the decision’s quote + the cushion (Price.worst), never above the dearest price that still clears the min edge (the card run’s limit, trading.working.price_instrument); the pair’s both legs together, never above its chance less the min edge. Contracts are sized on it: a fill at the limit never spends more than the Kelly dollars.

Position

One fight’s position in a strategy’s instruments: contracts and cost basis per instrument (RY / RN: the current round’s rounds market), the fight’s cash (costs paid, payouts known), and what is held but not tradable as an instrument (other: its payoff on the six states; its basis counts in the fight cap).

add

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

needs_split

needs_split() -> bool

open_basis

open_basis() -> float

payoff

payoff(split: bool) -> np.ndarray

Per state: what every holding pays (four or six states).

payoff6

payoff6() -> np.ndarray

remove

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

settle

settle(ended_round: bool, distance: bool, ko: bool) -> float

The fight’s P&L: the cash plus what its holdings paid (no draws: the pair pays on every decision, as the backtests settle it).

settle_round

settle_round() -> None

The fight reached the next break: the current round’s rounds market settled NO.

Var

One decision variable: a buy (unit = all-in ask c) or a sell (unit = net bid q, at most max_contracts) of an instrument, its payoff on the decision’s space.

effect

effect() -> np.ndarray

Wealth change per dollar of the variable in each state.

Functions

edge_price

edge_price(p: float, floor_edge: float) -> float

The dearest whole-cent price whose edge after the fee is still at least floor_edge: p - x - fee(x) >= floor_edge (trading.working._max_price: the fee rises with x up to 50c, so the search walks down from 99c); 0 when none.