For loop over different dimensions
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Anton Sørensen
am 19 Feb. 2020
Kommentiert: Anton Sørensen
am 22 Feb. 2020
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.
2 Kommentare
darova
am 19 Feb. 2020
I don't understand the question
X=[alfa factor]; % My matrix containing explanatory variables
alfa and factor are of different sizes? Are you trying to concantenate them?
Akzeptierte Antwort
darova
am 19 Feb. 2020
What about filling with NaN?
y = portfolios(:,i); % Between 60 and 180 observation
if length(portfolios(:,i)) < 180
y(end+1:180) = nan;
end
results = ols(y,X); % Functionen constructing a struct with prefered OLS estimates
20 Kommentare
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Portfolio Optimization and Asset Allocation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!