# setSolverMINLP

Choose mixed integer nonlinear programming (MINLP) solver for portfolio optimization

## Syntax

``obj = setSolverMINLP(obj,solverTypeMINLP)``
``obj = setSolverMINLP(___,Name,Value)``

## Description

example

````obj = setSolverMINLP(obj,solverTypeMINLP)` selects the mixed integer nonlinear programming (MINLP) solver and enables you to specify associated solver options for portfolio optimization for a `Portfolio`, `PortfolioCVaR`, or `PortfolioMAD` object. 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. The binary variable `0` indicates that an asset is not invested and the binary variable `1` indicates that an asset is invested. For more information on using `'Conditional'` `BoundType`, see `setBounds`. For more information on specifying `MinNumAssets` and `MaxNumAssets`, see `setMinMaxNumAssets`. If you use the `estimate` functions with a `Portfolio`, `PortfolioCVaR`, or `PortfolioMAD` object for which any of the `'Conditional'` `BoundType`, `MinNumAssets`, or `MaxNumAssets` constraints are active, MINLP solver is automatically used. For details on MINLP, see Algorithms.```

example

````obj = setSolverMINLP(___,Name,Value)` specifies options using one or more name-value pair arguments in addition to the input arguments in the previous syntax.```

## Examples

collapse all

Configure the MINLP solver for a three-asset portfolio for which you have the mean and covariance values of the asset returns.

```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);```

When working with a `Portfolio` object, use `setBounds` with a `'Conditional'BoundType` constraint to set `x`i = `0` or `0.02` <= `xi` <= `0.5` for all i = `1`,...`NumAssets`.

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

When working with a `Portfolio` object, use `setMinMaxNumAssets` function to set up `MinNumAssets` and `MaxNumAssets` constraints for a portfolio. This sets limit constraints for the `Portfolio` object, where the total number of allocated assets satisfying the constraints is between `MinNumAssets` and `MaxNumAssets`. Setting `MinNumAssets` = `MaxNumAssets` = 2, specifies that only two of the three assets are invested in the portfolio.

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

Three different MINLP solvers (`OuterApproximation`, `ExtendedCP`, `TrustRegionCP`) use the cutting plane method. Use the `setSolverMINLP` function to configure the `OuterApproximation` solver and options.

```pint = setSolverMINLP(p,'OuterApproximation', 'NonlinearScalingFactor', 1e4, 'Display', 'iter', 'CutGeneration', 'basic'); pint.solverTypeMINLP```
```ans = 'OuterApproximation' ```
`pint.solverOptionsMINLP`
```ans = struct with fields: MaxIterations: 1000 AbsoluteGapTolerance: 1.0000e-07 RelativeGapTolerance: 1.0000e-05 NonlinearScalingFactor: 10000 ObjectiveScalingFactor: 1000 Display: 'iter' CutGeneration: 'basic' MaxIterationsInactiveCut: 30 ActiveCutTolerance: 1.0000e-07 IntMasterSolverOptions: [1x1 optim.options.Intlinprog] NumIterationsEarlyIntegerConvergence: 30 ```

You can also configure the options for `intlinprog`,which is the Master solver for mixed integer linear programming problems in the MINLP solver.

```pint = setSolverMINLP(p,'OuterApproximation', 'IntMasterSolverOptions', optimoptions('intlinprog','Display','off')); pint.solverOptionsMINLP.IntMasterSolverOptions```
```ans = intlinprog options: Set properties: Display: 'off' Default properties: AbsoluteGapTolerance: 0 BranchRule: 'reliability' ConstraintTolerance: 1.0000e-04 CutGeneration: 'basic' CutMaxIterations: 10 Heuristics: 'basic' HeuristicsMaxNodes: 50 IntegerPreprocess: 'basic' IntegerTolerance: 1.0000e-05 LPMaxIterations: 'max(30000,10*(numberOfEqualities+numberOfInequalities+numberOfVariables))' LPOptimalityTolerance: 1.0000e-07 MaxFeasiblePoints: Inf MaxNodes: 10000000 MaxTime: 7200 NodeSelection: 'simplebestproj' ObjectiveCutOff: Inf ObjectiveImprovementThreshold: 0 OutputFcn: [] PlotFcn: [] RelativeGapTolerance: 1.0000e-04 RootLPAlgorithm: 'dual-simplex' RootLPMaxIterations: 'max(30000,10*(numberOfEqualities+numberOfInequalities+numberOfVariables))' ```

