I know there's a lot of martingale simulation code out there but I haven't found one that stops at the first win (thus stopping once profit is made).
I'm trying to write a code that ultimately simulates the average amount of spins needed to profit 1 unit (in this case $50 = 1 unit) and how much money was needed to reach 1 unit. I'm also using European roulette odds for black/red. For instance:
Simulation 1: Bet 1($50): wins = 1 spin, $50 total bet
Simulation 2: Bet 1($50): Loses Bet 2($100): Loses Bet 3($200): Wins = 3 spins, $350 total bet
Average 2 spins and $200 bet
Obviously I'd simulate this much more then 2 times.
I have the code below and it appears to give me spins and profit correctly but I can not get the totalbet value to be accurate. Does anyone know how to fix this? I'm also open to critique or suggestions if you think I went about it wrong. THank you!!
martingale <- function() {
money <- 0
betsize <- 50
i <- 1
while(money != 50 & i <= 100) {
result <- sample(c(-betsize, betsize), 1, replace = T, prob = c(0.487,
0.513))
if(result > 0) {
money <- money + betsize
if (money == 50)
break
} else {
money <- money - betsize
betsize <- betsize * 2
}
i <- i + 1
}
return(list(spins = i, profit = money, total bet = betsize))
}
test <- replicate(100,martingale())
Aucun commentaire:
Enregistrer un commentaire