[R] Rolling window linear regression

Grace Shi 1104271103 at qq.com
Sat Oct 4 09:09:25 CEST 2014


	
I have to do roll regression based on the Daily data. I use the past three
weeks of daily returns as the estimation window and the regression is
estimated rolling forward one week at a time generating time series
estimates of beta. I know I should use the rollapply in zoo package. but I
am not sure how to  do.

data example:

 stock        day             week          y              x
 "00001"      2009-01-02     2009-01      0.89          2.45
 "00001"      2009-01-03     2009-01      1.21          1.90
 "00001"      2009-01-04     2009-01      0.12          0.89
 "00001"      2009-01-05     2009-01      1.45          2.78
 "00001"      2009-01-06     2009-01      1.98          0.98
 "00001"      2009-01-09     2009-02      3.34          1.23
 "00001"      2009-01-10     2009-02      0.12          0.89
 "00001"      2009-01-11     2009-02      1.45          2.78
 "00001"      2009-01-13     2009-02      1.98          0.98
 "00001"      2009-01-16     2009-03      3.38          0.93
 "00001"      2009-01-17     2009-03      6.56          3.90
 "00001"      2009-01-18     2009-03      5.09          3.45
 "00001"      2009-01-19     2009-03      5.89          3.78

 


	[[alternative HTML version deleted]]



More information about the R-help mailing list