# Forecast and estimate in rolling window

29 views (last 30 days)
Astrik on 25 Nov 2016
Edited: Astrik on 2 Dec 2016
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?

Astrik on 30 Nov 2016
I use mdl = fitlm(X,y) this type that returns a linear model of the responses y, fit to the data matrix X
Brendan Hamm on 30 Nov 2016
I'm not sure how you are using h in this model as you do no forecasting. If you set this value to zero then all of the answers I give below hold. However with this set to 2 you are again shifting your frame of reference (see 3. below).
1. Yes. This his how you would perform a rolling window regression.
2. Plotting would be a good way to visually check the stability of the assets beta. I would not generally expect stability to hold in most cases as time-invariance is not typical, despite the assumptions of many models such as CAPM.
3. Not sure what you mean here. r is not changing in this model; i is. You have the same sample size on every single regression (400), the difference is in the indices of the regressor and response variables. So in other words what is rolling is your frame in time:
Beta Estimate 1: t=1 to T=400
Beta Estimate 2: t=2 to T=401
Beta Estimate 3: t=3 to T=402 ...
Astrik on 2 Dec 2016
1. Its fine that you confirmed it.
2. I am going to plot but I have very small p-values
3. You are right in this example I am not rolling the window. But later I run a loop for r where r has different values such as 1/2 of the whole sample, 1/3 of the whole sample etc.
As for forecasting I have the following
l=length of the sample
s_t=forecasted values of exchange rate
X_t=predictor variable
for t=r:l-h
s_t(t+h)=A(t,1)+B(t,1)*(X(t+h)-X(t));
end
It means for every next h exchange rate I use the evaluated values of alpha and beta and the realized h-step difference of predictor variable. (as the exchange rates are also log-differenced)