# estimateFrontierByRisk

Estimate optimal portfolios with targeted portfolio risks

## Syntax

``````[pwgt,pbuy,psell] = estimateFrontierByRisk(obj,TargetRisk)``````
``````[pwgt,pbuy,psell] = estimateFrontierByRisk(___,Name,Value)``````

## Description

example

``````[pwgt,pbuy,psell] = estimateFrontierByRisk(obj,TargetRisk)``` estimates optimal portfolios with targeted portfolio risks for `Portfolio`, `PortfolioCVaR`, or `PortfolioMAD` objects. For details on the respective workflows when using these different objects, see Portfolio Object Workflow, PortfolioCVaR Object Workflow, and PortfolioMAD Object Workflow.```

example

``````[pwgt,pbuy,psell] = estimateFrontierByRisk(___,Name,Value)``` adds name-optional name-value pair arguments for `Portfolio` or `PortfolioMAD` objects. ```

## Examples

collapse all

To obtain efficient portfolios that have targeted portfolio risks, the `estimateFrontierByRisk` function accepts one or more target portfolio risks and obtains efficient portfolios with the specified risks. Assume you have a universe of four assets where you want to obtain efficient portfolios with target portfolio risks of 12%, 14%, and 16%. This example uses the default `'direct'` method to estimate the optimal portfolios with targeted portfolio risks.

```m = [ 0.05; 0.1; 0.12; 0.18 ]; C = [ 0.0064 0.00408 0.00192 0; 0.00408 0.0289 0.0204 0.0119; 0.00192 0.0204 0.0576 0.0336; 0 0.0119 0.0336 0.1225 ]; p = Portfolio; p = setAssetMoments(p, m, C); p = setDefaultConstraints(p); pwgt = estimateFrontierByRisk(p, [0.12, 0.14, 0.16]); display(pwgt);```
```pwgt = 4×3 0.3984 0.2659 0.1416 0.3064 0.3791 0.4474 0.0882 0.1010 0.1131 0.2071 0.2540 0.2979 ```

When any one, or any combination of the constraints from '`Conditional'` `BoundType`, `MinNumAssets`, and `MaxNumAssets` are active, the portfolio problem is formulated as mixed integer programming problem and the MINLP solver is used.

Create a `Portfolio` object for three assets.

```AssetMean = [ 0.0101110; 0.0043532; 0.0137058 ]; AssetCovar = [ 0.00324625 0.00022983 0.00420395; 0.00022983 0.00049937 0.00019247; 0.00420395 0.00019247 0.00764097 ]; p = Portfolio('AssetMean', AssetMean, 'AssetCovar', AssetCovar); p = setDefaultConstraints(p); ```

Use `setBounds` with semicontinuous constraints to set xi = `0` or `0.02` <= `xi` <= `0.5` for all i = `1`,...`NumAssets`.

`p = setBounds(p, 0.02, 0.7,'BoundType', 'Conditional', 'NumAssets', 3); `

When working with a `Portfolio` object, the `setMinMaxNumAssets` function enables you to set up the limits on the number of assets invested (as known as cardinality) constraints. This sets the total number of allocated assets satisfying the Bound constraints that are between `MinNumAssets` and `MaxNumAssets`. By setting `MinNumAssets` = `MaxNumAssets` = 2, only two of the three assets are invested in the portfolio.

`p = setMinMaxNumAssets(p, 2, 2); `

Use `estimateFrontierByRisk` to estimate optimal portfolios with targeted portfolio risks.

`[pwgt, pbuy, psell] = estimateFrontierByRisk(p,[0.0324241, 0.0694534 ])`
```pwgt = 3×2 0.0000 0.5000 0.6907 0 0.3093 0.5000 ```
```pbuy = 3×2 0.0000 0.5000 0.6907 0 0.3093 0.5000 ```
```psell = 3×2 0 0 0 0 0 0 ```

The `estimateFrontierByRisk` function uses the MINLP solver to solve this problem. Use the `setSolverMINLP` function to configure the `SolverType` and options.

`p.solverTypeMINLP`
```ans = 'OuterApproximation' ```
`p.solverOptionsMINLP`
```ans = struct with fields: MaxIterations: 1000 AbsoluteGapTolerance: 1.0000e-07 RelativeGapTolerance: 1.0000e-05 NonlinearScalingFactor: 1000 ObjectiveScalingFactor: 1000 Display: 'off' CutGeneration: 'basic' MaxIterationsInactiveCut: 30 ActiveCutTolerance: 1.0000e-07 IntMasterSolverOptions: [1x1 optim.options.Intlinprog] NumIterationsEarlyIntegerConvergence: 30 ```

To obtain efficient portfolios that have targeted portfolio risks, the `estimateFrontierByRisk` function accepts one or more target portfolio risks and obtains efficient portfolios with the specified risks. Assume you have a universe of four assets where you want to obtain efficient portfolios with target portfolio risks of 12%, 14%, and 16%. This example uses the default`'direct'` method to estimate the optimal portfolios with targeted portfolio risks. The `'direct'` method uses `fmincon` to solve the optimization problem that maximizes portfolio return, subject to the target risk as the quadratic nonlinear constraint. `setSolver` specifies the s`olverType` and `SolverOptions` for `fmincon``.`

```m = [ 0.05; 0.1; 0.12; 0.18 ]; C = [ 0.0064 0.00408 0.00192 0; 0.00408 0.0289 0.0204 0.0119; 0.00192 0.0204 0.0576 0.0336; 0 0.0119 0.0336 0.1225 ]; p = Portfolio; p = setAssetMoments(p, m, C); p = setDefaultConstraints(p); p = setSolver(p, 'fmincon', 'Display', 'off', 'Algorithm', 'sqp', ... 'SpecifyObjectiveGradient', true, 'SpecifyConstraintGradient', true, ... 'ConstraintTolerance', 1.0e-8, 'OptimalityTolerance', 1.0e-8, 'StepTolerance', 1.0e-8); pwgt = estimateFrontierByRisk(p, [0.12, 0.14, 0.16]); display(pwgt);```
```pwgt = 4×3 0.3984 0.2659 0.1416 0.3064 0.3791 0.4474 0.0882 0.1010 0.1131 0.2071 0.2540 0.2979 ```

To obtain efficient portfolios that have targeted portfolio risks, the `estimateFrontierByRisk` function accepts one or more target portfolio risks and obtains efficient portfolios with the specified risks. Assume you have a universe of four assets where you want to obtain efficient portfolios with target portfolio risks of 12%, 20%, and 30%.

```m = [ 0.05; 0.1; 0.12; 0.18 ]; C = [ 0.0064 0.00408 0.00192 0; 0.00408 0.0289 0.0204 0.0119; 0.00192 0.0204 0.0576 0.0336; 0 0.0119 0.0336 0.1225 ]; rng(11); p = PortfolioCVaR; p = simulateNormalScenariosByMoments(p, m, C, 2000); p = setDefaultConstraints(p); p = setProbabilityLevel(p, 0.95); pwgt = estimateFrontierByRisk(p, [0.12, 0.20, 0.30]); display(pwgt);```
```pwgt = 4×3 0.5363 0.1387 0 0.2655 0.4991 0.3830 0.0570 0.1239 0.1461 0.1412 0.2382 0.4709 ```

The function `rng`($seed$) resets the random number generator to produce the documented results. It is not necessary to reset the random number generator to simulate scenarios.

To obtain efficient portfolios that have targeted portfolio risks, the `estimateFrontierByRisk` function accepts one or more target portfolio risks and obtains efficient portfolios with the specified risks. Assume you have a universe of four assets where you want to obtain efficient portfolios with target portfolio risks of 12%, 20%, and 25%. This example uses the default `'direct'` method to estimate the optimal portfolios with targeted portfolio risks.

```m = [ 0.05; 0.1; 0.12; 0.18 ]; C = [ 0.0064 0.00408 0.00192 0; 0.00408 0.0289 0.0204 0.0119; 0.00192 0.0204 0.0576 0.0336; 0 0.0119 0.0336 0.1225 ]; rng(11); p = PortfolioMAD; p = simulateNormalScenariosByMoments(p, m, C, 2000); p = setDefaultConstraints(p); pwgt = estimateFrontierByRisk(p, [0.12, 0.20, 0.25]); display(pwgt);```
```pwgt = 4×3 0.1610 0 0 0.4784 0.2137 0.0047 0.1116 0.1384 0.1200 0.2490 0.6480 0.8753 ```

The function `rng`($seed$) resets the random number generator to produce the documented results. It is not necessary to reset the random number generator to simulate scenarios.

To obtain efficient portfolios that have targeted portfolio risks, the `estimateFrontierByRisk` function accepts one or more target portfolio risks and obtains efficient portfolios with the specified risks. Assume you have a universe of four assets where you want to obtain efficient portfolios with target portfolio risks of 12%, 20%, and 25%. This example uses the default `'direct'` method to estimate the optimal portfolios with targeted portfolio risks. The `'direct'` method uses `fmincon` to solve the optimization problem that maximizes portfolio return, subject to the target risk as the quadratic nonlinear constraint. `setSolver` specifies the s`olverType` and `SolverOptions` for `fmincon``.`

```m = [ 0.05; 0.1; 0.12; 0.18 ]; C = [ 0.0064 0.00408 0.00192 0; 0.00408 0.0289 0.0204 0.0119; 0.00192 0.0204 0.0576 0.0336; 0 0.0119 0.0336 0.1225 ]; rng(11); p = PortfolioMAD; p = simulateNormalScenariosByMoments(p, m, C, 2000); p = setDefaultConstraints(p); p = setSolver(p, 'fmincon', 'Display', 'off', 'Algorithm', 'sqp', ... 'SpecifyObjectiveGradient', true, 'SpecifyConstraintGradient', true, ... 'ConstraintTolerance', 1.0e-8, 'OptimalityTolerance', 1.0e-8, 'StepTolerance', 1.0e-8); plotFrontier(p);```

```pwgt = estimateFrontierByRisk(p, [0.12 0.20, 0.25]); display(pwgt);```
```pwgt = 4×3 0.1613 0.0000 -0.0000 0.4777 0.2139 0.0037 0.1118 0.1381 0.1214 0.2492 0.6480 0.8749 ```

## Input Arguments

collapse all

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

Note

If no initial portfolio is specified in `obj.InitPort`, it is assumed to be `0` so that ```pbuy = max(0,pwgt)``` and ```psell = max(0,-pwgt)```. For more information on setting an initial portfolio, see `setInitPort`.

Data Types: `object`

Target values for portfolio risk, specified as a `NumPorts` vector.

Note

If any `TargetRisk` values are outside the range of risks for efficient portfolios, the target risk is replaced with the minimum or maximum efficient portfolio risk, depending on whether the target risk is below or above the range of efficient portfolio risks.

Data Types: `double`

### Name-Value Pair Arguments

Specify optional comma-separated pairs of `Name,Value` arguments. `Name` is the argument name and `Value` is the corresponding value. `Name` must appear inside quotes. You can specify several name and value pair arguments in any order as `Name1,Value1,...,NameN,ValueN`.

Example: ```[pwgt,pbuy,psell] = estimateFrontierByRisk(p,‘method’,‘direct’)```

Method to estimate frontier by risk for `Portfolio` or `PortfolioMAD` objects, specified as the comma-separated pair consisting of `'Method'` and a character vector with one of the following values:

Data Types: `char`

## Output Arguments

collapse all

Optimal portfolios on the efficient frontier with specified target returns from `TargetRisk`, returned as a `NumAssets`-by-`NumPorts` matrix. `pwgt` is returned for a `Portfolio`, `PortfolioCVaR`, or `PortfolioMAD` input object (`obj`).

Purchases relative to an initial portfolio for optimal portfolios on the efficient frontier, returned as `NumAssets`-by-`NumPorts` matrix.

Note

If no initial portfolio is specified in `obj.InitPort`, that value is assumed to be `0` such that ```pbuy = max(0,pwgt)``` and ```psell = max(0,-pwgt)```.

`pbuy` is returned for a `Portfolio`, `PortfolioCVaR`, or `PortfolioMAD` input object (`obj`).

Sales relative to an initial portfolio for optimal portfolios on the efficient frontier, returned as a `NumAssets`-by-`NumPorts` matrix.

Note

If no initial portfolio is specified in `obj.InitPort`, that value is assumed to be `0` such that ```pbuy = max(0,pwgt)``` and ```psell = max(0,-pwgt)```.

`psell` is returned for `Portfolio`, `PortfolioCVaR`, or `PortfolioMAD` input object (`obj`).

## Tips

You can also use dot notation to estimate optimal portfolios with targeted portfolio risks.

`[pwgt,pbuy,psell] = obj.estimateFrontierByRisk(TargetRisk);`

or

`[pwgt,pbuy,psell] = obj.estimateFrontierByRisk(TargetRisk,Name,Value);`

Introduced in R2011a