Question
Simulate gamblers ruin for a gambler with initial stake $2, playing a fair game. (a) Estimate the probability that the gambler is ruined before he
Simulate gambler’s ruin for a gambler with initial stake $2, playing a fair game.
(a) Estimate the probability that the gambler is ruined before he wins $5.
(b) Construct the transition matrix for the associated Markov chain. Estimate the desired probability in (a) by taking high matrix powers.
(c) Compare your results with the exact probability.
The R code for gambler's ruin is:
# gamblersruin.R
# Example 1.11
# gamble(k, n, p)
# k: Gambler's initial state
# n: Gambler plays until either $n or Ruin
# p: Probability of winning $1 at each play
# Function returns 1 if gambler is eventually ruined
# returns 0 if gambler eventually wins $n
gamble <- function(k,n,p) {
stake <- k
while (stake > 0 & stake < n) {
bet <- sample(c(-1,1),1,prob=c(1-p,p))
stake <- stake + bet
}
if (stake == 0) return(1) else return(0)
}
k <- 10
n <- 40
p <- 1/2
trials <- 1000
simlist <- replicate(trials, gamble(k, n, p))
mean(simlist) # Estimate of probability that gambler is ruined
# For p = 0.5, exact probability is (n-k)/n
Step by Step Solution
3.57 Rating (154 Votes )
There are 3 Steps involved in it
Step: 1
Required solution Ans a Using 1000 simulation k n p trials simlist meansimlist Estimate of probability that gambler is ruined 1 059 Ans b Markov chain ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started