Created
June 7, 2016 16:02
-
-
Save jilmun/b888f0b235cdb89bd69224595e8c7008 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Martingale Betting System | |
# initialize parameters --------------------------------------------------- | |
init_start <- 12800 | |
init_goal <- init_start + 1000 | |
init_bet <- 100 # initial bet value | |
prob_win <- 0.47 # probability of win | |
n <- 500000 # simulation count | |
# run simulation ---------------------------------------------------------- | |
cnt_win <- 0 | |
set.seed(123) | |
for (i in 1:n) { | |
curr.val <- init_start | |
curr.bet <- init_bet | |
flag_end <- FALSE | |
while (!flag_end) { | |
if (runif(1) < prob_win) { | |
curr.val <- curr.val + curr.bet | |
curr.bet <- init_bet # reset bet value if round won | |
} else { | |
curr.val <- curr.val - curr.bet | |
curr.bet <- curr.bet * 2 # double bet value if round lost | |
} | |
if (curr.val <= 0) | |
flag_end <- TRUE | |
if (curr.val >= init_goal) { | |
flag_end <- TRUE | |
cnt_win <- cnt_win + 1 | |
} | |
} | |
} | |
cat("Win probability:", cnt_win/n, "\nLose probability:", 1-cnt_win/n) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment