Dear Users
I have to do OLS every month for two series, which are both daily data. So I
am supposed to do the regression for 84 times for 7 years data. Since it is
supposed to do month, I can not use rollOLS function, which fix the rolling
window. So I refer to aggregateSeries function and use to use these script
to execute the program.
ols.month = function (x)
{
tmp = seriesData(x)
tmp1 = tmp[,1]
tmp2 = tmp[,2]
tmp.ols= OLS(tmp1~tmp2)
ols.beta = tmp.ols$coef[2]
ols.r = summary(tmp.ols)$rsq
ans = concat(ols.beta, ols.r)
}
tmp.result =
aggregateSeries(tmp,by="months",FUN=ols.month,colnames=c("beta","R-square"))
where x is a time series object and has two vectors. The ols.month runs well
for a time series object. But when it is used in aggregateSeries, it always
shows
"Problem in object@data: Class "matrix" has no "data" slot"
I don't know what is going on. Could someone help me with this?
Regards,
Sichong
SPLUS 7.0 and FinMetrics 2.0
|