In one sentence
Linear programming finds the stakes that maximise (or minimise) a target, such as guaranteed profit, while respecting a set of limits written as simple sums, and integer programming adds the rule that some answers must be whole numbers.
How it works
Many staking problems are really puzzles with rules: stay within a £200 budget, allow for the £30 you already have on at a better price, and make sure every outcome pays at least a set amount. Doing this by hand gets messy quickly.
A linear programme writes the target and the rules as straight-line formulas in the stakes. A solver then searches the space of allowed stakes and returns the best one, with a guarantee that nothing better exists. Integer programming does the same when stakes must be whole pounds or when choices are yes or no, such as whether to include a bet at all.
The method is only as clever as the rules you write. It will happily pile everything into one bet if nothing stops it.
The maths
- x with subscript i is the stake on price i.
- o with subscript i is the decimal odds of that price.
- The first sum adds up the returns from all stakes on outcome j.
- t is the worst-case profit across all outcomes, which we want as large as possible.
- B is the total budget and L with subscript i is the most that can go on at price i, for example a stake you placed earlier that is now fixed.
In plain English: choose stakes so that the worst result is as good as it can be, without breaking the budget or any limit on a price.
Worked betting example
A Match Odds trade on Betfair. Earlier you backed the home side for £30 at 2.30. The prices now are home 2.20, draw 3.60 and away 3.90, and you want to spend £200 in total, including that £30, so that every result pays. These prices are illustrative, and the 2% commission is left out to keep the numbers clean; in practice you would use commission-adjusted odds.
With the home side at 2.30, the three prices imply 96.9% in total, below 100%, which is what makes a guaranteed profit possible.
- If all the home money could have gone on at 2.30, the classic dutching answer would stake £89.74 on the home side and lock in £6.40 profit.
- With £30 fixed at 2.30 and the rest of the home money at 2.20, the linear programme returns: £30 at 2.30, £61.21 at 2.20, £56.57 on the draw and £52.22 on the away side.
- Guaranteed profit: £3.66 whatever happens. Home pays 2.30 × 30 + 2.20 × 61.21 = £203.66, the draw pays 3.60 × 56.57 = £203.66, the away pays 3.90 × 52.22 = £203.66.
- Requiring whole-pound stakes (integer programming): £30, £61, £57 and £52. The worst case is now £2.80 profit (away), with £3.20 on a home win and £5.20 on a draw.
Where it's good
- Arbitrage and dutching across several prices, including stakes you placed earlier at different prices.
- Hedging a set of open positions to guarantee a minimum outcome.
- Picking which bets to include from a shortlist under budget and exposure limits (a yes or no choice per bet).
- Correct Score books where every scoreline you care about must be covered.
Limitations and pitfalls
- True arbitrages are rare, disappear in seconds and attract account restrictions at bookmakers; the maths is the easy part.
- The objective must be linear, so it cannot directly maximise growth or penalise variance. Those need Kelly or quadratic optimisers.
- Maximising expected profit with a linear objective tends to put all the money into the single best-looking bet, which is usually the one with the biggest model error.
- Prices move between solving and placing, so a solution can be stale by the time you act.
- Commission, stake minimums and rounding change the answer; build them into the constraints.
- Integer problems can become slow when there are hundreds of yes or no choices, though modern solvers handle typical betting sizes well.
How to build it
- scipy.optimize.linprog for linear problems and scipy.optimize.milp for integer ones; PuLP or OR-Tools for larger models.
- Data: live prices, your open positions and your commission rate (2% on net winnings).
- Write constraints for budget, stakes already placed, minimum stake and exposure per outcome.
- Practical tip: always check the solver's answer by computing the payout for every outcome, as in step 3.
Related methods
- Arbitrage – the most common use of this tool in betting.
- Dutching – the unconstrained version of the example.
- Back-lay hedging – locking in outcomes across back and lay prices.
- Mean-variance optimisation – optimisation with a risk penalty.
- Simultaneous Kelly – optimisation for growth rather than guaranteed profit.