Main Content

plotFrontier

Plot efficient frontier

Description

[prsk,pret] = plotFrontier(obj) estimates the efficient frontier with default number of 10 portfolios on the frontier, and plots the corresponding efficient frontier for Portfolio, PortfolioCVaR, or PortfolioMAD objects. For details on the respective workflows when using these different objects, see Portfolio Object Workflow, PortfolioCVaR Object Workflow, and PortfolioMAD Object Workflow.

example

[prsk,pret] = plotFrontier(obj,NumPortfolios) estimates the efficient frontier with a specified number of portfolios (NumPortfolios) on the frontier, and plots the corresponding efficient frontier.

example

[prsk,pret] = plotFrontier(obj,PortfolioWeights) estimates efficient portfolio risks and returns with PortfolioWeights, and plots the efficient frontier with those portfolios. This syntax assumes that you provide valid efficient portfolio weights as input. PortWeights is a NumAssets-by-NumPortfolios matrix.

example

[prsk,pret] = plotFrontier(obj,PortfolioRisks,PortfolioReturns) plots the efficient frontier with the given risks and returns. This syntax assumes that you provide valid inputs for efficient portfolio risks and returns. PortfolioRisks and PortfolioReturns are vectors with the same size.

Note

plotFrontier handles multiple input formats as described above. Given an asset universe with NumAssets assets and an efficient frontier with NumPortfolios portfolios, remember that portfolio weights are NumAsset-by-NumPortfolios matrices and that portfolio risks and returns are NumPortfolios-by-1 column vectors.

example

[prsk,pret] = plotFrontier(ax,obj,___) displays the efficient frontier in the target axes (ax). Axes can be specified as an optional first input argument in any of the previous syntaxes.

example

[prsk,pret] = plotFrontier(obj,___,Name=Value) specifies the axes where the efficient frontier is displayed using the name-value argument Parent.

example

[prsk,pret,h] = plotFrontier(___) plots the efficient frontier and additionally returns a graphics object or an array of graphic objects (h). Use h to modify properties of the efficient frontier after creating it.

example

Examples

collapse all

Given a portfolio p, plot the efficient frontier.

load CAPMuniverse

p = Portfolio('AssetList',Assets(1:12));
p = estimateAssetMoments(p, Data(:,1:12),'missingdata',true);
p = setDefaultConstraints(p);
plotFrontier(p);

Figure contains an axes object. The axes object with title Efficient Frontier, xlabel Standard Deviation of Portfolio Returns, ylabel Mean of Portfolio Returns contains an object of type line. This object represents Efficient Frontier.

Given a portfolio p, plot the efficient frontier and specify an axes object using the Parent name-value argument.

% Define the Portfolio object.
m = [ 0.05; 0.1; 0.12; 0.18 ];
C = [ 0.0064 0.00408 0.00192 0; 
    0.00408 0.0289 0.0204 0.0119;
    0.00192 0.0204 0.0576 0.0336;
    0 0.0119 0.0336 0.1225 ];
p = Portfolio(AssetMean=m,AssetCovar=C);
p = setDefaultConstraints(p);

Plot 20 efficient portfolios for the Portfolio object on the left y-axes using the Parent name-value argument.

fig = figure;
ax = newplot(fig);
yyaxis(ax,'left')
[~,~,h1] = plotFrontier(p,20,Parent=ax);

Plot 20 efficient portfolios for the associated PortfolioCVaR object on the right y-axes using the Parent name-value argument.

% Create PortfolioCVaR object
AssetScenarios = mvnrnd(m,C,1000);
pCVaR = PortfolioCVaR(Scenarios=AssetScenarios,ProbabilityLevel=0.95);
pCVaR = setDefaultConstraints(pCVaR);

% Plot
yyaxis(ax,'right')
[~,~,h2] = plotFrontier(pCVaR,20,Parent=ax);
h2.Color = 'r';
h2.LineStyle = ':';
xlabel(ax,'Portfolio Returns Risk')
legend('Standard Deviation','CVaR')

Figure contains an axes object. The axes object with title Efficient Frontier, xlabel Portfolio Returns Risk, ylabel Mean of Portfolio Returns contains 2 objects of type line. These objects represent Standard Deviation, CVaR.

Given a portfolio p, plot the efficient frontier and specify an axes object using an optional first input argument.

% Define the Portfolio object.
m = [ 0.05; 0.1; 0.12; 0.18 ];
C = [ 0.0064 0.00408 0.00192 0; 
    0.00408 0.0289 0.0204 0.0119;
    0.00192 0.0204 0.0576 0.0336;
    0 0.0119 0.0336 0.1225 ];
p = Portfolio(AssetMean=m,AssetCovar=C);
p = p.setDefaultConstraints;

% Add an initial portfolio to a copy of the Portfolio object.
pInit = p;
pInit.InitPort = 1/4*ones(4,1);

Plot both Portfolio objects efficient frontiers using different axes.