Configure the MINLP solver for a 12 asset portfolio that is using semicontinuous and cardinality constraints.

```load CAPMuniverse p = PortfolioCVaR('AssetList',Assets(1:12)); p = simulateNormalScenariosByData(p, Data(:,1:12), 20000 ,'missingdata',true); p = setProbabilityLevel(p, 0.95);```

When working with a `PortfolioCVaR` object, the `setMinMaxNumAssets` function enables you to set up the limits on the number of assets invested. The following example specifies that a minimum of five assets and a maximum of 10 assets should be invested using `setMinMaxNumAssets` and the investments should be greater than 4% and less than 45% using `setBounds`.

```p = setMinMaxNumAssets(p, 5, 10); p = setBounds(p, 0.04, 0.45, 'BoundType', 'conditional'); ```

Three different MINLP solvers (`OuterApproximation`, `ExtendedCP`, `TrustRegionCP`) use the cutting plane method. Use the `setSolverMINLP` function to configure the `OuterApproximation` solver and options.

```pint = setSolverMINLP(p,'OuterApproximation', 'NonlinearScalingFactor', 1e4, 'Display', 'iter', 'CutGeneration', 'basic'); pint.solverTypeMINLP```
```ans = 'OuterApproximation' ```
`pint.solverOptionsMINLP`
```ans = struct with fields: MaxIterations: 1000 AbsoluteGapTolerance: 1.0000e-07 RelativeGapTolerance: 1.0000e-05 NonlinearScalingFactor: 10000 ObjectiveScalingFactor: 1000 Display: 'iter' CutGeneration: 'basic' MaxIterationsInactiveCut: 30 ActiveCutTolerance: 1.0000e-07 IntMasterSolverOptions: [1x1 optim.options.Intlinprog] NumIterationsEarlyIntegerConvergence: 30 ```

You can also configure the options for `intlinprog`,which is the Master solver for mixed integer linear programming problems in the MINLP solver.

```pint = setSolverMINLP(p,'OuterApproximation', 'IntMasterSolverOptions', optimoptions('intlinprog','Display','off')); pint.solverOptionsMINLP.IntMasterSolverOptions```
```ans = intlinprog options: Set properties: Display: 'off' Default properties: AbsoluteGapTolerance: 0 BranchRule: 'reliability' ConstraintTolerance: 1.0000e-04 CutGeneration: 'basic' CutMaxIterations: 10 Heuristics: 'basic' HeuristicsMaxNodes: 50 IntegerPreprocess: 'basic' IntegerTolerance: 1.0000e-05 LPMaxIterations: 'max(30000,10*(numberOfEqualities+numberOfInequalities+numberOfVariables))' LPOptimalityTolerance: 1.0000e-07 MaxFeasiblePoints: Inf MaxNodes: 10000000 MaxTime: 7200 NodeSelection: 'simplebestproj' ObjectiveCutOff: Inf ObjectiveImprovementThreshold: 0 OutputFcn: [] PlotFcn: [] RelativeGapTolerance: 1.0000e-04 RootLPAlgorithm: 'dual-simplex' RootLPMaxIterations: 'max(30000,10*(numberOfEqualities+numberOfInequalities+numberOfVariables))' ```

Configure the MINLP solver for a 12 asset portfolio that is using semicontinuous and cardinality constraints.

```load CAPMuniverse p = PortfolioMAD('AssetList',Assets(1:12)); p = simulateNormalScenariosByData(p, Data(:,1:12), 20000 ,'missingdata',true);```

When working with a `PortfolioMAD` object, the `setMinMaxNumAssets` function enables you to set up the limits on the number of assets invested. The following example specifies that a minimum of five assets and a maximum of 10 assets should be invested using `setMinMaxNumAssets` and the investments should be greater than 4% and less than 45% using `setBounds`.

```p = setMinMaxNumAssets(p, 5, 10); p = setBounds(p, 0.04, 0.45, 'BoundType', 'conditional'); ```

Three different MINLP solvers (`OuterApproximation`, `ExtendedCP`, `TrustRegionCP`) use the cutting plane method. Use the `setSolverMINLP` function to configure the `OuterApproximation` solver and options.

