Part 2

If I want to crack the Martingale system and start making millions, first I have to understand the odds properly. My ideal scenario would be running over 100,000 different trials, and using them to find the ideal strategy.

However, before I can get fancy, I need to model a single instance of roulette. This is pretty easy. I know the odds of winning and defining the bet size means I know how much I’ve won.

Lets have a look at some basic Python to do it.

"""
Very simple roulette simulator
"""
import random as rd
win_odds = 0.483
def gamble(win_odds):
""" takes a probability of winning and determines if we've won or not"""
    return "win" if rd.random() <= win_odds else "lose"
if __name__ == "__main__":
    gamble(win_odds)

To be completely honest, the above code works but isn’t really necessary. I just included it above to demonstrate the premise. If you’re not comfortable with Python, the main bits are:

  • import random as rd - I’m loading in some ready made code here to create a random number and make my life easier
  • def gamble(win_odds) - I define a function called gamble, which requires an argument called win_odds (the probability of winning) to work. You can see I’ve already defined what win_odds is on an earlier line.
  • return “win” if … - this tells the gamble function what to output. rd.random() generates a random number between 0 and 1, and if that number is less than or equal to the win odds, then we’ve won! Otherwise we lose.
  • if name == … - this is a funny piece of code which tells Python to run the gamble function when I use the code. If you’re familiar with C its the equivalent of running main.

What I actually want to do is model somebody playing roulette. This is more complicated than modelling somebody winning one spin.

My roulette tester will follow some simple rules:

  • they start the game with a starting balance
  • they are told a minimum bet to start with
  • they follow the Martingale system
  • if their balance hits 0 they are out.

The code to do this looks like:

"""
Modelling somebody actually playing roulette
"""
import random as rd
win_odds = 0.483
def roulette_simulator(starting_amount, minimum_bet):
    running_balance = starting_amount
    running_bet = minimum_bet
    while running_balance >= 0:
        result = 1 if rd.random() <= win_odds else 0
        if result == 1:
            running_balance += (2* running_bet)
            running_bet = min_bet
        else:
            new_bet *= 2
    return running_balance
 

The code is still pretty straightforward. However is isn’t useful. One of the constraints we defined on our test player is they keep playing till they hit zero. This is reflected in the while loop in the code. But there’s no point playing till you hit rock bottom - the point is to play and make a return.

As is, the code needs some changing. We need another way for our player to quit playing. Let’s keep following the Martingale system, but we’ll change some constraints. I can think of two ways to have an early exit: by having a limit on the number of spins which some can do, or by defining an exit multiple. If you can think of another approach feel free to tell me.

I’ve decided to follow the latter - by defining an exit multiple. The exit multiple tells our test player when to stop playing. An exit multiple of 1.1x means they stop playing once they’ve made 10% of their amount ie their running balance = 1.1 x starting balance. This is easy enough to do, and we can quickly change the code:

"""
Modelling the complete Martingale system
"""
import random as rd
win_odds = 0.483
 
def roulette_simulator(starting_amount, minimum_bet, exit_mult):
    running_balance = starting_amount
    running_bet = minimum_bet
    exit_balance = exit_mult * starting_amount
    outcome = 0
    while running_balance >= 0:
        result = 1 if rd.random() <= win_odds else 0
        if result == 1:
            running_balance += (2* running_bet)
            running_bet = min_bet
            if running_balance >= exit_balance:
                outcome = 1
        else:
            new_bet *= 2
    return outcome
 

The above code runs the Martingale system in a realistic(ish) way. Our test player doubles their bet upon losing, and once they win they reset their minimum bet. They don’t have infinite funds either - if they run out of money they’re out. They also leave the table if they make enough money, and this is user defined.

The function roulette_simulator() returns either 1 or 0. 1 means we have made enough money, and 0 means we’ve run out. I chose this deliberately, as it makes it easier to understand probabilities.

I start with £100, bet £0.50 as bet minimum, and define my exit value as £110 (1.1x). I can see if this passes or fails by simply running roulette_simulator(starting_amount=100, minimum_bet=0.50, exit_mult = 1.1). This gives me a 1 or a 0 ie a pass or a fail. To go from this to a probability, I just need to repeat my code several times and see what happens.

I can do this with Python pretty easily:

def prob_calculator(number_of_trials):
    exit_values = [ roulette_simulator(starting_amount, minimum_bet, exit_mult) for i in range(number_of_trials) ]
    return sum(exit_values)/number_of_trials
 

In the above code block, we run the simulator N times. This gives us a list of outcomes, for example [1, 0, 0, 0, 1, 1, 0, … , 0] (remember this reads as [success, fail, fail, fail … ]. The list has N elements (one for each trial). The probability of success is therefore the number of successes which we have, divided by the total number of trials.

To sum this post up - if I run prob_calculator with 1000 trials, £100 starting, £0.50 minimum and an exit amount of £110, I get a probability of 0.892 ie 89%. So there’s a 90% chance of a 10% return - not bad?

We’re getting somewhere it seems. We understand the returns we could make, and we know the risk associated with it. I have a few questions now:

  • How does this compare to actual investments? Which metrics and KPIs should I use to make it a valid comparison?
  • What is the ideal relationship between starting, exit_mult and minimum bet?
  • Can we understand the stats better?
  • Is there a better approach to the Martingale?

Hopefully I’ll address all of those questions in the next few posts - stay tuned for more.