rolling window regression code

Hi,just a question about a rolling window regression code that I found on Mathwork.I found this rolling window regression code however, I am not quite clear how to apply it in matlab. I currently have a variable:8(independent variables)*240(20years*12months)and a variable:100(dependent variables)*240. I want to conduct a 36month rolling window regression with a 'step' at 1. The purpose of running multi-factor regression model is to test whether these 100 companies generate abnormal returns (run regression 100 times and get 100 series of alphas) and therefore I want to get alphas.So, can anymore help me fill this function?
Many thanks
function [Coefficients, Estimates, Residuals, stats, rolling window] = wreg(y,x,alpha,constant,window,step)
stoppingpoint = (length(x)-window+1);
rolling_window = zeros(2,stoppingpoint);
[Coefficients, Estimates, Residuals, stats] = reg(y(1:window,:),x(1:window,:),alpha,constant);
i = 0;
HC1_cell = cell(1,1); %#ok<NASGU>
HC2_cell = cell(1,1); %#ok<NASGU>
for s = 1:step:stoppingpoint
i = i + 1;
[Coefficients(:,i), Estimates(:,i), Residuals(:,i), stats] = reg2(y(s:s+window-1,1),x(s:s+window-1,:),alpha,constant,stats,i);
rolling_window(1,i) = s; % Start
rolling_window(2,i) = s+window-1; % Stop
end
rolling_window(:,i+1:end) = [];
end

Answers (1)

Walter Roberson
Walter Roberson on 13 Aug 2015
The source http://www.mathworks.com/matlabcentral/fileexchange/34394-fast---detailed-multivariate-ols-regression/content/reg/wreg.m is commented about its purpose and the variables. It also says that the function is based upon reg() so you can read the comments in that source for more about the expected inputs and outputs.

Asked:

on 12 Aug 2015

Answered:

on 13 Aug 2015

Community Treasure Hunt

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

Start Hunting!