Example: Rolling estimation procedure
This example uses 400 observations of generated data with a break in the intercept after 120 observations. The error terms are standard normal. The data is replicated using the code below:
| |
| library tsmt; |
| |
| |
| b1 = { 1.2, -2, 0.75 }; |
| b2 = { 5, -2, 0.75 }; |
| |
| |
| n1 = 120; |
| |
| |
| n_tot = 400; |
| |
| |
| xt = ones(n_tot,1)~rndn(n_tot,2); |
| err = rndn(n_tot,1); |
| |
| |
| y1 = xt[1:n1,.]*b1 + err[1:n1,.]; |
| y2 = xt[n1+1:n_tot,.]*b2 + err[n1+1:n_tot,.]; |
| yt_break = y1|y2; |
Next we set the parameters to run a rolling window regression on the data simulated above and run the regression.
| |
| wind = 15; |
| |
| |
| |
| add = 15; |
| |
| |
| gr = 1; |
| |
| { beta, res, w } = rolling(yt_break, xt, wind, add, gr); |
Which produces the following three graphs for Beta 1, Beta 2 and Beta 3:
Finally we set parameters to run a forward expanding window regression and run the regression.
| |
| wind = -15; |
| |
| |
| |
| add = 15; |
| |
| |
| gr = 1; |
| |
| { beta_fwd, res_fwd, w_fwd } = rolling(yt_break, xt, wind, add, gr); |
Which produces the following three graphs for Beta 1, Beta 2 and Beta 3: