# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

# setBounds

Set up bounds for portfolio weights

Use the `setBounds` function with a `Portfolio`, `PortfolioCVaR`, or `PortfolioMAD` object to set up bounds for portfolio weights for portfolio objects.

For details on the respective workflows when using these different objects, see Portfolio Object Workflow, PortfolioCVaR Object Workflow, and PortfolioMAD Object Workflow.

## Syntax

``obj = setBounds(obj,LowerBound)``
``obj = setBounds(obj,LowerBound,UpperBound,NumAssets)``

## Description

example

````obj = setBounds(obj,LowerBound)` sets up bounds for portfolio weights for portfolio objects.```

example

````obj = setBounds(obj,LowerBound,UpperBound,NumAssets)` sets up bounds for portfolio weights for portfolio objects with additional options for `UpperBound` and `NumAssets`.Given bound constraints `LowerBound` and `UpperBound`, every weight in a portfolio `Port` must satisfy the following: LowerBound <= Port <= UpperBound ```

## Examples

collapse all

Suppose you have a balanced fund with stocks that can range from 50% to 75% of your portfolio and bonds that can range from 25% to 50% of your portfolio. To set the bound constraints for a balanced fund.

```lb = [ 0.5; 0.25 ]; ub = [ 0.75; 0.5 ]; p = Portfolio; p = setBounds(p, lb, ub); disp(p.NumAssets);```
``` 2 ```
`disp(p.LowerBound);`
``` 0.5000 0.2500 ```
`disp(p.UpperBound);`
``` 0.7500 0.5000 ```

Suppose you have a balanced fund with stocks that can range from 50% to 75% of your portfolio and bonds that can range from 25% to 50% of your portfolio. To set the bound constraints for a balanced fund.

```lb = [ 0.5; 0.25 ]; ub = [ 0.75; 0.5 ]; p = PortfolioCVaR; p = setBounds(p, lb, ub); disp(p.NumAssets);```
``` 2 ```
`disp(p.LowerBound);`
``` 0.5000 0.2500 ```
`disp(p.UpperBound);`
``` 0.7500 0.5000 ```

Suppose you have a balanced fund with stocks that can range from 50% to 75% of your portfolio and bonds that can range from 25% to 50% of your portfolio. To set the bound constraints for a balanced fund.

```lb = [ 0.5; 0.25 ]; ub = [ 0.75; 0.5 ]; p = PortfolioMAD; p = setBounds(p, lb, ub); disp(p.NumAssets);```
``` 2 ```
`disp(p.LowerBound);`
``` 0.5000 0.2500 ```
`disp(p.UpperBound);`
``` 0.7500 0.5000 ```

## Input Arguments

collapse all

Object for portfolio, specified using `Portfolio`, `PortfolioCVaR`, or `PortfolioMAD` object. For more information on creating a portfolio object, see

Lower-bound weight for each asset, specified as a vector for a `Portfolio`, `PortfolioCVaR`, or `PortfolioMAD` input object (`obj`).

### Note

• If either `LowerBound` or `UpperBound` are input as empties with `[]`, the corresponding attributes in the portfolio object are cleared and set to `[]`.

• If `LowerBound` or `UpperBound` are specified as scalars and `NumAssets` exists or can be imputed, then they undergo scalar expansion. The default value for `NumAssets` is `1`.

• If both `LowerBound` and `UpperBound` exist and they are not ordered correctly, the `setBounds` function switches bounds if necessary.

Data Types: `double`

Upper-bound weight for each asset, specified as a vector for a `Portfolio`, `PortfolioCVaR`, or `PortfolioMAD` input object (`obj`).

### Note

• If either `LowerBound` or `UpperBound` are input as empties with `[]`, the corresponding attributes in the portfolio object are cleared and set to `[]`.

• If `LowerBound` or `UpperBound` are specified as scalars and `NumAssets` exists or can be imputed, then they undergo scalar expansion. The default value for `NumAssets` is `1`.

• If both `LowerBound` and `UpperBound` exist and they are not ordered correctly, the `setBounds` function switches bounds if necessary.

Data Types: `double`

Number of assets in portfolio, specified as a scalar for a `Portfolio`, `PortfolioCVaR`, or `PortfolioMAD` input object (`obj`).

### Note

`NumAssets` cannot be used to change the dimension of a portfolio object.

• If either `LowerBound` or `UpperBound` are input as empties with `[]`, the corresponding attributes in the portfolio object are cleared and set to `[]`.

• If `LowerBound` or `UpperBound` are specified as scalars and `NumAssets` exists or can be imputed, then they undergo scalar expansion. The default value for `NumAssets` is `1`.

• If both `LowerBound` and `UpperBound` exist and they are not ordered correctly, the `setBounds` function switches bounds if necessary.

Data Types: `double`

## Output Arguments

collapse all

Updated portfolio object, returned as a `Portfolio`, `PortfolioCVaR`, or `PortfolioMAD` object. For more information on creating a portfolio object, see

## Tips

You can also use dot notation to set up the bounds for portfolio weights.

` obj = obj.setBounds(LowerBound, UpperBound, NumAssets);`