I want to generate 500 observations(returns) from a N(0,1) distribution. Set seed(100) to get the same sequence of random numbers. Then compute the volatility of these series using the EWMA method:
With λ=0.94, and where represents the mean of returns and the lagged return at period t-j. Plot the obtained volatility series. I know I should get a graph like the one in the following link
[1]:! [image for problem+ graph] https://i.stack.imgur.com/HXjWL.jpg
Here is my code so far - mainly just generating random numbers and creating new variables - I began to attempt using the "for" command but had no idea where to go with this:
set.seed(100)
data=rnorm(n=500,mean=0,sd=1)
lambda=0.94
rbar=mean(data)
dsquared=NULL
for (j in 0:100){dsquared[j]=lambda^j*(data[j]-rbar)^2}