Accelerating the pace of engineering and science

# Documentation Center

• Trials
• Product Updates

## Mean-Variance Efficient Frontier

Financial Toolbox™ Graphics Example 1

This example plots the efficient frontier of a hypothetical portfolio of three assets. It illustrates how to specify the expected returns, standard deviations, and correlations of a portfolio of assets, how to convert standard deviations and correlations into a covariance matrix, and how to compute and plot the efficient frontier from the returns and covariance matrix. The example also illustrates how to randomly generate a set of portfolio weights, and how to add the random portfolios to an existing plot for comparison with the efficient frontier.

Set Up

```if ~exist('quadprog')
msgbox('The Optimization Toolbox(TM) is required to run this example.','Product dependency')
return
end
```

Construct Hypothetical 3-Asset Universe

Specify the expected returns, standard deviations, and correlation matrix for a hypothetical 3-asset portfolio.

```returns      = [0.1 0.15 0.12];
STDs         = [0.2 0.25 0.18];
correlations = [ 1   0.3  0.4
0.3   1   0.3
0.4  0.3   1 ];

% Convert to variance-covariance matrix
% Convert the standard deviations and correlation

covariances = corr2cov(STDs , correlations);
```

Calculate Efficient Frontier

Compute and plot the efficient frontier for 20 portfolios along the frontier.

```portopt(returns , covariances , 20)
```

Randomize Asset Weights

Randomly generate the asset weights of 1000 portfolios uniformly distributed on the set of portfolios.

```weights = exprnd(1,1000,3);

total   =  sum(weights , 2);
total   =  total(:,ones(3,1));

weights =  weights./total;
```

Compute Expected Portfolio Returns / Risks

Compute the expected return and risk of each portfolio.

```[portRisk , portReturn] = portstats(returns , covariances , weights);
```

Compare Risk-Return Results with Efficient Frontier

Now plot the returns and risks of each portfolio on top of the existing efficient frontier for comparison.

```hold on
plot(portRisk , portReturn , '.r')
title('Mean-Variance Efficient Frontier and Random Portfolios')
hold off
```

Was this topic helpful?