Risk Modeling: The Power of Capital Advantage in Random-Walk Zero Sum Games

Pranav Ahluwalia
Towards Data Science
9 min readNov 16, 2019

--

In this article, I will demonstrate a crucial mathematical concept that is essential to constructing risk management strategies in games of chance. Using experimentation with random number generators in R, we will explore how having a fixed capital advantage over an opponent in a model investment game will yield significant probabilistic advantage towards winning in the long run.

We will compare the results of our simulations with those predicted by proven math theorems. Afterwards, we will explore the strategic implications of this concept to gambling, investing, and business.

Introduction To Risk of Ruin:

Risk of ruin is a concept commonly used in the world of Finance. It attempts to quantify the likelihood of a portfolio’s value going to zero. The principles of Risk of Ruin are as follows:

  • Over an infinite sample space, betting a fixed fraction of one’s total starting capital on any event will eventually result in going broke regardless of having a positive expected value on each bet.
  • Each succesive bet following the above critereon increases the risk of ruin and yields stochastic certainty of going broke.

There is a possibility that you are skeptical of the above statements. If you have a certain probability of winning a bet, and thus a positive expected value, how is it possible that making that bet iteratively will result in losing all your money? This is precisely the question we will explore in this series through simulation and data analysis of various toy games. When it comes to math, seeing is always believing.

Defining The Game:

  • Let there be two players: Player-1 and Player-2
  • Let ‘a’ be the amount of dollars Player1 starts out with
  • Let ‘b’ be a multiplier where Player-2 starts with (b * a) dollars

The two players will continuously flip a coin.

  • On heads, Player-1 will gain 2% of his starting investment [.02 * a] and on tails he will lose [.02 * a].
  • On tails Player-2 will gain what Player1 loses [.02 * a] and on heads he will lose what Player1 gains [.02 * a]
  • If one player goes broke, (loses all his money) then the other player wins the game.

We will have each player toss an infinite amount of coins until one of them goes broke. We will then run this game thousands of times to determine how often each player wins the game.

In the beginning, both players will start out with an equal amount of money. Slowly, we will increase Player-2’s bankroll by 1% of his starting investment and observe how Player-2’s probability of winning the game increases despite his lack of inherent advantage during each toss.

Modeling The Problem With Code:

All code can be found here.

If you are unfamiliar with programming feel free to skip this section and go to the results.

We will define three functions in R. The first function will simply run a single game. The function arguments are as follows: starting capital for Player-1, a multiplier for Player-2, and a sample size. It will output a 3 piece bit-vector that represents three scenarios: Player-1 wins, Player-2 wins, Tie (there shouldn’t be any ties as per Huygen’s Gambler’s Ruin Theorem). Note: R indexes arrays starting from 1 (for reasons that are completely beyond me). Do not think i’m crazy for counting arrays 1:n.

###Runs a coin flip simulation and outputs a winner or tie.
# a [double] amount of money in player 1 bankroll
# b [double] multiplier for amount of money in player 2 bankroll
#S [int] Sample size
#w [double] the fraction of a gained when a player wins
#l [double] the fraction of a lost when a player loses
#Outputs: a length 3 vector where a 1 represents a positive result #for a P1 win, P2 win, or Tie respectively
runSim <- function(a,b,s,w,l) {
player1 <- a
player2 <- a * b
output <- c(0,0,0)
for (i in 1:s) {
coin = sample(0:1,1)
if (coin == 0) {
player1 <- player1 - (l * a)
player2 <- player2 + (w * a)
} else {
player1 <- player1 + (w * a)
player2 <- player2 - (l * a)
}
if (player1 <= 0) {
output[2] <- 1
output
break
} else if (player2 <= 0) {
output[1] <- 1
output
break
}
}
if (player1 != 0 & player2 != 0) {
output[3] = 1
output
}
output
}

It is important to note that including ‘Break’ statements in the win conditions for each player is crucial as the game should end as soon as someone goes broke.

Our next function will run multiple games to determine the frequency at which each player wins for a given bankroll advantage for Player-2.

