**Introduction**

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*” [1].

**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[0], x[1], x[2] : Money to bet on mutually exclusive events

w[0], w[1], w[2] : Winning coefficients (e.g. if I bet on the first outcome and it happens, I win w[0]*x[0])

l[0], l[1], l[2] : Loss coefficients (e.g. if I bet on the first outcome and it does not happens, I lose l[0]*x[0])

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[0]*x[0] + l[1]*x[1] + l[2]*x[2] > x[0] + x[1] + x[2] + margin[0]

or equivalently, for all the events:

(w[0]-1)*x[0] + (l[1]-1)*x[1] + (l[2]-1)*x[2] > margin[0]

(l[0]-1)*x[0] + (w[1]-1)*x[1] + (l[2]-1)*x[2] > margin[1]

(l[0]-1)*x[0] + (l[1]-1)*x[1] + (w[2]-1)*x[2] > margin[2]

The same inequalities can be expressed in matrix form: A*x < b

whereby we define the vectors…

…A as

1 2 3 |
1-w[0] 1-l[1] 1-l[2] 1-l[0] 1-w[1] 1-l[2] 1-l[0] 1-l[1] 1-w[2] |

…x as

1 2 3 |
x[0] x[1] x[2] |

…b as

1 2 3 |
-margin[0] -margin[1] -margin[2] |

**Complete Python code example**

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
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) else: 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, b_ub=b, bounds=bounds, method='revised simplex', options={'maxiter':max_iteration}) if res.success: print("Money to bet:", res.x) print("Profit above minimum profit:",res.slack) else: print("No solution found") |

**Code explanation**

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.

1 2 3 4 5 6 7 8 |
A = [] for i in range(nr_events): A.append([]) for j in range(nr_events): if i == j: A[i].append(1-w[j]) else: A[i].append(1-l[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.

## Leave a Reply