```pint = setSolverMINLP(p,'OuterApproximation', 'NonlinearScalingFactor', 1e4, 'Display', 'iter', 'CutGeneration', 'basic'); pint.solverTypeMINLP```
```ans = 'OuterApproximation' ```
`pint.solverOptionsMINLP`
```ans = struct with fields: MaxIterations: 1000 AbsoluteGapTolerance: 1.0000e-07 RelativeGapTolerance: 1.0000e-05 NonlinearScalingFactor: 10000 ObjectiveScalingFactor: 1000 Display: 'iter' CutGeneration: 'basic' MaxIterationsInactiveCut: 30 ActiveCutTolerance: 1.0000e-07 IntMasterSolverOptions: [1x1 optim.options.Intlinprog] NumIterationsEarlyIntegerConvergence: 30 ```

You can also configure the options for `intlinprog`,which is the Master solver for mixed integer linear programming problems in the MINLP solver.

```pint = setSolverMINLP(p,'OuterApproximation', 'IntMasterSolverOptions', optimoptions('intlinprog','Display','off')); pint.solverOptionsMINLP.IntMasterSolverOptions```
```ans = intlinprog options: Set properties: Display: 'off' Default properties: AbsoluteGapTolerance: 0 BranchRule: 'reliability' ConstraintTolerance: 1.0000e-04 CutGeneration: 'basic' CutMaxIterations: 10 Heuristics: 'basic' HeuristicsMaxNodes: 50 IntegerPreprocess: 'basic' IntegerTolerance: 1.0000e-05 LPMaxIterations: 'max(30000,10*(numberOfEqualities+numberOfInequalities+numberOfVariables))' LPOptimalityTolerance: 1.0000e-07 MaxFeasiblePoints: Inf MaxNodes: 10000000 MaxTime: 7200 NodeSelection: 'simplebestproj' ObjectiveCutOff: Inf ObjectiveImprovementThreshold: 0 OutputFcn: [] PlotFcn: [] RelativeGapTolerance: 1.0000e-04 RootLPAlgorithm: 'dual-simplex' RootLPMaxIterations: 'max(30000,10*(numberOfEqualities+numberOfInequalities+numberOfVariables))' ```

## 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`

MINLP solver for portfolio optimization when any one or any combination of `'Conditional'` `BoundType`, `MinNumAssets`, or `MaxNumAssets` constraints are active. Specify `solverTypeMINLP` using a character vector or string with a value of `'OuterApproximation'`, `'ExtendedCP'`, or `'TrustRegionCP'`.

For a `Portfolio` object, the default value of the `solverTypeMINLP` is `'OuterApproximation'` with the following default settings for name-value pairs for `setSolverMINLP`:

For a `PortfolioCVaR` and `PortfolioMAD` object, the default value of the `solverTypeMINLP` is `'TrustRegionCP'` with the following default settings for name-value pairs for `setSolverMINLP`:

• `MaxIterations``1000`

• `AbsoluteGapTolerance``1.0000e-07`

• `RelativeGapTolerance``1.0000e-05`

• `Display``'off'`

• `NonlinearScalingFactor``1000`

• `ObjectiveScalingFactor``1000`

• `CutGeneration``'basic'`

• `MaxIterationsInactiveCut``30`

• `NumIterationsEarlyIntegerConvergence``30`

• `ActiveCutTolerance``1.0000e-07`

• `TrustRegionStartIteration` - `2`

• `ShrinkRatio``0.75`

• `InitialDelta``0.5`

• `DeltaLimit``1e-6`

• `IntMasterSolverOptions``optimoptions('intlinprog','Algorithm','Dual-Simplex','Display','off')`

Data Types: `char` | `string`

### Name-Value Arguments

Specify optional pairs of arguments as `Name1=Value1,...,NameN=ValueN`, where `Name` is the argument name and `Value` is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose `Name` in quotes.

Example: ```p = setSolverMINLP(p,'ExtendedCP','MaxIterations',10000,'NonlinearScalingFactor',1000)```

Maximum number of iterations, specified as the comma-separated pair consisting of `'MaxIterations'` and a nonnegative integer value.

Data Types: `double`

Scaling factor for nonlinear function and gradient, specified as the comma-separated pair consisting of `'NonlinearScalingFactor'` and a nonnegative real value.

