Effacer les filtres
Effacer les filtres

Loop over different matrix sizes

2 vues (au cours des 30 derniers jours)
Anton Sørensen
Anton Sørensen le 27 Fév 2020
Commenté : Anton Sørensen le 28 Fév 2020
I have a dataset containing y portfolios which consists of a length that can be anything between 60 to 180 observations.
These portfolios have to be regressed on their respective factors. The factor length is fixed at 180 observations. So for instance a portfolio containing 60 observations needs to be regressed on the 60 matching factor observations.
My portfolios can either contain:
180 observations, meaning they have data available for the entire period.
Less than 180 observations, but always at least 60 observations:
  • They can either have observations from the beginning of the datapoint, but they can have missing data at some point in the data (for instance observations available from t0-t60)
  • They can also start up during the data period. For instance from t100-t170.
As suggested in an earlier solution i need to load in the portfolios and in order to do so, I need to fill with NaN to make the matrix in same length.
So how do I make a loop that can capture the dynamics of my dataset?
At the moment I am thinking of an "if" function that will state that if NaN is present it will be ignored and the available data will then be regressed on the matching observations from my factor matrix. An example if portfolio y has observations from t100-t170, then they have to be regressed on factors from t100-t170.
Do you guys have a smart solution for this?
  1 commentaire
Anton Sørensen
Anton Sørensen le 28 Fév 2020
I have resolved the issue now.
For any readers with same issue, simply do the following:
wasnan=(isnan(y));
havenans=any(wasnan);
if havenans
y=wasnan=[];
factors(wasnan,:)=[]; %this ensures that if there is missing data (NaN) the factor matrix will be reduced to the same length as the length of y, when ignorring Nan's.
end
results=ols(y,factors); %Function creating my ols estimates, residuals series, etc.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Portfolio Optimization and Asset Allocation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by