rollapply with overlap

Hi,

I have a time-series with prices of two stocks. I would like to regress them on each other, and calculate the coefficient on every 125 day, based on the previous 250 observation. I found out, that the code below does this more or less. My only problem is that, with this solution, the windows are 1 day shorter, bacause they do not overlap. Is there a method which lets that the last day of a period be the first day of the next period as well?

coef<- function(x){
return(lm(x[,1]~0+x[,2])$coefficient[1])
}

beta<-na.locf(rollapply(merged,width = 250, FUN=coef, by.column = F, align = "right", by=125), fromLast = T)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.