Problem with Portfolio Optimization, Mean Returns are not processed as vectors

1 Ansicht (letzte 30 Tage)
Hey everybody,
I am trying to implement a classical portfolio optimization à la Markowitz with financial tooldbox. The data input is according to the following: (a 660x500 matrix)
Asset1 Asset2 Asset3 Asset4 ...... Asset500
1960_01
1960_02
...
...
2014_12
the entries are monthly returns in that specific slot.
Now I try to perform the calculation of the efficient frontier using the Portfolio commands: First I cut the size of the set into intervals (later it will be in a for loop, for now I am trying to create a interval of the first 60 months):
ret_temp = ret(1:60,:); %subset of the dataset
.
Now, I am calculating the mean return and the var/cov matrix for each asset in this subpart:
mean_temp = nanmean(ret_temp); %returns a vector of mean returns of each asset cov_temp = nancov(ret_temp); %var/cov matrix of the sample period
now I can perform a portfolio optimization based on these inputs:
p = Portfolio; p = setAssetMoments(p,mean_temp,cov_temp); p = setDefaultConstraints(p); pwgt = estimateFrontier(p, 10);
Now, when running the code, the following Error appears:
Error using codename (line 18) Cannot set moments of asset returns.
Caused by: Error using Portfolio/parsearguments (line 101) Invalid AssetMean must be a scalar or a vector.
However, my asset means are clearly a vector and I cannot understand why this error is popping up..
Thank you very much in advance!
Clemens

Akzeptierte Antwort

Brendan Hamm
Brendan Hamm am 8 Jul. 2015
The problem is likely due to the presence of all NaNs in one of your return series, which results in a NaN even using nanmean.
rng('default')
X = rand(5,3); % Create a random matrix
X(2,:) = NaN; % Set an entire row to NaN
X(:,3) = NaN; % Set an entire column to NaN
nanmean(X)
ans =
0.6219 0.6417 NaN
Notice nanmean will ignore the NaNs in a column, but if the entire column is a NaN you will have trouble. For this reason you will need to perform a little more data cleaning before hand.

Weitere Antworten (0)

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!

Translated by