## Working with Linear Equality Constraints Using Portfolio Object

Linear equality constraints are optional linear constraints
that impose systems of equalities on portfolio weights (see Linear Equality Constraints). Linear equality
constraints have properties `AEquality`

, for the
equality constraint matrix, and `bEquality`

, for
the equality constraint vector.

### Setting Linear Equality Constraints Using the `Portfolio`

Function

The properties for linear equality constraints are set using the `Portfolio`

object. Suppose that you
have a portfolio of five assets and want to ensure that the first three assets are
50% of your portfolio. To set this constraint:

A = [ 1 1 1 0 0 ]; b = 0.5; p = Portfolio('AEquality', A, 'bEquality', b); disp(p.NumAssets) disp(p.AEquality) disp(p.bEquality)

5 1 1 1 0 0 0.5000

### Setting Linear Equality Constraints Using the `setEquality`

and `addEquality`

Functions

You can also set the properties for linear equality constraints using `setEquality`

. Suppose that you have
a portfolio of five assets and want to ensure that the first three assets are 50% of
your portfolio. Given a `Portfolio`

object `p`

,
use `setEquality`

to set the linear
equality constraints:

A = [ 1 1 1 0 0 ]; b = 0.5; p = Portfolio; p = setEquality(p, A, b); disp(p.NumAssets) disp(p.AEquality) disp(p.bEquality)

5 1 1 1 0 0 0.5000

Suppose that you want to add another linear equality constraint to ensure that the last three
assets also constitute 50% of your portfolio. You can set up an augmented system of
linear equalities or use `addEquality`

to build up linear
equality constraints. For this example, create another system of
equalities:

p = Portfolio; A = [ 1 1 1 0 0 ]; % first equality constraint b = 0.5; p = setEquality(p, A, b); A = [ 0 0 1 1 1 ]; % second equality constraint b = 0.5; p = addEquality(p, A, b); disp(p.NumAssets) disp(p.AEquality) disp(p.bEquality)

5 1 1 1 0 0 0 0 1 1 1 0.5000 0.5000

The `Portfolio`

object, `setEquality`

, and `addEquality`

implement scalar
expansion on the `bEquality`

property based on the dimension of the
matrix in the `AEquality`

property.

## See Also

`Portfolio`

| `setDefaultConstraints`

| `setBounds`

| `setBudget`

| `setGroups`

| `setGroupRatio`

| `setEquality`

| `setInequality`

| `setTurnover`

| `setOneWayTurnover`

| `setTrackingPort`

| `setTrackingError`

## Related Examples

- Creating the Portfolio Object
- Working with Portfolio Constraints Using Defaults
- Validate the Portfolio Problem for Portfolio Object
- Estimate Efficient Portfolios for Entire Efficient Frontier for Portfolio Object
- Estimate Efficient Frontiers for Portfolio Object
- Constraint Specification Using a Portfolio Object
- Asset Allocation Case Study
- Portfolio Optimization Examples Using Financial Toolbox
- Portfolio Optimization with Semicontinuous and Cardinality Constraints
- Black-Litterman Portfolio Optimization Using Financial Toolbox
- Portfolio Optimization Using Factor Models
- Portfolio Optimization Using Social Performance Measure
- Diversify Portfolios Using Custom Objective

## More About

- Portfolio Object
- Portfolio Optimization Theory
- Portfolio Object Workflow
- Setting Up a Tracking Portfolio