Hi everybody,
I am trying to create a loop using the function mvregress. I need to estimate coefficients, as well as the other outputs, with a rolling window of 60 months. I faced a problem with the allocation in the empty matrix, since the output "b" is a 2×1 vector. If I have, for instance, 203 months of observations for 43 stocks and I want to start with a time window of 60 months. I would do the following:
w=60;CAPM_data=CAPM_Factors_data; %Import CAPM data
STOXX_M_EXRet= STOXX_M_Ret- repmat(CAPM_data(:,2),1,size(STOXX_M_Ret,2)); %Create Asset Excess returns
[T,n] = size(STOXX_M_EXRet);XCAPM=[ones(T,1) , CAPM_data(:,1)]; %Create design matrix adding ones vectors to include constant
CAPMParameters=zeros(T-w,n);for j=w:T for i=1:n[CAPMParameters(j,i)] = mvregress(STOXX_M_EXRet(j+1-w:j,:),XCAPM(j+1-w:j,:)); end; end;
When I run this loop, I get "Subscripted assignment dimension mismatch". This is given by the fact that it's trying to allocate a 2×1 vector (constant and beta) in a single cell.
Could someone please help me? I would like to obtain a time series of all the values of the output (for example, a matrix with 286 rows (each2 rows the parameters at time t)).
Thank you very much
Best Answer