Note: This page has been translated by MathWorks. Click here to see

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

This example computes the efficient frontier of portfolios consisting of three different assets, INTC, XON, and RD, given a list of constraints. The expected returns for INTC, XON, and RD are respectively as follows:

ExpReturn = [0.1 0.2 0.15];

The covariance matrix is

ExpCovariance = [ 0.005 -0.010 0.004; -0.010 0.040 -0.002; 0.004 -0.002 0.023];

Constraint 1

Allow short selling up to 10% of the portfolio value in any asset, but limit the investment in any one asset to 110% of the portfolio value.

Constraint 2

Consider two different sectors, technology and energy, with the following table indicating the sector each asset belongs to.

**Asset**INTC

XON

RD

**Sector**Technology

Energy

Energy

Constrain the investment in the Energy sector to 80% of the portfolio value, and the investment in the Technology sector to 70%.

To solve this problem, use

`Portfolio`

, passing in a list of asset constraints. Consider eight different portfolios along the efficient frontier:NumPorts = 8;

To introduce the asset bounds constraints specified in Constraint 1, create the matrix

`AssetBounds`

, where each column represents an asset. The upper row represents the lower bounds, and the lower row represents the upper bounds. Since the bounds are the same for each asset, only one pair of bounds is needed because of scalar expansion.AssetBounds = [-0.1, 1.1];

Constraint 2 must be entered in two parts, the first part defining the groups, and the second part defining the constraints for each group. Given the information above, you can build a matrix of

`1`

s and`0`

s indicating whether a specific asset belongs to a group. Each column represents an asset, and each row represents a group. This example has two groups: the technology group, and the energy group. Create the matrix`Groups`

as follows.Groups = [0 1 1; 1 0 0];

The

`GroupBounds`

matrix allows you to specify an upper and lower bound for each group. Each row in this matrix represents a group. The first column represents the minimum allocation, and the second column represents the maximum allocation to each group. Since the investment in the Energy sector is capped at 80% of the portfolio value, and the investment in the Technology sector is capped at 70%, create the`GroupBounds`

matrix using this information.GroupBounds = [0 0.80; 0 0.70];

Now use

`Portfolio`

to obtain the vectors and arrays representing the risk, return, and weights for each of the eight portfolios computed along the efficient frontier. A budget constraint is added to ensure that the portfolio weights sum to 1.p = Portfolio('AssetMean', ExpReturn, 'AssetCovar', ExpCovariance); p = setBounds(p, AssetBounds(1), AssetBounds(2)); p = setBudget(p, 1, 1); p = setGroups(p, Groups, GroupBounds(:,1), GroupBounds(:,2)); PortWts = estimateFrontier(p, NumPorts); [PortRisk, PortReturn] = estimatePortMoments(p, PortWts); PortRisk PortReturn PortWts

PortRisk = 0.0416 0.0499 0.0624 0.0767 0.0920 0.1100 0.1378 0.1716 PortReturn = 0.1279 0.1361 0.1442 0.1524 0.1605 0.1687 0.1768 0.1850 PortWts = 0.7000 0.6031 0.4864 0.3696 0.2529 0.2000 0.2000 0.2000 0.2582 0.3244 0.3708 0.4172 0.4636 0.5738 0.7369 0.9000 0.0418 0.0725 0.1428 0.2132 0.2835 0.2262 0.0631 -0.1000

The outputs are represented as columns for the portfolio’s risk and return. Portfolio weights are identified as corresponding column vectors in a matrix.

While the `Portfolio`

object allows you to enter
a fixed set of constraints related to minimum and maximum values for groups and
individual assets, you often need to specify a larger and more general set of
constraints when finding the optimal risky portfolio. `Portfolio`

also addresses this need,
by accepting an arbitrary set of constraints.

This example requires specifying the minimum and maximum investment in various groups.

**Maximum and Minimum Group Exposure**

Group | Minimum Exposure | Maximum Exposure |
---|---|---|

North America | 0.30 | 0.75 |

Europe | 0.10 | 0.55 |

Latin America | 0.20 | 0.50 |

Asia | 0.50 | 0.50 |

The minimum and maximum exposure in Asia is the same. This means that you require a fixed exposure for this group.

Also assume that the portfolio consists of three different funds. The correspondence between funds and groups is shown in the table below.

**Group Membership**

Group | Fund 1 | Fund 2 | Fund 3 |
---|---|---|---|

North America | X | X | |

Europe | X | ||

Latin America | X | ||

Asia | X | X |

Using the information in these two tables, build a mathematical
representation of the constraints represented. Assume that the vector
of weights representing the exposure of each asset in a portfolio
is called ```
Wts = [W1 W2
W3]
```

.

Specifically

1. |
| ≥ | 0.30 |

2. |
| ≤ | 0.75 |

3. |
| ≥ | 0.10 |

4. |
| ≤ | 0.55 |

5. |
| ≥ | 0.20 |

6. |
| ≤ | 0.50 |

7. |
| = | 0.50 |

Since you must represent the information in the form ```
A*Wts
<= b
```

