Martingale in Monte Carlo with R
Spinning the wheel: a simulation of the roulette game in R
Introduction
Martingale is a gambling betting strategy based on the fact that after each loss, the player raises the bets until he wins. So that, if he wins, it will pay off all past losses in this series, with a small income. The player’s profit when winning will be equal to the initial bet. In case of a win, the player must return to the initial bet. The most popular approach is to double the bet after each loss. The generalized strategy might be used in gambling, perhaps stock trading, some business applications.
It states several assumptions: the observations are independent and identically distributed, the gambler has infinite wealth, there is no limit on the betting size, the probability of outcomes is 50%.
An example with a fair coin: 1/2 head, 1/2 tail. The bet is 1 point. A series of n trials. The budget is 2^(n-1). There are 2^n possible combinations. The probability of bankruptcy: 1/(2^n). Any other combination: 1–1/(2^n). Therefore the ratio of bankruptcy to winning a bet of 1 point: 1/(2^n) / (1–1/(2^n)) = 1/((2^n)-1). That is, for winning 1 point the player risks (2^n)-1 points. Playing many rounds of this game, the player would on average lose every (2^n)-1 round, making the expected value of the game zero.
The problem with Martingale is even knowing the probability on paper, behaviorally/mentally it is difficult to accept the fact that the long series are typical, assuming the observations are independent. In this article, there would be two simulations of this strategy: unlimited and practical.
Simulation One (unlimited)
For the first simulation, the function would hold the assumptions of i.i.d, infinite wealth, unlimited betting size; however, the probability will be set for European roulette that is containing one zero.
The function sets several containers for saving the results such as bet, outcome, bank, cumulative bank. The simulation would make 10000 repetition of 100 bets with probability of winning 18/37. If the bet is lost, then the following bet is doubled. The initial value of the bet is 1 point.
martingale <- function(x){
results <- x
bet <- c(1, rep(NA, length(results)))
bank <- rep(0, length(results))
outcome <- vector()
for (i in 1:length(results)){
if (results[i] == -1){
bet[i+1] <- 2*bet[i]
bank[i] <- bank[i] - bet[i]
} else {
bet[i+1] <- bet[1]
bank[i] <- bank[i] + bet[i]
}
}
outcome <- cbind(bet = bet[-length(bet)], results, bank, cms = cumsum(bank))
return(outcome)
}sim <- replicate(10000, martingale(sample(c(-1, 1), 100, T, c(19/37, 18/37))))
For the first 10 games, it is obvious from Figure 1 that the drops in value are common. There are several drops below 200 points, and one drop below 1000 points for the game at bet #79.
Figure 2 demonstrates the results from the first 100 games. The drops are more frequent and severe. That is the probability of observing a series of losses is increasing. Here some drops are already below -1000. That is it would require more than 1000 to return the initial bet, and earn 1 point.
Further simulation of 1000 games shows how often the series of losses might be observed (Figure 3). Having infinite banks and no limits on betting, the general trend is positive. However, this plot already cannot capture the maximum loss.
Finally, the simulation of 10000 games covers almost all the area in red (Figure 4). At this point, it is more useful to look at the aggregated summaries of the simulation.
From Table 1 we can see, that from this simulation more than 1000 bets required the bank greater than 1000, that is risking 1000 to earn 1 point. More than 100 bets required the bank greater than 8000, which would already break the max bet limit for most of the casinos. Once we observed a series of 18 repetitive outcomes. Perhaps, the frequent casino visitors or workers are not impressed by the length of this series.
Simulation Two (practical)
For this simulation, the function would be simplified. The assumption of i.i.d only would remain. The wealth/bank would be limited to 100 points, and the goal will be to double the bankroll, i.e. to reach 200 points. The probability will be set for the European roulette that is containing one zero.
The function sets several containers for saving the results such as the budget, bet, goal, iteration.The initial bankroll is 100 points. The probability of winning 18/37. If the bet is lost, then the next is doubled. The initial value of the bet is 1 point. The function skips recording intermediate results, returning summary of the game only.
mart5 <- function(x, c, g){
budget <- x
bet <- c
goal <- g
i <- 1
while((budget > bet) & (budget < goal)){
outcome <- sample(c(-1, 1), 1, T, c(19/37, 18/37))
if (outcome == 1){
budget <- budget + bet
bet <- c
}else{
budget <- budget - bet
bet <- bet*2
}
i <- i+1
}
return(c(budget = budget, bet = bet, i = i))
}sim <- replicate(100, mart5(100, 1, 200))
The simulation could be described as a player with an initial 100 points bankroll. If he doubles his initial bankroll, i.e. reaching 200 points, he stops playing. If there are not enough points for making the next bet, he stops playing.
Inspecting the output of the function for the first 10 games: 3 times the player was able to double the bankroll. The length of the game to reach 200 points was around 200 spins. Considering that each spin may take up to 2–5 minutes, it would be a long night to double the stake.
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
budget 200 42 200 16 200 6 5 62 48 44
bet 1 128 1 128 1 128 128 64 64 64
i 182 145 180 89 221 72 73 61 25 22
When the player lost, he was not completely broke, and accumulated points from the bankrolls could be used for further games. However, it would not help, as Table 2 shows the average values of the results of 10000 simulations. The average budget is below 100, indicating that on average the player lost 10.55 points from each initial 100-point bankroll. The average bet was 64, meaning that bankruptcy was a popular option for the player. On average the player spins the wheel 109 times every simulation.
Conclusion
The martingale strategy may not be very effective in modern casinos. Limits on the amount of the minimum and maximum bets, ensure that the player can play using this system not endlessly, but only a certain number of times. As a result, having bet almost the maximum of all his money and losing, the player no longer has the opportunity to continue and loses the chance to return the money. Rarely, any player has an infinite amount of money. The series of consecutive losses are more frequent than assumed by most players. The probability of the outcomes is not 50/50 but in favor of the house. Comparing the total cost of betting and the number of winnings, it turns out that the return on capital is not so significant. Both simulations clearly show the disadvantages of applying this betting strategy.
You can find the full code here on GitHub.
Thank you for reading!
Connect on LinkedIn