Forecast and estimate in rolling window
Show older comments
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?
6 Comments
Image Analyst
on 25 Nov 2016
I don't understand the terminology. What does "Data set dependent variable (T): 521" mean??? Does that mean T is a 1-D array with 521 elements?
What does "400(r) to 521(T)" mean? Does the window go from element 400 to 521? On the r array or the T array? I don't know.
Does this have anything to do with the financial toolbox???
Astrik
on 25 Nov 2016
Image Analyst
on 25 Nov 2016
Exactly which form of fitlm() are you using? I can't tell:
Description
mdl = fitlm(tbl) returns a linear model fit to variables in the table or dataset array tbl. By default, fitlm takes the last variable as the response variable.
mdl = fitlm(tbl,modelspec) returns a linear model of the type you specify in modelspec fit to variables in the table or dataset array tbl.
mdl = fitlm(X,y) returns a linear model of the responses y, fit to the data matrix X.
mdl = fitlm(X,y,modelspec) returns a linear model of the type you specify in modelspec for the responses y, fit to the data matrix X.
mdl = fitlm(_,Name,Value) returns a linear model with additional options specified by one or more Name,Value pair arguments.
For example, you can specify which variables are categorical, perform robust regression, or use observation weights.
Astrik
on 30 Nov 2016
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).
- Yes. This his how you would perform a rolling window regression.
- 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.
- 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 ...
Answers (0)
Categories
Find more on Gaussian Process Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!