I use R to simulate the price path of a stock with volatility of 0.25, then I calculate the volatility of those simulated path. I found that when the number of simulation steps is small, e.g., less than 75 steps, the volatility of simulated price path is actually less than 0.25. When I increase the number of steps, then it gradually converges to 0.25. Can anyone explain this, and how can I generate price paths with a fixed volatility, no matter the number of steps. Thanks.
#----------------------- code -----------------------
#number of simulation runs
nSims = 1000
S = 100
r = 0
q = 0
volatility = 0.25
#drift term
mu = r - q
#every trading day increment
dt = 1 / 365
vol_vec = vector()
for (tDays in 1:365) {
# standard normal distribution random number
z = rnorm(tDays*nSims, mean=0, sd=1)
# generate log-normal return matrix
return_matrix = matrix(exp((mu - 0.5 * volatility ^ 2) * dt + volatility * sqrt(dt) * z), ncol=nSims)
# return value: price path matrix
path = rbind(matrix(rep(S,nSims),ncol=nSims), S*apply(return_matrix,2,cumprod))
# calculate the volatility of path
vol = mean(apply(path, 2, function(x){sqrt(365*mean(diff(log(x),n=1)^2))}))
vol_vec = c(vol_vec, vol)
}
plot(vol_vec, type="l", col="blue")
abline(h=volatility, col="black", pch=22, lty=2)