matlab代码算有效边界
Returns = [0.1 0.15 0.12 0.4];
STDs = [0.01882 0.014376 0.01575 0.01300 0.0167 0.00913 0.0169 0.015517 0.016096 0.01260];
Correlations = [ 1 0.8 0.5 0.2
0.8 1 0.3 0.7
0.5 0.3 1 0.1
0.2 0.7 0.1 1 ];
Covariances = corr2cov(STDs, Correlations);
portopt(Returns, Covariances, 20) %画出有效前沿曲线
rand('state', 0);
Weights = rand(1200, 10);
Total = sum(Weights, 2);
Weights(:,1) = Weights(:,1)./Total;
Weights(:,2) = Weights(:,2)./Total;
Weights(:,3) = Weights(:,3)./Total;
Weights(:,4) = Weights(:,4)./Total;
Weights(:,5) = Weights(:,5)./Total;
Weights(:,6) = Weights(:,6)./Total;
Weights(:,7) = Weights(:,7)./Total;
Weights(:,8) = Weights(:,8)./Total;
Weights(:,9) = Weights(:,9)./Total;
Weights(:,10) = Weights(:,10)./Total;
[PortRisk, PortReturn] = portstats(Returns, Covariances, Weights); hold on
plot(PortRisk, PortReturn, '.r') %画出各个资产组合风险与收益
title('均值-方差有效前沿以及各个资产组合风险与收益','fontsize',12) xlabel('风 险(标准差)','fontsize',10)
ylabel('期望收益率','fontsize',10)
y=0.03413+0.29*Covariances
plot()
hold off