You want to bet money on a given event and be sure to win, so you got the beautiful idea of betting on all possibilities at the same time? It doesn’t really work in the real life, but let’s look into this problem from the mathematical point of view and afterwards implement it in Python. I’m going to use scipy.optimize.linprog module in order to “minimize a linear objective function subject to linear equality and inequality constraints” .
Simple Maths Background…
A sample space describes all possible outcomes for a given experiment. “Oucomes” could be everything. We consider now a sample space made of three mutually exclusive outcomes for 2 given numbers N and M.
Event 1: N > M
Event 2: N < M
Event 3: N = M
Normally the higher is the risk, the more you can win (or lose). If someone (which I will call bookmaker) would offer you 100 times your betting money for the Event 3 (because it’s not lileky to happen) it’s expected from him to offer you much less for the remaining outcomes in such a way to make you lose money if you would bet on all events at the same time and to take advantage of the gamblers behaviour stastistic.
Now suppose you have many bookmakers offering you different rewards for your bet on the same sample space. What does it happen if you can choose to bet on all outcomes but from different rewards sources / bookmakers? I’m going to use the following notation:
x, x, x : Money to bet on mutually exclusive events
w, w, w : Winning coefficients (e.g. if I bet on the first outcome and it happens, I win w*x)
l, l, l : Loss coefficients (e.g. if I bet on the first outcome and it does not happens, I lose l*x)
Logically, since all outcomes are mutually exclusive, if you win by betting on Event 1 you lose by betting on Event 2 and 3. We want to bet on all outcomes. The resulting money must be greater than the money you bet and exceed it by a margin you wish. For example, if the Event 1 occurs it applies:
w*x + l*x + l*x > x + x + x + margin
or equivalently, for all the events:
(w-1)*x + (l-1)*x + (l-1)*x > margin
(l-1)*x + (w-1)*x + (l-1)*x > margin
(l-1)*x + (l-1)*x + (w-1)*x > margin
The same inequalities can be expressed in matrix form: A*x < b
whereby we define the vectors…
1-w 1-l 1-l
1-l 1-w 1-l
1-l 1-l 1-w
Complete Python code example
from scipy.optimize import linprog
w = [10,6,3] # winning coefficients
l = [-1,-1,-1] # loss coefficients multiplied by -1
b = [-20, -20, -20] # minimum profit for each bet multiplied by -1
max_iteration = 100000 # maximum number of iterations for the selected numerical resolution methods
bounds = [(0,10000),(0,10000),(0,10000)] # unknowns upper / lower bounds
if len(w) == len(l):
nr_events = len(w)
print("Winning and loss coefficients must have the same length!")
A = [[1-w[j] if j==i else 1-l[j] for j in range(nr_events)] for i in range(nr_events)] # system matrix
c = [sum([A[i][j] for i in range(nr_events)]) for j in range(nr_events)] # objective function array
res = linprog(c, A_ub=A,
print("Money to bet:", res.x)
print("Profit above minimum profit:",res.slack)
print("No solution found")
In the first part the user must define some sample vectors, namely w, l, b. Furthermore we defined upper or lower bounds for our unknowns. In our case, a lower bound must be zero (since we can’t bet negative money!) and an upper bound can be defined as we wish, e.g. 10000 Euros.
From the first input arrays w and l, it’s possible to generate the system matrix A. An alternative code for A would be the following.
A = 
for i in range(nr_events):
for j in range(nr_events):
if i == j:
We are interested in minimizing our left-hand side of the inequalities. According to the way linprog accept parameters, we only need to define the array (here called c) which multiplies the unknowns vector x inside the objective function. It corresponds to the elementwise sum of all rows of matrix A.