I am trying to prove via some Monte Carlo simulation that the variance of a random walk equals $t*σ^2$ in R. I am running the following code, 180 times, to find the variance of 180 different random walks with the same error standard deviation.
Although I can see in graphs that the variance is increasing, the variance itself is very far away than the expected. The theory would say that expected variance for n = 1000, would be $t*σ^2 = 1000 * 0.5^2 = 250$ but in reality I get a much lower variance. Running 180 simulations, I get a mean of ~40 for the variance, instead of 250. Even the max variance in 180 iterations, rarely goes above 200.
Can somebody let me know what I am missing here? If I run an AR model (e.g. adding $0.8*y[t-1]$) the variance is approaching the expected from the formula. But not for the random walk.
n <- 1000
cumulative_var <- 0
for (h in 1:180) {
et <- rnorm(n, mean = 0 , sd = 0.5)
yt <- et[1]
vars <- 0
for (i in 2:n){
yt[i] <- yt[i-1] + et[i]
vars[i] <- var(yt)
}
cumulative_var[h] <- var(yt)
}
hist(cumulative_var)
mean(cumulative_var)