Data Types: `double`

Scales the objective function used by MasterSolver by a factor, specified as the comma-separated pair consisting of `'ObjectiveScalingFactor'` and a nonnegative real value.

Data Types: `double`

The solver stops if the absolute difference between the approximated nonlinear function value and its true value is less than or equal to `AbsoluteGapTolerance`. `AbsoluteGapTolerance` is specified as the comma-separated pair consisting of `'AbsoluteGapTolerance'` and a nonnegative real value.

Data Types: `double`

The solver stops if the relative difference between the approximated nonlinear function value and its true value is less than or equal to `RelativeGapTolerance`. `RelativeGapTolerance` is specified as the comma-separated pair consisting of `'AbsoluteGapTolerance'` and a nonnegative real value.

Data Types: `double`

Display output format, specified as the comma-separated pair consisting of `'Display'` and a character vector with a value of:

• `'off'` - Display no output

• `'iter'` - Display output at each iteration and the technical exit message

• `'final'` - Display only the final output and the final technical exit message

Data Types: `char`

Cut specification, specified as the comma-separated pair consisting of `'CutGeneration'` and a character vector with one of these values:

• `'midway'` - Add the new cut at the midpoint between the latest and previous solutions found.

• `'basic'` - Add the new cut at the latest solution found.

Data Types: `char`

Removes constraints that are not active for the last `MaxIterationsInactiveCut` iterations, specified as the comma-separated pair consisting of `'MaxIterationsInactiveCut'` and a nonnegative integer value. Generally, the `MaxIterationsInactiveCut` value is larger than `10`.

Data Types: `double`

When the integer variable solution is stable for the last `NumIterationsEarlyIntegerConvergence` iterations, the solver computes a final NLP by using the latest integer variable solution in the MILP. `NumIterationsEarlyIntegerConvergence` is specified as the comma-separated pair consisting of `'NumIterationsEarlyIntegerConvergence'` and a nonnegative integer value.

Data Types: `double`

Determines if the cuts are active, specified as the comma-separated pair consisting of `'ActiveCutTolerance'` and a nonnegative real value. `ActiveCutTolerance` is used together with `MaxIterationsInactiveCut` to decide which cuts to remove from the MILP subproblem.

Data Types: `double`

Solver starts to apply the trust region heuristic at `TrustRegionStartIteration`, specified as the comma-separated pair consisting of `'TrustRegionStartIteration'` and a nonnegative integer.

Note

The `TrustRegionStartIteration` name-value pair argument can only be used with a `solverTypeMINLP` of `'TrustRegionCP'`.

Data Types: `double`

Ratio to shrink size of trust region, specified as the comma-separated pair consisting of `'ShrinkRatio'` and a nonnegative real value between `0` and `1`. If the approximated functions do not have good agreement in the previous iterations, the algorithm uses this ratio to shrink the trust-region size.

Note

The `ShrinkRatio` name-value pair argument can only be used with a `solverTypeMINLP` of `'TrustRegionCP'`.

Data Types: `double`

Value to initialize trust region, specified as the comma-separated pair consisting of `'InitialDelta'` and a nonnegative real value.

Note

The `InitialDelta` name-value pair argument can only be used with a `solverTypeMINLP` of `'TrustRegionCP'`.

Data Types: `double`

Trust region of the approximated functions is bounded by `DeltaLimit` during the iterations, specified as the comma-separated pair consisting of `'DeltaLimit'` and a nonnegative real value.

Note

The `DeltaLimit` name-value pair argument can only be used with a `solverTypeMINLP` of `'TrustRegionCP'`.

Modifying `'DeltaLimit'` might result in the solver not being able to find a solution.

If you modify `'DeltaLimit'` without specifying a value for `'InitialDelta'`, the `'InitialDelta'` is automatically set to `InitialDelta'` = `'DeltaLimit'`/2.

Data Types: `double`

Options for the master solver`intlinprog`, specified as the comma-separated pair consisting of `'IntMasterSolverOptions'` and an `optimoptions` object.

Example: ```'IntMasterSolverOptions', optimoptions('intlinprog','Display','off')```

## Output Arguments

collapse all

Updated portfolio object, returned as a `Portfolio`, `PortfolioCVaR`, or `PortfolioMAD` object.

collapse all

