Whether the code for plotting efficiency frontier is correct or not?
Show older comments
% Task is to plot efficiency frontier for the current energy mix (portfolio) indicating Sharpe ratio, % and plot assets with their returns and deviations. % There is countryZ, where there are four enegy companies (compapy1...company4) operating. % Energy mix (portfolio) of the countryZ consists of seven energy assets % ({'A','B','C','D','E','F','G'}). Energy mixes (portfolios) of each of four energy companies consists of different % combinations of the mentioned energy assets. Prices (costs) for the energy assets are given for a period of % six years ({'1';'2';'3';'4';'5';'6'}). Current energy portfolios of the countryZ as well as four enegy companies % are as the following: % CountryZ= [0.49;0.8;0.12;0.01;0.01;0.01;0.28]; % Company1=[0.78;0.21;0;0.01;0.001;0;0]; % Company2=[0;0;0.02;0;0;0;0.98]; % Company3=[1;0;0;0;0;0;0]; % Company4=[0;0;1;0;0;0;0]; % I would like to know whether the code below makes any sence, whether it is correct? % Does it mean that Sharpe ratio indicates the most riskless portfolio on the efficiency frontier?
AssetList={'A','B','C','D','E','F','G'}; c=AssetCovar; m=AssetMean; year={'1';'2';'3';'4';'5';'6'}; A=[44.8;55.7;59.1;63.4;70.7;88]; B=[68.8;87.2;104.9;106.6;112.8;168.3]; C=[11.4;12.9;20.7;20.1;30.2;71.1]; D=[93.8;137.4;276.9;262.4;286;434.1]; E=[93.8;137.4;276.9;262.4;286;434.1]; F=[93.8;137.4;276.9;262.4;286;434.1]; G=[15.8;18.8;21.4;21.7;27.7;39.5]; T=table(year,A,B,C,D,E,F,G); symbol = T.Properties.VariableNames(2:end)'; Return = tick2ret(T{:,2:end}); m=mean(Return)'; C=cov(Return); p = Portfolio; p = setAssetMoments(p, m, C); [assetmean, assetcovar] = getAssetMoments(p); p = setInitPort(p,1/p.NumAssets); [prsk,pret] = estimatePortMoments(p,p.InitPort); p = setDefaultConstraints(p); pwgt = estimateFrontier(p); p = setDefaultConstraints(p); pwgt = estimateFrontier(p); [prsk, pret] = estimatePortMoments(p, pwgt); pwgtCountryZ=[0.49;0.8;0.12;0.01;0.01;0.01;0.28]; pwgtCompany1=[0.78;0.21;0;0.01;0.001;0;0]; pwgtCompany2=[0;0;0.02;0;0;0;0.98]; pwgtCompany3=[1;0;0;0;0;0;0]; pwgtCompany4=[0;0;1;0;0;0;0]; [CountryZrsk, CountryZret] = estimatePortMoments(p, pwgtCountryZ); [Company1rsk, Company1ret] = estimatePortMoments(p, pwgtCompany1); [Company2rsk, Company2ret] = estimatePortMoments(p, pwgtCompany2); [Company3rsk, Company3ret] = estimatePortMoments(p, pwgtCompany3); [Company4rsk, Company4ret] = estimatePortMoments(p, pwgtCompany4); swgt = estimateMaxSharpeRatio(p); [srsk,sret] = estimatePortMoments(p,swgt); p = setDefaultConstraints(p); pwgt = estimateFrontier(p,10); [prsk,pret] = estimatePortMoments(p,pwgt); p = Portfolio('assetmean', m, 'AssetList',{'A','B','C','D','E','F','G'},'assetcovar', C, ... 'lowerbudget', 1, 'upperbudget', 1, 'lowerbound', 0); clf; portfolioexamples_plot('Efficient Frontier with Maximum Sharpe Ratio Portfolio', ... {'line', prsk, pret}, ... {'scatter', srsk, sret, {'Sharpe'}}, ... {'scatter', [CountryZrsk,Company1rsk,Company2rsk,Company3rsk,Company4rsk], [CountryZret,Company1ret,Company2ret,Company3ret,Company4ret], {'CountryZ','Company1','Company2','Company3','Company4'}}, ... {'scatter', sqrt(diag(p.AssetCovar)), p.AssetMean, p.AssetList, '.r'});
Answers (0)
Categories
Find more on Portfolio Optimization and Asset Allocation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!