S0 <- 100 mu <- 0.01 sigma <- 0.08 T <- 5 S <- rep(0, T) S[1] <- S0 N <- 10000 Sf <- rep(0, N) plot(S, type="n", ylim=c(50,150)) for (n in 1:N) { x <- rnorm(T, mu, sigma) for (t in 2:T) { S[t] = S[1] * exp( sum(x[1:t]) ) } lines(S, col=n) Sf[n] <- S[T] } #hist(Sf) mean(Sf) sd(Sf) #S <- ts(S) #png(filename="Stock1.png", width=400, height=300) # plot(S, lwd=2, col=2, xlab="Time", ylab="Price") #dev.off()