29 views (last 30 days)

I am trying to estimate the parameters in rolling window regression and then conduct a out-of sample fit forecast with realized values of predictor. I have the following data:

- The data set of the dependent variable is a vector of length T=521
- The data set predictor is a vector of length T=521
- In sample window size is denoted as r, r=400
- Forecast horizon is denoted as h, h=2

I have estimated my parameters using the following MATLAB code

for i=r:T

lm=fitlm(X(i-r+h+1:i),y_diff(i-r+h+1:i));

alpha(i,1)=lm.Coefficients.Estimate(1,:);

beta(i,1)=lm.Coefficients.Estimate(2,:);

end

1. Is this the correct way to implement a rolling window regression in MATLAB? It means my window rolls from 400(r) to 521(T) at interval of 1.

2. In order to analyze the stability of beta estimate should I plot these results? Or I should make the interval bigger such as r:10:T and than estimate the parameters?

3. I need to understand what exactly should I roll in order to perfom the regression? In sample size r already rolls from 400 to 521 so is that enough?

Opportunities for recent engineering grads.

Apply TodayFind the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
## 6 Comments

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/313961-forecast-and-estimate-in-rolling-window#comment_409053

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/313961-forecast-and-estimate-in-rolling-window#comment_409053

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/313961-forecast-and-estimate-in-rolling-window#comment_409093

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/313961-forecast-and-estimate-in-rolling-window#comment_409093

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/313961-forecast-and-estimate-in-rolling-window#comment_409104

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/313961-forecast-and-estimate-in-rolling-window#comment_409104

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/313961-forecast-and-estimate-in-rolling-window#comment_410315

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/313961-forecast-and-estimate-in-rolling-window#comment_410315

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/313961-forecast-and-estimate-in-rolling-window#comment_410355

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/313961-forecast-and-estimate-in-rolling-window#comment_410355

## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/313961-forecast-and-estimate-in-rolling-window#comment_410780

⋮## Direct link to this comment

https://se.mathworks.com/matlabcentral/answers/313961-forecast-and-estimate-in-rolling-window#comment_410780

Sign in to comment.