Week 10 Gamblers Ruin






Smith is in jail and has 1 dollar; he can get out on bail if he has 8 dollars. A guard agrees to make a series of bets with him. If Smith bets A dollars, he wins A dollars with probability .4 and loses A dollars with probability .6. Find the probability that he wins 8 dollars before losing all of his money if (a) he bets 1 dollar each time (timid strategy). (b) he bets, each time, as much as possible but not more than necessary to bring his fortune up to 8 dollars (bold strategy). (c) Which strategy gives Smith the better chance of getting out of jail?


These are 2 of many variations of the Gamblers Ruin


We will explore a Markov Matrix, a geometric series, a plain union of probability trials, and lastly a simulation.


First set up the paratmeters


p<-.4
q<-1-p

N<-8
dollars<-1
bet<-1




Below is a row stochastic matrix, i.e. the values in each row add up to 1, indicating the probabilties that the transition will end in that position.


\[\begin{vmatrix} 1& 0& 0& 0& 0& 0& 0& 0& 0 \\ .6& 0& .4& 0& 0& 0& 0& 0& 0 \\ 0& .6& 0& .4& 0& 0& 0& 0& 0 \\ 0& 0& .6& 0& .4& 0& 0& 0& 0 \\ 0& 0& 0& .6& 0& .4& 0& 0& 0 \\ 0& 0& 0& 0& .6& 0& .4& 0& 0 \\ 0& 0& 0& 0& 0& .6& 0& .4& 0 \\ 0& 0& 0& 0& 0& 0& .6& 0& .4 \\ 0& 0& 0& 0& 0& 0& 0& 0& 1 \end{vmatrix}\]


Each row represents a starting position, i.e. we are starting with $1 so our row is row 2 and \(P_{2,1}\) represents the bankrupt state…


\[ \begin{vmatrix} .6& 0& .4& 0& 0& 0& 0& 0& 0 \end{vmatrix}\]


Now each time we dot prodcut the vector against the matrix represents a step. Once we wind up at 0 or 8, that probability never diminishes, i.e. \(P_{2,1} = P_{2,1} * 1\) + next step probability to go broke.


mat <- matrix(c(1,0,0,0,0,0,0,0,0,q,0,p,0,0,0,0,0,0,0,q,0,p,0,0,0,0,0,0,0,q,0,p,0,0,0,0,0,0,0,q,0,p,0,0,0,0,0,0,0,q,0,p,0,0,0,0,0,0,0,q,0,p,0,0,0,0,0,0,0,q,0,p,0,0,0,0,0,0,0,0,1), nrow=9, byrow=TRUE)

v<-c(q,0,p,0,0,0,0,0,0)

for (i in 1:300) {
  v<-v %*% mat
  
}

round(v,4)
##        [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]   [,9]
## [1,] 0.9797    0    0    0    0    0    0    0 0.0203


The first column is the probability of going broke, and the last column is the probability of success.


This geometric series is an approximation, but it is a more compact way to do this.


\[\frac{1 - (\frac{q}{p})^{s}} { 1 - (\frac{q}{p})^{N+s} }\]


where s = the start position. In our case, s = 1


p_timid<-function(p,N) {
  
num<-1-((1-p)/p)^1
den<-1-((1-p)/p)^(N+1)
return(num/den)
}


p_timid(p,N)
## [1] 0.0133535


The series is a little less intuitive, but it is a close approximation to the markov matrix for all probabilities I tested.

click here for a deeper dive into it.


The Bold strategy is just the probability of winning 3 times in a row.


.4^3
## [1] 0.064


The Bold strategy is has nearly 3 times better chance of being successful. See below for a simulation.


timid<-function() {
  
while (dollars > 0 & dollars < 8) {
  if ( rbinom(1, 1,p) == 1) {
    dollars=dollars+1
  } else
  {
    dollars=dollars-1
  }
}
  return (dollars>0)  
}






daring<-function() {
  
  while (dollars > 0 & dollars < 8) {
    if ( rbinom(1, 1,p) == 1) {
      dollars=dollars+bet
    } else
    {
      dollars=dollars-bet
    }
    if ((8-dollars) > dollars) {
      bet<-dollars
    } else {
      bet<-8-dollars
    }
    
  }
  return (dollars>0)  
}





t_won<-0
t_lost<-0
d_won<-0
d_lost<-0


for (i in 1:1000) {
if (timid()) {
  t_won=t_won+1
} else 
{ 
  t_lost = t_lost+1 
}
  
  if (daring()) {
    d_won=d_won+1
  } else 
  { 
    d_lost = d_lost+1 
  } 
}


print(paste("Timid   : Won :", t_won, "      Went Broke : ", t_lost)) 
## [1] "Timid   : Won : 16       Went Broke :  984"
print(paste("Daring  : Won :", d_won, "      Went Broke : ", d_lost)) 
## [1] "Daring  : Won : 73       Went Broke :  927"