### MINLP Solvers

All three MINLP solvers (`'OuterApproximation'`, `'ExtendedCP'`, and `'TrustRegionCP'`) defined by `solverTypeMINLP` rely on the cutting plane concept.

These MINLP solvers approximate the nonlinear convex function f(x) by a piecewise linear approximation, which is a sequence of linear cuts around the original function. In this way, the original MINLP is reduced to a sequence of MILP subproblems, each one with a more refined approximation to f(x) than previous MILPs, and yields a more optimal solution. The process continues until the solution found from MILP converges to the true function value within a certain tolerance.

• The `'ExtendedCP'` solver iteratively adds a linear cut at the latest solution found to approximate f(x).

• The `'OuterApproximation'` solver is similar to `'ExtendedCP'`, but they differ in where to add the cut. Instead of using the solution from the latest MILP, `OuterApproximation` uses the values of integer variables from the latest MILP solution and fixes them to reduce the MINLP to a nonlinear programming (NLP) problem. The cut is added at the solution from this NLP problem.

• The `'TrustRegionCP'` solver is a version of `'ExtendedCP'` that is modified to speed up the optimization process. In general, the trust region method uses a model to approximate the true function within a region at each iteration. In the context of the MINLP solver, the model is the maximum of all the added cuts. The true function is the nonlinear function f(x) in the optimization problem. The region of the model is updated based on how well the model approximates the true function for the iteration. This approximation is the comparison of the predicted reduction of the objective function using the model vs. the true reduction.

## Tips

You can also use dot notation to specify associated name-value pair options.

`obj = obj.setSolverMINLP(Name,Value);`

Note

The `solverTypeMINLP` and `solverOptionsMINLP` properties cannot be set using dot notation because they are hidden properties. To set the `solverTypeMINLP` and `solverOptionsMINLP` properties, use the `setSolverMINLP` function directly.

## Algorithms

When any one, or any combination of `'Conditional'` `BoundType`, `MinNumAssets`, or `MaxNumAssets` constraints is active, the portfolio problem is formulated by adding `NumAssets` binary variables. The binary variable `0` indicates that an asset is not invested and the binary variable `1` indicates that an asset is invested.

The `MinNumAssets` and `MaxNumAssets` constraints narrow down the number of active positions in a portfolio to the range of [minN, maxN]. In addition, the `'Conditional'` `BoundType` constraint is to set a lower and upper bound so that the position is either `0` or lies in the range [minWgt, maxWgt]. These two types of constraints are incorporated into the portfolio optimization model by introducing n variables, νi, which only take binary values `0` and `1` to indicate whether the corresponding asset is invested (`1`) or not invested (`0`). Here n is the total number of assets and the constraints can be formulated as the following linear inequality constraints:

In this equation, minN and maxN are representations for `MinNumAsset` and `MaxNumAsset` that are set using `setMinMaxNumAssets`. Also, minWgt and maxWgt are representations for `LowerBound` and `UpperBound` that are set using `setBounds`.

The portfolio optimization problem to minimize the variance of the portfolio, subject to achieving a target expected return and some additional linear constraints on the portfolio weights, is formulated as

In this equation, H represents the covariance and m represents the asset returns.

The portfolio optimization problem to maximize the return, subject to an upper limit on the variance of the portfolio return and some additional linear constraints on the portfolio weights, is formulated as

When the `'Conditional'` `BoundType`, `MinNumAssets`, and `MaxNumAssets` constraints are added to the two optimization problems, the problems become:

## References

[1] Bonami, P., Kilinc, M., and J. Linderoth. "Algorithms and Software for Convex Mixed Integer Nonlinear Programs." Technical Report #1664. Computer Sciences Department, University of Wisconsin-Madison, 2009.

[2] Kelley, J. E. "The Cutting-Plane Method for Solving Convex Programs." Journal of the Society for Industrial and Applied Mathematics. Vol. 8, Number 4, 1960, pp. 703–712.

[3] Linderoth, J. and S. Wright. "Decomposition Algorithms for Stochastic Programming on a Computational Grid." Computational Optimization and Applications. Vol. 24, Issue 2–3, 2003, pp. 207–250.

[4] Nocedal, J., and S. Wright. Numerical Optimization. New York: Springer-Verlag, 1999.

## Version History

Introduced in R2018b