figure
ax1 = axes('Position',[0.1 0.1 0.7 0.7]);
ax2 = axes('Position',[0.65 0.65 0.28 0.28]);

Plot the efficient frontier for the Portfolio object without the initial portfolio (p) in ax2.

[~,~,h] = plotFrontier(ax2,p)
h = 
  Line (Efficient Frontier) with properties:

              Color: [0 0.4470 0.7410]
          LineStyle: '-'
          LineWidth: 2
             Marker: 'none'
         MarkerSize: 6
    MarkerFaceColor: 'none'
              XData: [0.0769 0.0831 0.0994 0.1217 0.1474 0.1750 0.2068 0.2487 0.2968 0.3500]
              YData: [0.0590 0.0725 0.0859 0.0994 0.1128 0.1262 0.1397 0.1531 0.1666 0.1800]

  Use GET to show all properties

Plot the efficient frontiers for the Portfolio object with initial portfolio (pInit) in ax1.

[~,~,hInit] = plotFrontier(ax1,pInit)
hInit = 
  2x1 graphics array:

  Scatter    (Initial Portfolio)
  Line       (Efficient Frontier)

Modify the plot properties.

h.LineStyle = '--';
hInit(1).MarkerFaceColor = 'r';

Figure contains 2 axes objects. Axes object 1 with title Efficient Frontier, xlabel Standard Deviation of Portfolio Returns, ylabel Mean of Portfolio Returns contains 2 objects of type scatter, line. These objects represent Initial Portfolio, Efficient Frontier. Axes object 2 with title Efficient Frontier, xlabel Standard Deviation of Portfolio Returns, ylabel Mean of Portfolio Returns contains an object of type line. This object represents Efficient Frontier.

Create a Portfolio object for 12 stocks based on CAPMuniverse.mat.

load CAPMuniverse
p0 = Portfolio('AssetList',Assets(1:12));
p0 = estimateAssetMoments(p0, Data(:,1:12),'missingdata',true);
p0 = setDefaultConstraints(p0);

Use setMinMaxNumAssets to define a maximum number of 3 assets.

pWithMaxNumAssets = setMinMaxNumAssets(p0, [], 3);

Use setBounds to define a lower and upper bound and a BoundType of 'Conditional'.

pWithConditionalBound = setBounds(p0, 0.1, 0.5,'BoundType', 'Conditional');

Use plotFrontier to compare the different portfolio objects.

figure;
plotFrontier(p0); hold on; 
plotFrontier(pWithMaxNumAssets); hold on; 
plotFrontier(pWithConditionalBound); hold off;
legend('p0', 'with Max 3 assets invested', ' with each asset weight 0 or [0.1, 0.5]', 'location', 'best');

Figure contains an axes object. The axes object with title Efficient Frontier, xlabel Standard Deviation of Portfolio Returns, ylabel Mean of Portfolio Returns contains 3 objects of type line. These objects represent p0, with Max 3 assets invested, with each asset weight 0 or [0.1, 0.5].

Define a target return and use estimateFrontierByReturn to compare the three portfolio objects.

targetRetn = 2.0e-3;
pwgt0 = estimateFrontierByReturn(p0, targetRetn);
pwgtWithMaxNumAssets = estimateFrontierByReturn(pWithMaxNumAssets, targetRetn);
pwgtConditionalBound = estimateFrontierByReturn(pWithConditionalBound, targetRetn);

The following table shows the final allocation for specified target return among the three portfolio objects. You can see that the small positions in 'AAPL'and 'HPQ' are avoided in pwgtConditionalBound, and only three assets are invested in pwgtWithMaxNumAssets.

