## Working with `'Conditional'`

`BoundType`

, `MinNumAssets`

, and
`MaxNumAssets`

Constraints Using PortfolioCVaR Objects

When any one, or any combination of `'Conditional'`

`BoundType`

, `MinNumAssets`

, or
`MaxNumAssets`

constraints are active, the portfolio problem is
formulated by adding `NumAssets`

binary variables, where
`0`

indicates not invested, and `1`

is invested.
For example, to explain the `'Conditional'`

`BoundType`

and `MinNumAssets`

and
`MaxNumAssets`

constraints, assume that your portfolio has a
universe of 100 assets that you want to invest:

`'Conditional'`

`BoundType`

(also known as semicontinuous constraints), set by`setBounds`

, is often used in situations where you do not want to invest small values. A standard example is a portfolio optimization problem where many small allocations are not attractive because of transaction costs. Instead, you prefer fewer instruments in the portfolio with larger allocations. This situation can be handled using`'Conditional'`

`BoundType`

constraints for a`PortfolioCVaR`

object.For example, the weight you invest in each asset is either

`0`

or between`[0.01, 0.5]`

. Generally, a semicontinuous variable*x*is a continuous variable between bounds [`lb`

,`ub`

] that also can assume the value`0`

, where`lb`

>`0`

,`lb`

≤`ub`

. Applying this to portfolio optimization requires that very small or large positions should be avoided, that is values that fall in (`0`

,`lb`

) or are more than`ub`

.`MinNumAssets`

and`MaxNumAssets`

(also known as cardinality constraints), set by`setMinMaxNumAssets`

, limit the number of assets in a`PortfolioCVaR`

object. For example, if you have 100 assets in your portfolio and you want the number of assets allocated in the portfolio to be from 40 through 60. Using`MinNumAssets`

and`MaxNumAssets`

you can limit the number of assets in the optimized portfolio, which allows you to limit transaction and operational costs or to create an index tracking portfolio.

### Setting `'Conditional'`

`BoundType`

Constraints Using the `setBounds`

Function

Use `setBounds`

with a
`'conditional'`

`BoundType`

to set *xi* =
`0`

or `0.02`

<= *xi* <= `0.5`

for all *i*=`1`

,...`NumAssets`

:

p = PortfolioCVaR; p = setBounds(p, 0.02, 0.5,'BoundType', 'Conditional', 'NumAssets', 3)

p = PortfolioCVaR with properties: BuyCost: [] SellCost: [] RiskFreeRate: [] ProbabilityLevel: [] Turnover: [] BuyTurnover: [] SellTurnover: [] NumScenarios: [] Name: [] NumAssets: 3 AssetList: [] InitPort: [] AInequality: [] bInequality: [] AEquality: [] bEquality: [] LowerBound: [3×1 double] UpperBound: [3×1 double] LowerBudget: [] UpperBudget: [] GroupMatrix: [] LowerGroup: [] UpperGroup: [] GroupA: [] GroupB: [] LowerRatio: [] UpperRatio: [] MinNumAssets: [] MaxNumAssets: [] BoundType: [3×1 categorical]

### Setting the Limits on the Number of Assets Invested Using the `setMinMaxNumAssets`

Function

You can also set the `MinNumAssets`

and
`MaxNumAssets`

properties to define a limit on the number of
assets invested using `setMinMaxNumAssets`

. For example, by setting
`MinNumAssets`

=`MaxNumAssets`

=`2`

,
only two of the three assets are invested in the
portfolio.

p = PortfolioCVaR; p = setBounds(p, 0.02, 0.5,'BoundType', 'Conditional', 'NumAssets', 3) p = setMinMaxNumAssets(p, 2, 2)

p = PortfolioCVaR with properties: BuyCost: [] SellCost: [] RiskFreeRate: [] ProbabilityLevel: [] Turnover: [] BuyTurnover: [] SellTurnover: [] NumScenarios: [] Name: [] NumAssets: 3 AssetList: [] InitPort: [] AInequality: [] bInequality: [] AEquality: [] bEquality: [] LowerBound: [3×1 double] UpperBound: [3×1 double] LowerBudget: [] UpperBudget: [] GroupMatrix: [] LowerGroup: [] UpperGroup: [] GroupA: [] GroupB: [] LowerRatio: [] UpperRatio: [] MinNumAssets: 2 MaxNumAssets: 2 BoundType: [3×1 categorical]

## See Also

`PortfolioCVaR`

| `setBounds`

| `setMinMaxNumAssets`

| `setDefaultConstraints`

| `setBounds`

| `setBudget`

| `setGroups`

| `setGroupRatio`

| `setEquality`

| `setInequality`

| `setTurnover`

| `setOneWayTurnover`

## Related Examples

- Creating the PortfolioCVaR Object
- Working with CVaR Portfolio Constraints Using Defaults
- Working with 'Simple' Bound Constraints Using PortfolioCVaR Object
- Troubleshooting for Setting 'Conditional' BoundType, MinNumAssets, and MaxNumAssets Constraints
- Validate the CVaR Portfolio Problem
- Estimate Efficient Portfolios for Entire Frontier for PortfolioCVaR Object
- Estimate Efficient Frontiers for PortfolioCVaR Object
- Asset Returns and Scenarios Using PortfolioCVaR Object
- Hedging Using CVaR Portfolio Optimization
- Compute Maximum Reward-to-Risk Ratio for CVaR Portfolio