r - Seed function in Brownian motion -
when simulate brownian motion, need 10 20 seeds in r. code following, think fixed seed , how create under different seeds, thank you
u <- 0.05 sigma <- 0.2 t <- 1 steps <- 252 s0 <- 100 dt <- u / steps set.seed(10:20) epsilon_t_vec <- rnorm(steps) epsilon_t_vec <- append(0, epsilon_t_vec) dwt_vec <- epsilon_t_vec * sqrt(dt) st_vec <- c() st_vec[1] <- s0 for(i in 1:steps) { dwt <- dwt_vec[i+1] st_vec[i+1] <- st_vec[i] + u * st_vec[i] * dt + sigma * st_vec[i] * dwt } st_vec
you can this. seed being changed in second loop every time , output appended list length of seeds.
u <- 0.05 sigma <- 0.2 t <- 1 steps <- 252 s0 <- 100 dt <- u / steps seeds <- 10:20 st_vec <- list() for(s in 1:length(seeds)) { set.seed(seeds[s]) epsilon_t_vec <- rnorm(steps) epsilon_t_vec <- append(0, epsilon_t_vec) dwt_vec <- epsilon_t_vec * sqrt(dt) st_vec[[s]] <- c(s0) for(i in 1:steps) { dwt <- dwt_vec[i+1] st_vec[[s]][i+1] <- st_vec[[s]][i] + u * st_vec[[s]][i] * dt + sigma * st_vec[[s]][i] * dwt } }
Comments
Post a Comment