21.4.22/R/トレーニングと実践


Today


講義


R番組第2期第9強

結果



学習内容


9.コイン投げ株シミュレーション


coin toss stock price simulation
n <- 10000
stock_price <- vector(length = n)
current_stock <- 34

for(i in 1:n){
  if(rbinom(1, 1, 1/2) == 1){
    current_stock <- current_stock + 1
  }else{
  current_stock <- current_stock - 1
  }
  stock_price[i] <- current_stock
}

current_stock
stock_price

plot(stock_price, type = 'l', col = 'red')

Tomorrow

  • R 10講習
  • Summary

  • keep going!