Two Efficient frontiers in one figur

6 visualizzazioni (ultimi 30 giorni)
Alexander Wehner
Alexander Wehner il 26 Feb 2018
Risposto: Dimitrios Tsampas il 27 Ago 2022
I am using a portfolio optimization script to get the max sharp ratio. So far so good, i am able to plot the frontier in one figur. Now i need to add another portfolio (same portfolio + test asset), repeat the procedure. So i get another figure. But i want so get the new frontier in the same figure than the older on. Another possibility would be to add a specific constrain to exclude and than include my test asset. However, i need both frontiers in the same figure to be able to compare them.
I used the following script:
T = readtable('TestMathlab.xlsx') symbol = T.Properties.VariableNames(3:end)'; dailyReturn = tick2ret(T{:,3:end}); p = Portfolio('AssetList',symbol,'RiskFreeRate',0.01/252); p = estimateAssetMoments(p, dailyReturn); p = setDefaultConstraints(p); w1 = estimateMaxSharpeRatio(p) [risk1, ret1] = estimatePortMoments(p, w1)
f = figure; tabgp = uitabgroup(f); % Define tab group tab1 = uitab(tabgp,'Title','Efficient Frontier Plot'); % Create tab ax = axes('Parent', tab1); % Extract asset moments from portfolio and store in m and cov [m, cov] = getAssetMoments(p); scatter(ax,sqrt(diag(cov)), m,'oc','filled'); % Plot mean and s.d. xlabel('Risk') ylabel('Expected Return') text(sqrt(diag(cov))+0.0003,m,symbol,'FontSize',7); % Label ticker names Plot optimal portfolio and efficient frontier using plotFrontier hold on; [risk2, ret2] = plotFrontier(p,10); plot(risk1,ret1,'p','markers',15,'MarkerEdgeColor','k',... 'MarkerFaceColor','y'); hold off Visualize table in MATLAB tab2 = uitab(tabgp,'Title','Optimal Portfolio Weight'); % Create tab
% Column names and column format columnname = {'Ticker','Weight (%)'}; columnformat = {'char','numeric'};
% Define the data as a cell array data = table2cell(table(symbol(w1>0),w1(w1>0)*100));
% Create the uitable uit = uitable(tab2, 'Data', data,... 'ColumnName', columnname,... 'ColumnFormat', columnformat,... 'RowName',[]);
% Set width and height uit.Position(3) = 450; % Widght uit.Position(4) = 350; % Height
Any solution to get both frontiers in one figure?

Risposte (1)

Dimitrios Tsampas
Dimitrios Tsampas il 27 Ago 2022
Hello Alexander,
4 years later I happened to have the same question. And as I can see we are using the same optimization code. After a lot of experimenting, I came up with the following code (it is a modified version from the code in: https://uk.mathworks.com/matlabcentral/fileexchange/60433-getting-started-with-portfolio-optimization-files-for-video-demom ):
%% Plot Efficient Frontiers together
f = figure;
tabgp = uitabgroup(f); % Define tab group
tab1 = uitab(tabgp,'Title','Efficient Frontier Plot'); % Create tab
ax = axes('Parent', tab1);
% Extract asset moments from portfolio and store in m and cov
[m, cov] = getAssetMoments(p1);
scatter(ax,sqrt(diag(cov)), m,'oc','filled'); % Plot mean and s.d.
xlabel('Risk')
ylabel('Expected Return')
text(sqrt(diag(cov))+0.0003,m,symbol1,'FontSize',7); % Label ticker names
hold on;
[risk, ret] = plotFrontier(p,10);
hold on
[risk1, ret1] = plotFrontier(p1,10);
hold off
In my case though, I have to note that I have two portfolios p and p1 (with symbol and symbol1 accordingly) attained through the proccess you describe. But, p1 already includes the assets of p. So, this is why I let p1's details appear in the graph, as they cover both portfolios.
If you have two portfolios with entirely different assets, then you could perhaps adjust the code a little bit to your needs.
Hopefully, this will help other people too.
Cheers.

Categorie

Scopri di più su Portfolio Optimization and Asset Allocation in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by