, multiply equations 1, 3 and 5 by –1. Also
turn equation 7 into a set of two inequalities: *W*2
+ *W*3 ≥ 0.50 and *W*2
+ *W*3 ≤ 0.50. (The intersection of these
two inequalities is the equality itself.) Thus

1. |
| ≤ | -0.30 |

2. |
| ≤ | 0.75 |

3. |
| ≤ | -0.10 |

4. |
| ≤ | 0.55 |

5. |
| ≤ | -0.20 |

6. |
| ≤ | 0.50 |

7. |
| ≤ | -0.50 |

8. |
| ≤ | 0.50 |

Bringing these equations into matrix notation gives

A = [-1 -1 0; 1 1 0; 0 0 -1; 0 0 1; -1 0 0; 1 0 0; 0 -1 -1; 0 1 1] b = [-0.30; 0.75; -0.10; 0.55; -0.20; 0.50; -0.50; 0.50]

One approach to solving this portfolio problem is to explicitly
use the `setInequality`

function:

p = Portfolio('AssetMean', ExpReturn, 'AssetCovar', ExpCovariance); p = setBounds(p, AssetBounds(1), AssetBounds(2)); p = setBudget(p, 1, 1); p = setInequality(p, A, b); PortWts = estimateFrontier(p, NumPorts); [PortRisk, PortReturn] = estimatePortMoments(p, PortWts); PortRisk PortReturn PortWts

PortRisk = 0.0586 0.0586 0.0586 0.0586 0.0586 0.0586 0.0586 0.0586 PortReturn = 0.1375 0.1375 0.1375 0.1375 0.1375 0.1375 0.1375 0.1375 PortWts = 0.5000 0.5000 0.5000 0.5000 0.5000 0.5000 0.5000 0.5000 0.2500 0.2500 0.2500 0.2500 0.2500 0.2500 0.2500 0.2500 0.2500 0.2500 0.2500 0.2500 0.2500 0.2500 0.2500 0.2500

`setInequality`

function
is the same as using the `setGroups`

function
in the next example (Specifying Group Constraints).The example above (Linear Constraint Equations) defines a constraint
matrix that specifies a set of typical scenarios. It defines groups of assets,
specifies upper and lower bounds for total allocation in each of these groups, and
it sets the total allocation of one group to a fixed value. Constraints like these
are common occurrences. `Portfolio`

object enables you to
simplify the creation of the constraint matrix for these and other common portfolio
requirements.

An alternative approach for solving the portfolio problem is to use the `Portfolio`

object to define:

A

`Group`

matrix, indicating the assets that belong to each group.A

`GroupMin`

vector, indicating the minimum bounds for each group.A

`GroupMax`

vector, indicating the maximum bounds for each group.

Based on the table Group Membership, build the `Group`

matrix, with each
row representing a group, and each column representing an asset.

Group = [1 1 0; 0 0 1; 1 0 0; 0 1 1];

The table Maximum and Minimum Group Exposure has the information to
build `GroupMin`

and `GroupMax`

.

GroupMin = [0.30 0.10 0.20 0.50]; GroupMax = [0.75 0.55 0.50 0.50];

Now use `Portfolio`

and the `setInequality`

function to obtain
the vectors and arrays representing the risk, return, and weights for the portfolios
computed along the efficient frontier.

p = Portfolio('AssetMean', ExpReturn, 'AssetCovar', ExpCovariance); p = setBounds(p, AssetBounds(1), AssetBounds(2)); p = setBudget(p, 1, 1); p = setGroups(p, Group, GroupMin, GroupMax); PortWts = estimateFrontier(p, NumPorts); [PortRisk, PortReturn] = estimatePortMoments(p, PortWts); PortRisk PortReturn PortWts

PortRisk = 0.0586 0.0586 0.0586 0.0586 0.0586 0.0586 0.0586 0.0586 PortReturn = 0.1375 0.1375 0.1375 0.1375 0.1375 0.1375 0.1375 0.1375 PortWts = 0.5000 0.5000 0.5000 0.5000 0.5000 0.5000 0.5000 0.5000 0.2500 0.2500 0.2500 0.2500 0.2500 0.2500 0.2500 0.2500 0.2500 0.2500 0.2500 0.2500 0.2500 0.2500 0.2500 0.2500

In this case, the constraints allow only one optimum portfolio.
Since eight portfolios were requested, all eight portfolios are the
same. Note that the solution to this portfolio problem using the `setGroups`

function is the same as using
the `setInequality`

function
in the previous example (Linear Constraint Equations).

`Portfolio`

| `estimateFrontier`

| `estimatePortMoments`

| `setGroups`

| `setInequality`

- Setting Default Constraints for Portfolio Weights Using Portfolio Object
- Working with 'Simple' Bound Constraints Using Portfolio Object
- Working with Budget Constraints Using Portfolio Object
- Working with Group Constraints Using Portfolio Object
- Working with Group Ratio Constraints Using Portfolio Object
- Working with Linear Equality Constraints Using Portfolio Object
- Working with Linear Inequality Constraints Using Portfolio Object
- Working with Average Turnover Constraints Using Portfolio Object
- Working with One-Way Turnover Constraints Using Portfolio Object
- Working with Tracking Error Constraints Using Portfolio Object
- Asset Allocation Case Study
- Portfolio Optimization Examples