Why Your Optimal Bet Is Provably Optimal: Convex Optimisation for Sports Trading (Part 1)

You have three edges on this Saturday's card. Frankel to win the 2:30 at 5% edge, Constitution Hill in the 3:15 at 12% edge, and Enable in the 4:00 at 3% edge. Your bankroll is £3,000. Liquidity caps each bet at different levels. How much do you stake on each?

Most punters go by feel. Some use Kelly. But very few can answer this question: how do you know your staking plan is actually optimal? Not "pretty good." Not "better than last time." Provably optimal — with a certificate you can check.

That certificate comes from convex optimisation and duality theory. The same mathematics that powers every serious pricing engine, arbitrage detector, and market-making algorithm in quantitative finance. This post introduces the core ideas — Lagrangians, KKT conditions, weak and strong duality — and shows what they mean for betting decisions.


The Problem: Constrained Staking

Let's make the Saturday problem concrete.

Race Selection Estimated edge Max stake (liquidity)
2:30 Newmarket Frankel 5% £2,000
3:15 Cheltenham Constitution Hill 12% £500
4:00 Ascot Enable 3% £5,000

Your total bankroll is £3,000. You want to maximise expected profit:

$$ \text{maximise} \quad 0.05\,x_1 + 0.12\,x_2 + 0.03\,x_3 $$

subject to:

$$ x_1 + x_2 + x_3 \leq 3{,}000, \qquad 0 \leq x_1 \leq 2{,}000, \qquad 0 \leq x_2 \leq 500, \qquad 0 \leq x_3 \leq 5{,}000 $$

This is a constrained optimisation problem. The objective is linear, the constraints are linear. Simple enough to solve by hand — but the method generalises to problems with thousands of markets, non-linear objectives, and complex cross-constraints. That method is Lagrangian duality.


The Lagrangian: Softening Constraints into Prices

Hard constraints vs soft penalties

The budget constraint says: spend at most £3,000. One way to enforce this is rigidly — if $x_1 + x_2 + x_3 > 3{,}000$, the solution is invalid. Full stop.

Another way is to put a price on violating the constraint. Exceed the budget by £1? Pay a penalty of $\mu$ pounds. The parameter $\mu$ is the "cost of capital" — how much each extra pound of budget is worth to you.

The Lagrangian formalises this:

$$ L(x, \mu) = -(0.05\,x_1 + 0.12\,x_2 + 0.03\,x_3) + \mu\,(x_1 + x_2 + x_3 - 3{,}000) $$

(We negate the objective because optimisation convention minimises.) The variable $\mu \geq 0$ is a Lagrange multiplier — a dual variable, one per constraint. It represents the price of the constraint.

What the Lagrangian does

Rearranging:

$$ L(x, \mu) = (\mu - 0.05)\,x_1 + (\mu - 0.12)\,x_2 + (\mu - 0.03)\,x_3 - 3{,}000\mu $$

Now look at each coefficient:

The multiplier $\mu$ acts as a hurdle rate. Any selection with edge below $\mu$ gets zero stake. The multiplier self-adjusts until the total stake exactly exhausts the budget. This is the same logic as a fund manager's return threshold — the cost of capital determines the cutoff.


Weak and Strong Duality: Bounds You Can Trust

Weak duality — a guaranteed lower bound

The dual function is what you get by minimising the Lagrangian over $x$ for fixed $\mu$:

$$ g(\mu) = \inf_x L(x, \mu) $$

A fundamental theorem — weak duality — says:

$$ g(\mu) \leq p^* \quad \text{for all } \mu \geq 0 $$

where $p^*$ is the true optimal value.

In English: any dual-feasible solution gives a lower bound on the best possible profit. You might not have found the optimal stakes yet, but the dual tells you a floor. If the floor is already £200 and your current best strategy gives £210, you know you're within £10 of optimal.

This is immensely practical. In live trading, you often don't have time to run the solver to full convergence. Weak duality lets you bound the gap. If the gap is small relative to execution uncertainty, stop and trade.

Strong duality — the gap closes to zero