##Runs n amount of simulations to determine P1 win $, P2 win$, Tie%, P2% advantage
##n: amount of sims to run
#a: starting money
#s: sample size required for a single game
#swing: how much a player will win or lose based on outcome
#Player2 bankroll edge
runMetaSim <- function(n, a, s, swing, p2Multiplier) {
results <- c(0,0,0)
for (i in 1:n) {
r <- runSim(a,p2Multiplier,s,swing,swing)
if (r[1] == 1) {
results[1] <- results[1] + 1
} else if (r[2] == 1) {
results[2] <- results[2] + 1
} else {
results[3] <- results[3] + 1
}
}
output <- c(results[1]/sum(results),results[2]/sum(results),
results[3]/sum(results),-1 *(1 - p2Multiplier))
output
}

Our last function will output the frequency at which each player wins, record Player-2’s bankroll advantage, increase Player-2’s bankroll by a predetermined amount, and run the next simulation. The function will output a 4 column data frame logging the entire results of the aggregate simulation.

##Runs x amount of Meta-"Simulations"  gradually increasing the bankroll edge of one player by a given amount
#x[int]: amount of simulations to run
#start[double]: starting edge that player 2 has
#increment: a percentage increase for the succesive simulation
#Outputs: A two dimensional Data Frame: Cols[P1 win %, P2 win %, Tie #%, P2$ Advantage]
runAggregateSims <- function(x, start, increment, swing,rounds) {
cols <- c("P1 Win %","P2 Win %", "Tie %","P2 Bankroll Advantage")
out <- data.frame(matrix(ncol = 4, nrow = 0))

for (i in 1:x) {
start <- start + increment
row <- runMetaSim(rounds,1000,1000000,swing,start)

out <- rbind(out,row)
print(paste("Sim ", toString(i), "/", toString(x), " Complete"))
}
colnames(out) <- cols
out

}

The code below simply runs the simulations and graphs the results

sims <- runAggregateSims(300,1,.01,.02,1000)simsWithPercent <- sims
simsWithPercent$`P2 Bankroll Advantage` <- simsWithPercent$`P2 Bankroll Advantage` * 100
simsWithPercent$`P2 Win %` <- simsWithPercent$`P2 Win %` * 100
simsWithPercent$`P1 Win %` <- simsWithPercent$`P1 Win %` * 100
qplot(simsWithPercent$`P2 Bankroll Advantage`,simsWithPercent$`P2 Win %`,xlab = "Player 2 Bankroll Advantage %",ylab = "Player 2 Win Likelihood %",
main = "Probability Player 2 Wins")
qplot(simsWithPercent$`P2 Bankroll Advantage`,simsWithPercent$`P1 Win %`,xlab = "Player 2 Bankroll Advantage %",ylab = "Player 1 Win Likelihood %",
main = "Probability Player 1 Wins")

Results:

  • The sample-space for one game of coin tossing was limited to 1 million tosses
  • 1000 games were run at each level of bankroll advantage for Player-2 to determine his likelihood of winning
  • Win-rates were determined over a range of 1% bankroll advantage up to a 300% bankroll advantage for Player-2.

Figure 1 graphs the probability distribution for Player-2 winning at various levels of bankroll advantage as a percentage of Player-1’s starting capital. We can observe that the graph follows a logarithmic growth rate. Player-2’s advantage grows extremely quickly in the beginning and gradually tapers off as his bankroll increases by 1% at each iteration.

By the time Player-2 has 300% more capital than Player-1, he has more than an 80% chance of outlasting his opponent.

Figure 1
Figure 2

Figure 2 above simply shows the reverse distribution for Player-1. As Player-2’s bankroll advantage increases, Player-1’s likelihood of winning the coin toss game gradually diminishes and his risk of ruin thus increases.

Formalization:

Studying our own data is all fair and well but let’s see if this distribution follows the formula proposed by Christiaan Huygens ‘Gambler’s Ruin’ Theorem.

We will derive Huygen’s formula from his original coin toss problem to fit our own variant of the game. Recall the beginning of the article where we defined our variables.

