The Real Kelly – a #python implementation for mutually exclusive outcomes

In my recent article The Real Kelly – an #excel implementation for mutually exclusive outcomes I described how to use excel to find optimal bet sizes for a set of mutually exclusive outcomes applying the generalised Kelly Criterion (a.k.a. The Real Kelly).

The basic concept of Real Kelly is discussed here The Real Kelly

In this article I will follow up on the excel implementation and show how to use python in order to derive the same results.

Excel is great if you have an idea and want to quickly test different scenarios. However as your dataset grows you will inevitable reach excel’s limits and/or have runtime issues.

Python is then your preferred choice!

The python implementation is available for download on my github repository real_kelly-mutually_exclusive_outcomes-

The code will work out of the box, but you will still need to know what you are doing!

That is,

(1) Outcomes must be mutually exclusive (= EXACTLY one outcome will happen). The optimization will work for markets like ‘Liverpool To Win The EPL’, but will not work for markets like ‘Liverpool Top-4’.

(2) Probabilities need to add up to 1 (or very close to it).

USAGE

(1) Selections need to be passed in as a list of dictionaries called ‘selections’. The template near the bottom is there to be modified.

Screenshot 2020-03-17 at 22.40.29

(2) Any existing bets you might have need to be passed in as a list of dictionaries called ‘existing_bets’. The template near the bottom is there to be modified.

Screenshot 2020-03-17 at 22.42.15

(3) Also pass in the bankroll as a parameter of the function call at the very bottom.

Screenshot 2020-03-17 at 22.42.21

Thanx to @SmoLurks the python code now runs faster by a factor of 35!!!

 

The Real Kelly – an #excel implementation for mutually exclusive outcomes

Twitter user @optibrebs recently made me aware of the generalised Kelly Criterion (a.k.a. The Real Kelly) discussed in this @Pinnacle article The Real Kelly

To be honest I have been successfully using the simple/naïve Kelly Criterion for years and haven’t bothered looking anywhere else.

This is how the simplified Kelly looks

s = b * (o / f – 1) / (o – 1)

where

s…Kelly Stake
b…Bankroll
o…Odds offered
f…Odds fair

The simplified Kelly Criterion has some potential flaws and can give some head-scratching results which are explained in the article above.

I therefore recommend using the more sophisticated generalised Kelly Criterion wherever possible as it is superior to the simplified Kelly Criterion. The Real KC is very useful for outright betting as shown below.

In this article I will explain how to use the real KC in order to find optimal bet sizes for a set of futures bets on several different teams to win the same division or championship. However please note that the algorithm can be applied to ANY market with mutually exclusive outcomes (e.g. it could also be applied to a 3-way betting market as explained in example #1 in the @Pinnacle article).

Let’s dive in.

The excel template can be downloaded here real_kelly-mutually_exclusive_outcomes-

Please note

(1) Outcomes must be mutually exclusive (= EXACTLY one outcome will happen). The algorithm will work for markets like ‘Liverpool To Win The EPL’, but will not work for markets like ‘Liverpool Top-4’.

(2) Probabilities need to add up to 1 (or very close to it).

(3) You can adapt the number of outcomes to your needs, but be aware to also update the variable cells within the solver.

(4) You can use excel’s built-in solver using method ‘GRG Nonlinear’, but be advised that it might not give you the best set of results. I recommend using the GlobalMinimize macro instead which can be downloaded here GlobalMinimize Excel Macro.
The algorithm will very likely find a global maximum (instead of just a local maximum) for the objective and will yield the optimal solution.

The drawback is that GlobalMinimize is limited to 30 variable cells. Excel’s solver has a limit of 250 variable cells.

INSTRUCTIONS

  • Make sure to open both GlobalMinimize and the Real Kelly worksheet.
  • Fill out the fields in the yellow columns (‘BET’, ‘BOOK_ODDS’, ‘MY_ODDS’) as shown below. ‘MY_ODDS’ is what you consider to be the fair odds.

Screenshot 2020-03-21 at 15.27.27

  • Set all stakes to 0.
  • Enter your bankroll in the yellow cell ‘START BANKROLL’
  • If you have any existing bets on this tournament enter those in columns (O, P, Q). Note that any strings in column O must exactly match those in column A.
  • Press CTRL+M to open GlobalMinimize settings.
  • Adjust the stake range/constraints according to your needs.
  • Select Differential-Evolution (DE) followed by Nelder-Mean (NM) and hit ‘Minimize’.

Differential-Evolution (DE) followed by Nelder-Mean (NM) should be your default option, as it increases the likehood of finding the global maximum, and NM ‘polishes off’ the optimum with a high degree of accuracy.

Depending on the field size the algorithm can now take several minutes until excel populates the optimal set in the stakes column.

What I like about this application is that you could potentially use it from week to week as the season progresses. The algorithm will find optimal bets and/or (partial) hedges whenever the sheet is updated with new prices.

Have fun!