我使用R模拟波动率为0.25的股票的价格路径,然后计算这些模拟路径的波动率。我发现当模拟步骤的数量很小时,例如小于75步,模拟价格路径的波动率实际上小于0.25。当我增加步数时,它逐渐收敛到0.25。任何人都可以解释这一点,无论步骤数多少,我如何生成具有固定波动率的价格路径。谢谢。
#----------------------- 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)
答案 0 :(得分:0)
您的路径模拟是正确的,但您的波动率计算是错误的。我想你想用你的for循环替换vol:
vol = mean(apply(path, 2, function(x){365*mean( (diff(log(x),n=1)-0.5*(volatility*dt)^2 )^2 ) } ) )
给出: