The inverse of covariance matrix in Markowitz optimization

3 次查看(过去 30 天)
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)

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Portfolio Optimization and Asset Allocation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by