For well-behaved problems (convex objective, convex constraints, and a technical condition called Slater's condition), the gap closes completely:

$$ g(\mu^*) = p^* $$

This is strong duality. The best lower bound equals the true optimum.

Slater's condition requires that a strictly feasible point exists — a point satisfying all inequality constraints with strict inequality. For our staking problem, that's any allocation where each stake is strictly positive but the total is strictly below £3,000. Easy to find. So strong duality holds.

What this means for you. When strong duality holds, solving the dual problem (finding the optimal multiplier $\mu^*$) gives you the same answer as solving the primal (finding optimal stakes). You can attack the problem from either direction. For large problems with many markets, the dual is often much smaller and faster to solve.


KKT Conditions: The Optimality Certificate

The four conditions

At the optimum of a convex problem with strong duality, the Karush–Kuhn–Tucker (KKT) conditions hold. These are both necessary and sufficient — a checklist that certifies optimality:

  1. Primal feasibility. The solution satisfies all constraints. Stakes are non-negative, within liquidity limits, and within budget.

  2. Dual feasibility. All multipliers for inequality constraints are non-negative: $\mu \geq 0$, $\lambda_i \geq 0$.

  3. Complementary slackness. For each inequality constraint: either the constraint is tight (binding, held with equality) or the multiplier is zero. Not both loose.

  4. Stationarity. The gradient of the Lagrangian with respect to $x$ is zero at the optimum.

Complementary slackness — the one that matters most

Complementary slackness is where the economic insight lives. For each constraint $i$:

$$ \lambda_i \cdot f_i(x^*) = 0 $$

Either the constraint binds, or you don't care about it. There is no middle ground.

Back to our Saturday card. Suppose the optimal solution is:

Selection Optimal stake Liquidity limit Constraint status
Frankel £2,000 £2,000 Binding
Constitution Hill £500 £500 Binding
Enable £500 £5,000 Slack (not binding)

The budget constraint: $2{,}000 + 500 + 500 = 3{,}000$. Binding.

Complementary slackness tells us:

The stationarity condition

For our linear problem, stationarity gives:

$$ -e_i + \mu + \lambda_i^{\text{upper}} - \lambda_i^{\text{lower}} = 0 $$

where $e_i$ is the edge on selection $i$. For Enable (not at its upper limit, not at zero):

$$ -0.03 + \mu = 0 \implies \mu = 0.03 $$

The optimal budget multiplier equals the edge of the marginal selection — the worst bet you're still willing to take. This is the hurdle rate. Every selection with edge above 0.03 gets funded (up to its liquidity limit). Everything below gets nothing.


Shadow Prices: What Each Constraint Is Worth

The dual variable as a price

Each Lagrange multiplier $\lambda_i^*$ is the shadow price of its constraint — the rate at which the optimal objective improves if you relax that constraint by one unit.

For our problem:

Constraint Status Shadow price Interpretation
Budget ≤ £3,000 Binding $\mu^* = 0.03$ An extra £1 of bankroll → £0.03 more expected profit
Frankel ≤ £2,000 Binding $\lambda_1^* = 0.05 - 0.03 = 0.02$ An extra £1 of Frankel liquidity → £0.02 more profit
Constitution Hill ≤ £500 Binding $\lambda_2^* = 0.12 - 0.03 = 0.09$ An extra £1 of Constitution Hill liquidity → £0.09 more profit
Enable ≤ £5,000 Slack $\lambda_3^* = 0$ More Enable liquidity is worthless

The shadow prices are ordered by how much you'd benefit from relaxing each constraint. Constitution Hill's liquidity constraint is the most expensive — an extra £1 of depth on that selection is worth 9p of expected profit. On a live exchange, this tells you exactly where to focus your execution effort.

Shadow prices in practice

Shadow prices answer real trading questions:

"Should I use a different exchange?" If Smarkets offers £200 more liquidity on Constitution Hill, that's worth $200 \times 0.09 = £18$ of expected profit. If Smarkets charges 2% commission and Betfair charges 5%, the commission saving on £200 at typical odds might be £3–4. Total benefit: roughly £21–22. Worth the effort.

"Should I increase my bankroll?" Each extra £1 of bankroll is worth £0.03. If you can borrow at 1% per race-day (i.e., the opportunity cost of capital is 1%), then borrowing is profitable up to the point where the marginal benefit (£0.03) equals the marginal cost (£0.01). You'd borrow until a new constraint binds.

"Which data feed should I improve?" If better data increases your estimated edge on Constitution Hill from 12% to 14%, the shadow price of its liquidity constraint rises from £0.09 to £0.11. The binding constraints shift. The entire staking plan reconfigures. Shadow prices propagate information about where your system is bottlenecked.


Optimality Certificates: Proof, Not Hope

What a certificate is

An optimality certificate is a pair $(x^*, \lambda^*)$ — a primal solution and its corresponding dual variables — that together satisfy the KKT conditions. If you can exhibit such a pair, the solution is provably optimal. No further searching is needed.

Every serious LP and convex optimisation solver (Gurobi, CPLEX, MOSEK, SciPy's linprog) returns both the primal solution and the dual variables. If you're not reading the dual solution, you're throwing away half the information.

A worked certificate

For our Saturday problem:

Primal solution: $x^* = (2000, 500, 500)$

Dual variables: $\mu^* = 0.03$, $\lambda_1^* = 0.02$, $\lambda_2^* = 0.09$, $\lambda_3^* = 0$

Check KKT:

  1. Primal feasibility: $2000 + 500 + 500 = 3000 \leq 3000$. ✓ Each $x_i$ within bounds. ✓
  2. Dual feasibility: $\mu^* = 0.03 \geq 0$, all $\lambda_i^* \geq 0$. ✓
  3. Complementary slackness:
  4. Budget: binding, $\mu^* > 0$. ✓
  5. Frankel upper: binding, $\lambda_1^* > 0$. ✓
  6. Constitution Hill upper: binding, $\lambda_2^* > 0$. ✓
  7. Enable upper: slack, $\lambda_3^* = 0$. ✓
  8. Stationarity:
  9. Frankel: $-0.05 + 0.03 + 0.02 = 0$. ✓
  10. Constitution Hill: $-0.12 + 0.03 + 0.09 = 0$. ✓
  11. Enable: $-0.03 + 0.03 + 0 = 0$. ✓

All four conditions hold. The solution is certified optimal. Not approximately. Not heuristically. Mathematically proven.

Why certificates matter in production

In a live trading system, you often can't wait for the solver to report "optimal." Time budgets force early termination. But even an interrupted solver can provide a primal-dual pair with a known duality gap:

$$ \text{gap} = f(x^{\text{best}}) - g(\lambda^{\text{best}}) $$

If the gap is £0.50 on a trade with £200 expected profit, you've captured 99.75% of theoretical value. Execute the trade. If the gap is £50, keep solving.

The duality gap is a live, quantitative measure of "how far from optimal am I?" — not a guess, but a proven bound. No other framework gives you this.


Connecting Back: From Polytopes to Optimisation

In the previous posts, we established that valid probabilities across linked markets form a polytope — and that checking whether exchange prices are inside or outside this polytope is a linear program. Now we see the other half:

Convex optimisation doesn't just find good trades. It proves they're good. And when they're not provably good yet, it tells you exactly how much room for improvement remains.


The Takeaway


Key Terms Introduced

Term Meaning
Constrained optimisation Maximising (or minimising) an objective subject to constraints
Lagrangian The objective plus penalty terms for each constraint, weighted by multipliers
Lagrange multiplier (dual variable) The "price" of a constraint — how much the optimum improves per unit of relaxation
Dual function The Lagrangian minimised over the primal variables — a lower bound on the optimum
Weak duality The dual value is always ≤ the primal optimum
Strong duality The dual value equals the primal optimum (under Slater's condition)
Slater's condition A strictly feasible point exists — guarantees strong duality for convex problems
KKT conditions Four conditions (primal/dual feasibility, complementary slackness, stationarity) that certify optimality
Complementary slackness Either a constraint binds or its multiplier is zero — never both loose
Shadow price The rate of improvement in the objective per unit relaxation of a constraint
Optimality certificate A primal-dual pair satisfying KKT — mathematical proof of optimality
Duality gap The difference between primal and dual objective values — a measure of sub-optimality

References

  1. Boyd, S. & Vandenberghe, L. (2004). Convex Optimization. Cambridge University Press. — Chapter 5 covers Lagrangian duality, KKT conditions, and sensitivity analysis. Free online at stanford.edu/~boyd/cvxbook. The definitive first read on this material.

  2. Rockafellar, R. T. (1970). Convex Analysis. Princeton University Press. — Section 28 on Fenchel duality, Section 30 on Lagrangian saddle points. The mathematical foundations beneath everything in this post.

  3. Bertsimas, D. & Tsitsiklis, J. N. (1997). Introduction to Linear Optimization. Athena Scientific. — Chapters 4–5 on LP duality and sensitivity analysis with economic interpretations. Excellent for building intuition about shadow prices.

  4. Abernethy, J., Chen, Y. & Vaughan, J. W. (2013). "Efficient Market Making via Convex Optimization, and a Connection to Online Learning." ACM Transactions on Economics and Computation, 1(2). — Applies Lagrangian duality and conjugates directly to automated market making in prediction and sports markets.

  5. Kelly, J. L. (1956). "A New Interpretation of Information Rate." Bell System Technical Journal, 35, 917–926. — The Kelly criterion as a concave maximisation problem. The dual variables of the Kelly problem give the shadow prices of bankroll and exposure constraints.

  6. Nesterov, Y. (2004). Introductory Lectures on Convex Optimization: A Basic Course. Kluwer. — The rigorous treatment of strong convexity, condition numbers, and convergence rates referenced in the discussion of duality gaps and solver performance.