The inverse of covariance matrix in Markowitz optimization

2 ビュー (過去 30 日間)
Xia
Xia 2015 年 9 月 27 日
編集済み: Xia 2015 年 9 月 28 日
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 Center および File ExchangePortfolio 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