2 views (last 30 days)

I have to loop over i portfolios with different dimensions, in order to obtain OLS estimates

My length of the portfolios can be anything between 60 to 180.

For now it is a fairly simple loop, if I just have a fixed length on say 180, however I can't find a solution, when I have to extend the loop and allow for different dimensions.

I am thinking I need to put a restriction on both my X matrix (Explanatory variables) and Y matrix (Portfolios), so the loop will switch to the different dimensions depending on which i'th portfolio it loops over.

Here is the loop now:

for i = 1:size(portfolios,2)

X=[alfa factor]; % My matrix containing explanatory variables

y=portfolios(:,i); % Between 60 and 180 observations

results=ols(y,X); % Functionen constructing a struct with prefered OLS estimates

estimates(:,i)=results.beta;

tstat(:,i)=results.tstat(1);

residuals=results.resid;

end

Thanks in advance.

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/506481-for-loop-over-different-dimensions#comment_799699

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/506481-for-loop-over-different-dimensions#comment_799699

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/506481-for-loop-over-different-dimensions#comment_799701

⋮## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/506481-for-loop-over-different-dimensions#comment_799701

Sign in to comment.