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

`frontcon`

, 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.AssetBounds = [-0.10, -0.10, -0.10; 1.10, 1.10, 1.10];

Constraint 2 needs to 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 1s and 0s 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

`frontcon`

to obtain the vectors and arrays representing the risk, return, and weights for each of the eight portfolios computed along the efficient frontier.[PortRisk, PortReturn, PortWts] = frontcon(ExpReturn,... ExpCovariance, NumPorts, [], AssetBounds, Groups, GroupBounds)

Warning: In a future release, frontcon will be removed. Use the Portfolio object instead. See the release notes for details, including examples to make the conversion. > In frontcon at 89 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.2582 0.0418 0.6031 0.3244 0.0725 0.4864 0.3708 0.1428 0.3696 0.4172 0.2132 0.2529 0.4636 0.2835 0.2000 0.5738 0.2262 0.2000 0.7369 0.0631 0.2000 0.9000 -0.1000

The output data is represented row-wise, where each portfolio's risk, rate of return, and associated weight is identified as corresponding rows in the vectors and matrix.

While `frontcon`

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. The function `portopt`

addresses
this need, by accepting an arbitrary set of constraints as an input
matrix.

The auxiliary function `portcons`

can
be used to create the matrix of constraints, with each row representing
an inequality. These inequalities are of the type ```
A*Wts'
<= b
```

, where `A`

is a matrix, `b`

is
a vector, and `Wts`

is a row vector of asset allocations.
The number of columns of the matrix `A`

, and the
length of the vector `Wts`

correspond to the number
of assets. The number of rows of the matrix `A`

,
and the length of vector `b`

correspond to the number
of constraints. This method allows you to specify any number of linear
inequalities to the function `portopt`

.

In actuality, `portcons`

is an entry
point to a set of functions that generate matrices for specific types
of constraints. `portcons`

allows you to specify
all the constraints data at once, while the specific portfolio constraint
functions allow you to build the constraints incrementally. These
constraint functions are `pcpval`

, `pcalims`

, `pcglims`

,
and `pcgcomp`

.

Consider an example to help understand how to specify constraints
to `portopt`

while bypassing
the use of `portcons`

. 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 |

Note that 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 need to 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]

Build the constraint matrix `ConSet`

by concatenating the matrix `A`

to
the vector `b`

.

ConSet = [A, b]

The example above defined a constraints matrix that specified
a set of typical scenarios. It defined groups of assets, specified
upper and lower bounds for total allocation in each of these groups,
and it set the total allocation of one of the groups to a fixed value.
Constraints like these are common occurrences. The function `portcons`

was created to simplify the
creation of the constraint matrix for these and other common portfolio
requirements. `portcons`

takes as input arguments
a list of constraint-specifier strings, followed by the data necessary
to build the constraint specified by the strings.

Assume that you need to add more constraints to the previous example. Specifically, add a constraint indicating that the sum of weights in any portfolio should be equal to 1, and another set of constraints (one per asset) indicating that the weight for each asset must greater than 0. This translates into five more constraint rows: two for the new equality, and three indicating that each weight must be greater or equal to 0. The total number of inequalities in the example is now 13. Clearly, creating the constraint matrix can turn into a tedious task.

To create the new constraint matrix using `portcons`

,
use two separate constraint-specifier strings:

`'Default'`

, which indicates that each weight is greater than 0 and that the total sum of the weights adds to 1`'GroupLims'`

, which defines the minimum and maximum allocation on each group

The only data requirement for the constraint-specifier string `'Default'`

is `NumAssets`

(the
total number of assets). The constraint-specifier string `'GroupLims'`

requires
three different arguments: a `Groups`

matrix indicating
the assets that belong to each group, the `GroupMin`

vector
indicating the minimum bounds for each group, and the `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];

Given that the number of assets is three, build the constraint
matrix by calling `portcons`

.

ConSet = portcons('Default', 3, 'GroupLims', Group, GroupMin,... GroupMax);

In most cases, `portcons('Default')`

returns
the minimal set of constraints required for calling `portopt`

. If `ConSet`

is
not specified in the call to `portopt`

, the function
calls `portcons`

passing `'Default'`

as
its only specifier.

Now use `portopt`

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

[PortRisk, PortReturn, PortWts] = portopt(ExpReturn,... ExpCovariance, [], [], ConSet)

Warning: In a future release, portopt will no longer accept ConSet or varargin arguments. 'It will only solve the portfolio problem for long-only fully-invested portfolios. To solve more general problems, use the Portfolio object. See the release notes for details, including examples to make the conversion. > In portopt at 83 In frontcon at 231 PortRisk = 0.0586 Port Return = 0.1375 PortWts = 0.5 0.25 0.25

In this case, the constraints allow only one optimum portfolio.

`abs2active`

| `active2abs`

| `frontcon`

| `frontier`

| `pcalims`

| `pcgcomp`

| `pcglims`

| `pcpval`

| `portalloc`

| `portcons`

| `Portfolio`

| `portopt`

| `portvrisk`

- Portfolio Optimization Functions
- Portfolio Selection and Risk Aversion
- Active Returns and Tracking Error Efficient Frontier
- Plotting an Efficient Frontier
- Turning off the Warning Messages for portopt
- Turning off the Warning Messages for frontcon
- portopt Migration to Portfolio Object
- frontcon Migration to Portfolio Object

Was this topic helpful?