0

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}
  • 1
    When you tried to program this, where did you get stuck? Please show your code. – Fortranner Apr 08 '15 at 19:33
  • @fortranner - I added my code to the post - as you can see i'm struggling big time. all I really know how to do is generate the random numbers and create my new variables. Sorry about this! if i'm beyond help don't worry about it – Stevie Kvothe Apr 08 '15 at 21:08

0 Answers0