0

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. enter image description here

#----------------------- 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)
2607
  • 4,037
  • 13
  • 49
  • 64
  • This looks like initialization bias. Are your data serially correlated? – pjs Sep 20 '14 at 18:37
  • @pjs No, the data is randomly generated using rnorm(). Thanks. – 2607 Sep 21 '14 at 11:43
  • Your `z`s are iid, but they're not the output data. Not being an R programmer I can't make out what you're doing to the `z`s to get to `vol_vec`. If the `vol_vec` values are serially correlated they'll be affected by your starting conditions -- it looks like you're starting at zero and drifting your way up. – pjs Sep 21 '14 at 16:50

1 Answers1

0

Your path simulations are correct, but your volatility calculations are wrong. I think you want to replace vol in your for-loop with:

 vol = mean(apply(path, 2, function(x){365*mean( (diff(log(x),n=1)-0.5*(volatility*dt)^2 )^2 ) } ) ) 

which gives: enter image description here

J.R.
  • 3,838
  • 1
  • 21
  • 25