【发布时间】:2021-04-09 01:42:25
【问题描述】:
我正在尝试在 R 中进行鞅模拟,我下注一个金额,如果我赢了,我下注相同的金额,但如果我输了,我下注双倍的金额。我一直这样做,直到我没有钱下注或下注 100 次。然后我必须进行 100 次鞅模拟。当我应用我的代码时,我收到以下错误;
错误:“}”中的意外'}'(我认为所有括号都已考虑在内)
martingale_function(m, c, n, p) 中的错误: 找不到函数“martingale_function”
(我不知道为什么会出现这个错误)
m = amount to bet
c = initial bet
n= number of round
p = probability of winning
martingale_function <- function(m,c,n,p){
for(i in 1:n){
betting_money <- m
amount_bet <- c
end_Sim <- FALSE
while(!end_Sim){
if(runif(1) = p){
betting_money <- betting_money + amount_bet
amount_bet <- amount_bet
}
else {
betting_money <- betting_money - amount_bet
amount_bet <- amount_bet*2
}
if(betting_money <= 0|i=100){# if we have no more money left to bet or have done it 100 times we stop
end_Sim <- TRUE
}
} return(betting_money)
}
}
iteration_function <- function(m,c,n,p){
for(i in 1:100){
return(data.frame(Iteriation=i,AmountLeft = martingale_function(m,c,n,p)))
}
}
iteration_function(650,5,100,18/38)
【问题讨论】:
标签: r statistics