The inverse of covariance matrix in Markowitz optimization

2 visualizaciones (últimos 30 días)
Xia
Xia el 27 de Sept. de 2015
Editada: Xia el 28 de Sept. de 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)

Respuestas (0)

Categorías

Más información sobre Portfolio Optimization and Asset Allocation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by