Figure 3: Probability of Player 1 going broke
Figure 4: Probability of Player 2 going broke

The above formulas represent the risk of ruin for Players 1 and 2 respectively. using that information we can derive the probability of either player winning which is simply the likelihood of the other player going broke divided by the likelihood that either Player 1 or Player 2 goes broke.

Figure 5: Probability of Player 1 winning
Figure 6: Probability of Player 2 winning

We will now re-write our runAggregateSims() function to simply plot a data frame of the above functions and their values according to our original parameters.

##Runs the aggregate sims using the Huygen's TheoromrunAggregateSims2 <- function(x,increment,swing,a,b) {
cols <- c("P1 Win %","P2 Win %", "Tie %","P2 Bankroll Advantage")
out <- data.frame(matrix(ncol = 4, nrow = 0))

for (i in 1:x) {
b <- b + increment
p1 <- (a/.02*a)/(((b*a)/.02*a) + (a/(0.2*a)))
p2 <- ((b*a)/.02*a)/(((b*a)/.02*a) + (a/(0.2*a)))

p1winrate <- p1/(p1 + p2)
p2winrate <- p2/(p1 + p2)

row <- c(p1winrate,p2winrate,0,-1 * (1 - b))
out <- rbind(out,row)
print(paste("Sim ", toString(i), "/", toString(x), " Complete"))
}
colnames(out) <- cols
out
}
##Running Huygen's Formula
huygensFormula <- runAggregateSims2(300,1,.01,.02,1000,1)
huygensFormulaPercent <- huygensFormula * 100
###Stacking Huygen's Formula onto The Simulation Graph
###Sorry, R is the ugliest language in the world when it comes
#To using third party libraries
a <- ggplot() + geom_point(data = simsWithPercent,aes(x= simsWithPercent$`P2 Bankroll Advantage`, y = simsWithPercent$`P2 Win %`),color = "yellow") + xlab("P2 % Bankroll Advantage") + ylab("Player 2 % Win Likelihood") +
geom_line(data = huygensFormulaPercent, aes(x = huygensFormulaPercent$`P2 Bankroll Advantage`,y=huygensFormulaPercent$`P2 Win %`),color = "blue") + ggtitle("Player 2 Winning Distribution: Huygen's Formula vs Simulation")
a

Figure 7 below shows the curve yielded by the probability density function derived from Huygen’s formula.

Figure 7: Plot of Huygen’s Formula

Plotting the probability density function on the same chart as the results of our simulation, we can see that the data from the simulations is a near perfect fit for the formula derived from the theorem.

Figure 8: Huygen’s Formula over Simulation

Conclusions:

If two individuals play a fair chance betting game iteratively we can assume the following:

  • Somebody is guarantied to go broke as per Risk of Ruin Theory
  • The person with more money has a statistical advantage towards winning the overall game despite not having any particular advantage on individual rounds.
  • The statistical advantage of having more money than your opponent in a fair chance betting game can be reliably and accurately quantified.
  • If you want to win an iterative coin tossing game against your friend, simply bet more money.

Business Applications:

  • During times of loss, the only way to avoid ruin is to downsize your risks as a portion of your overall bankroll while increasing your risks in times of gain. This way, your gains will be large enough to offset variable costs and losses in the long run.
  • Having a large bankroll (free flowing liquid cash) set aside for the sole purpose of withering economic and financial variance provides a direct quantifiable competitive advantage and results in an increased chance of survival.
  • Simply having a lot of money makes it far easier to… acquire more money. In fact, you don’t even have to make particularly wise choices with how you risk that money. So long as you make sure that you’re risking it in a zero sum game against competitors with smaller bankrolls.
  • If you are at a bankroll disadvantage, you need a massive probabilistic advantage to compensate for not being able to whither variance. This concept will be explored in the coming articles.

To Be Continued:

In the next article, I will explore this same phenomena in unfair games. We will see if a probabilistic advantage can overcome a bankroll disadvantage or if simply having more money than your opponent is all that is required to come out on top in a zero sum game.

--

--