result = table(p0.AssetList',pwgt0,pwgtWithMaxNumAssets,pwgtConditionalBound)
result=12×4 table
      Var1       pwgt0      pwgtWithMaxNumAssets    pwgtConditionalBound
    ________    ________    ____________________    ____________________

    {'AAPL'}    0.076791        -5.2042e-17                   0.1       
    {'AMZN'}           0                  0                     0       
    {'CSCO'}           0                  0                     0       
    {'DELL'}           0                  0                     0       
    {'EBAY'}           0                  0                     0       
    {'GOOG'}     0.44841            0.47297               0.44255       
    {'HPQ' }    0.022406                  0                     0       
    {'IBM' }     0.31139            0.34763               0.31592       
    {'INTC'}           0                  0                     0       
    {'MSFT'}     0.14101             0.1794               0.14153       
    {'ORCL'}           0                  0                     0       
    {'YHOO'}           0                  0                     0       

Given a PortfolioCVaR p, plot the efficient frontier.

m = [ 0.05; 0.1; 0.12; 0.18 ];
C = [ 0.0064 0.00408 0.00192 0; 
    0.00408 0.0289 0.0204 0.0119;
    0.00192 0.0204 0.0576 0.0336;
    0 0.0119 0.0336 0.1225 ];
m = m/12;
C = C/12;

AssetScenarios = mvnrnd(m, C, 20000);

p = PortfolioCVaR;
p = setScenarios(p, AssetScenarios);
p = setDefaultConstraints(p);
p = setProbabilityLevel(p, 0.95);

plotFrontier(p);

Figure contains an axes object. The axes object with title Efficient Frontier, xlabel Conditional Value-at-Risk of Portfolio, ylabel Mean of Portfolio Returns contains an object of type line. This object represents Efficient Frontier.

Given a PortfolioMAD p, plot the efficient frontier.

m = [ 0.05; 0.1; 0.12; 0.18 ];
C = [ 0.0064 0.00408 0.00192 0; 
    0.00408 0.0289 0.0204 0.0119;
    0.00192 0.0204 0.0576 0.0336;
    0 0.0119 0.0336 0.1225 ];
m = m/12;
C = C/12;

AssetScenarios = mvnrnd(m, C, 20000);

p = PortfolioMAD;
p = setScenarios(p, AssetScenarios);
p = setDefaultConstraints(p);

plotFrontier(p);

Figure contains an axes object. The axes object with title Efficient Frontier, xlabel Mean Absolute Deviation of Portfolio Returns, ylabel Mean of Portfolio Returns contains an object of type line. This object represents Efficient Frontier.

Input Arguments

collapse all

Since R2024a

(Optional) Axes object in which to display the efficient frontier plot, specified as an Axes object that you create using axes. The optional argument ax can precede any of the input argument combinations. The efficient frontier plot is displayed on the axes specified by the optional ax argument. If you do not specify the axes, MATLAB® plots into the current axes or it creates an axes object if one does not exist. For an example of using an Axes object with plotFrontier, see Display Plot for Efficient Frontier Using Axes Optional First Input.

Data Types: object

Object for portfolio optimization, specified using Portfolio, PortfolioCVaR, or PortfolioMAD object. For more information on creating a portfolio object, see

Data Types: object

(Optional) Number of portfolios to plot on efficient frontier, specified as a scalar integer.

Note

If no value is specified for NumPortfolios, the default value is obtained from the hidden property defaultNumPorts (default value is 10). If NumPortfolios = 1, this function returns the portfolio specified by the hidden property defaultFrontierLimit (current default value is 'min').

Data Types: double

(Optional) Standard deviations of portfolio returns for each portfolio, specified as a NumPortfolios-by-1 column vector.

Note

PortfolioRisks and PortfolioReturns must be vectors with the same size. The risks and returns must be valid values associated to portfolios on the efficient frontier.

If portfolio risks and returns are inputs, make sure that risks come first in the calling sequence. In addition, if portfolio risks and returns are not sorted in ascending order, this method performs the sort. On output, the sorted moments are returned.

Data Types: double

(Optional) Means of portfolio returns for each portfolio, specified as a NumPortfolios-by-1 column vector.

Note

PortfolioRisks and PortfolioReturns must be vectors with the same size. The risks and returns must be valid values associated to portfolios on the efficient frontier.

If portfolio risks and returns are inputs, make sure that risks come first in the calling sequence. In addition, if portfolio risks and returns are not sorted in ascending order, this method performs the sort. On output, the sorted moments are returned.

Data Types: double

(Optional) Optimal portfolios on the efficient frontier, specified as a NumAssets-by-NumPortfolios matrix.

Note

PortfolioWeights assumes that you provide valid portfolios on the efficient frontier.

Data Types: double

Name-Value Arguments

Example: [prsk,pret]=plotFrontier(p,Parent=ax)

Specify required pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Since R2024a

Axes object in which to display the efficient frontier plot, specified as an Axes object. The efficient frontier plot is displayed on the axes specified by the Parent name-value argument. If you do not specify the axes, MATLAB plots into the current axes or it creates an axes object if one does not exist. For an example of using an Axes object with plotFrontier, see Display Plot for Efficient Frontier for Portfolio and PortfolioCVaR Objects Using Axes Object.

Data Types: object

Output Arguments

collapse all

Estimated efficient portfolio risks, returned as a NumPortfolios-by-1 vector for a Portfolio, PortfolioCVaR, or PortfolioMAD input object (obj).

Estimated efficient portfolio returns, returned as a NumPortfolios-by-1 vector for a Portfolio, PortfolioCVaR, or PortfolioMAD input object (obj).

Since R2024a

Figure handle for the efficient frontier plot, returned as an array of graphics (Line or Scatter) objects. Use the elements in h to access and modify properties of the efficient frontier plot.

Note

  • If the portfolio object has a name in the Name property, the name is displayed as the title of the plot. Otherwise, the plot is labeled “Efficient Frontier.”

  • If the portfolio object has an initial portfolio in the InitPort property, the initial portfolio is plotted and labeled.

Tips

You can also use dot notation to plot the efficient frontier.

[prsk, pret] = obj.plotFrontier;

Version History

Introduced in R2011a

expand all