The inverse of covariance matrix in Markowitz optimization

3 Ansichten (letzte 30 Tage)
Xia
Xia am 27 Sep. 2015
Bearbeitet: Xia am 28 Sep. 2015
I’m doing a portfolio optimization problem but the covariance matrix is not of full rank. However, the portopt function does figure out the efficient frontier, while the code I made following mean-variance equation can’t get that. The warning is that “Matrix is close to singular or badly scaled.” Could anyone tell me how to improve the code? Thanks a lot.
%%%code using portopt function
load('SP500.mat')
SPT=SP500';
SP=SPT(~any(isnan(SPT),2),:);
SP=SP';
Ret=price2ret(SP);
Stocks=Ret(:,2:end);
Index=Ret(:,1);
R=mean(Stocks);
Cov=cov(Stocks);
Std=std(Stocks);
portopt(R,Cov,30)
hold on
plot(Std,R,'.r')
plot(std(Index),mean(Index),'*k')
legend('Efficient Frontier','Individual Stocks','S&P 500')
%%%code using mean-variance equation
load('SP500.mat')
SPT=SP500';
SP=SPT(~any(isnan(SPT),2),:);
SP=SP';
Ret=price2ret(SP);
Stocks=Ret(:,2:end);
Index=Ret(:,1);
R=mean(Stocks);
Cov=cov(Stocks);
Std=std(Stocks);
Inv=inv(Cov);
One=ones(size(R,2),1);
a=R*Inv*R';
b=R*Inv*One;
c=One'*Inv*One;
x=0:0.005:0.25;
y=sqrt((c*x.^2-2*b*x+a)/(a*c-b^2));
plot(y,x)

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