Hello,

1) In the provided example, you have 2 stock returns and

> EWMA = matrix(nrow=T, ncol=3)

See the number of columns (2+1)
Please modify the number of columns according to the number of stock
returns.

2) As you have 5 stock returns, the following cannot work

> EWMA[1,] = c(S)[c(1,4,2)]

You have to modify this part too.


3) Do the same modification within the loop.

Regards,
Pascal



2013/7/18 G Girija <girija...@gmail.com>

> hi,
>
> Could anyone help me in solving the following error:
> I have 5 stocks returns data (returns)
>
> EWMA = matrix(nrow=T,ncol=5)                  # create a matrix to hold the
> covariance matrix for each t
>
> lambda = 0.94
> S<-cov(returns)                                         # initial (t=1)
> covariance matrix
> EWMA[1,] = c(S)[c(1,4,2)]                  ---ERROR        # extract the
> variances and covariancefor (i in 2:T)
>
>    {            # loop though the sample
>         S<- lambda*S+(1-lambda)*t(returns[i])%*%returns[i]
>         EWMA[i,] = c(S)[c(1,4,2)]       # convert matrix to vector
>  }
>
> *ERROR as follows:*
>
> *> EWMA[1,]<-c(S)[c(1,4,2)]*
> *Error in EWMA[1, ] <- c(S)[c(1, 4, 2)] : *
> *  number of items to replace is not a multiple of replacement length*
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to