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?
beta<-na.locf(rollapply(merged,width = 250, FUN=coef, by.column = F, align = "right", by=125), fromLast = T)