getGroups

Obtain group constraint arrays from portfolio object

Syntax

``````[GroupMatrix,LowerGroup,UpperGroup] = getGroups(obj)``````

Description

Use the `getGroups` function with a `Portfolio`, `PortfolioCVaR`, or `PortfolioMAD` object to obtain group constraint arrays from portfolio objects.

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

example

``````[GroupMatrix,LowerGroup,UpperGroup] = getGroups(obj)``` obtains group constraint arrays from portfolio objects.```

Examples

collapse all

Suppose you have a portfolio of five assets and you want to ensure that the first three assets constitute no more than 30% of your portfolio. Given a Portfolio object `p` with the group constraints set, obtain the values for `GroupMatrix`, `LowerGroup`, and `UpperGroup`.

```G = [ true true true false false ]; p = Portfolio; p = setGroups(p, G, [], 0.3); [GroupMatrix, LowerGroup, UpperGroup] = getGroups(p)```
```GroupMatrix = 1×5 1 1 1 0 0 ```
```LowerGroup = [] ```
```UpperGroup = 0.3000 ```

Suppose you have a portfolio of five assets and you want to ensure that the first three assets constitute at most 30% of your portfolio. Given a PortfolioCVaR object `p` with the group constraints set, obtain the values for `GroupMatrix`, `LowerGroup`, and `UpperGroup`.

```G = [ true true true false false ]; p = PortfolioCVaR; p = setGroups(p, G, [], 0.3); [GroupMatrix, LowerGroup, UpperGroup] = getGroups(p)```
```GroupMatrix = 1×5 1 1 1 0 0 ```
```LowerGroup = [] ```
```UpperGroup = 0.3000 ```

Suppose you have a portfolio of five assets and you want to ensure that the first three assets constitute at most 30% of your portfolio. Given a PortfolioMAD object `p` with the group constraints set, obtain the values for `GroupMatrix`, `LowerGroup`, and `UpperGroup`.

```G = [ true true true false false ]; p = PortfolioMAD; p = setGroups(p, G, [], 0.3); [GroupMatrix, LowerGroup, UpperGroup] = getGroups(p)```
```GroupMatrix = 1×5 1 1 1 0 0 ```
```LowerGroup = [] ```
```UpperGroup = 0.3000 ```

Input Arguments

collapse all

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

Data Types: `object`

Output Arguments

collapse all

Group constraint matrix, returned as a matrix for a `Portfolio`, `PortfolioCVaR`, or `PortfolioMAD` input object (`obj`).

Lower bound for group constraints, returned as a vector for a `Portfolio`, `PortfolioCVaR`, or `PortfolioMAD` input object (`obj`).

Upper bound for group constraints, returned as a vector for a `Portfolio`, `PortfolioCVaR`, or `PortfolioMAD` input object (`obj`).

Tips

You can also use dot notation to obtain the group constraint arrays from portfolio objects.

`[GroupMatrix, LowerGroup, UpperGroup] = obj.getGroups;`

Version History

Introduced in R2011a