Hi All, I have 5 stock values and i am calculating EWMA followed the logic as given ind following link.[ http://www.orecastingfinancialrisk.com/3.html<http://www.forecastingfinancialrisk.com/3.html> ]
library('tseries') returns[,1]<-returns[,1]-mean(returns[,1]) returns[,2]<-returns[,2]-mean(returns[,2]) returns[,3]<-returns[,3]-mean(returns[,3]) returns[,4]<-returns[,4]-mean(returns[,4]) returns[,5]<-returns[,5]-mean(returns[,5]) T<-length(returns[,1]) T EWMA<-matrix(nrow=T,ncol=5) lambda=0.94 S<-cov(returns) S EWMA[1,] <- S[lower.tri(S,diag=TRUE)] *Error in EWMA[1, ] <- S[lower.tri(S, diag = TRUE)] : * * number of items to replace is not a multiple of replacement length* * * for(i in 2:T) { S<- lambda*S +(1-lambda)*t(returns[i])%*% returns[i] EWMA[i,] <- S[lower.tri(S,diag=TRUE)] } * * [[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.