Main Content

Choosing and Controlling the Solver for Mean-Variance Portfolio Optimization

The default solver for mean-variance portfolio optimization is lcprog, which implements a linear complementarity programming (LCP) algorithm. Although lcprog works for most problems, you can adjust arguments to control the algorithm. Alternatively, the mean-variance portfolio optimization tools let you use any of the variations of quadprog from Optimization Toolbox™ software. Like Optimization Toolbox, which uses the interior-point-convex algorithm as the default algorithm for quadprog, the portfolio optimization tools also use the interior-point-convex algorithm as the default. For details about quadprog and quadratic programming algorithms and options, see Quadratic Programming Algorithms.

Using 'lcprog' and 'quadprog'

To modify either lcprog or to specify quadprog as your solver, use the setSolver function to set the hidden properties solverType and solverOptions that specify and control the solver. Because the solver properties are hidden, you cannot set these options using the Portfolio object. The default solver is lcprog so you do not need to use setSolver to specify this solver. To use quadprog, you can set the default interior-point-convex algorithm of quadprog using this code:

p = Portfolio;
p = setSolver(p, 'quadprog');
display(p.solverType)
display(p.solverOptions)
quadprog options:

   Options used by current Algorithm ('interior-point-convex'):
   (Other available algorithms: 'active-set', 'trust-region-reflective')

   Set properties:
              Algorithm: 'interior-point-convex'
                Display: 'off'
    OptimalityTolerance: 1.0000e-12

   Default properties:
    ConstraintTolerance: 1.0000e-08
           LinearSolver: 'auto'
          MaxIterations: 200
          StepTolerance: 1.0000e-12
You can switch back to lcprog with this code:
p = setSolver(p, 'lcprog');
display(p.solverType);
display(p.solverOptions)
lcprog
     MaxIter: []
    TieBreak: []
      TolPiv: 5.0000e-08
In both cases, setSolver sets up default options associated with either solver. If you want to specify additional options associated with a given solver, setSolver accepts these options with name-value arguments in the function call. For example, if you intend to use quadprog and want to use the 'trust-region-reflective' algorithm, call setSolver with this code:
p = Portfolio;
p = setSolver(p, 'quadprog', 'Algorithm', 'trust-region-reflective');
display(p.solverOptions)
  quadprog options:

   Options used by current Algorithm ('trust-region-reflective'):
   (Other available algorithms: 'active-set', 'interior-point-convex')

   Set properties:
              Algorithm: 'trust-region-reflective'

   Default properties:
                Display: 'final'
      FunctionTolerance: 'default dependent on problem'
     HessianMultiplyFcn: []
          MaxIterations: 'default dependent on problem'
    OptimalityTolerance: 'default dependent on problem'
          StepTolerance: 2.2204e-14
    SubproblemAlgorithm: 'cg'
               TypicalX: 'ones(numberOfVariables,1)'

In addition, if you want to specify any of the options for quadprog that you typically set through optimoptions from Optimization Toolbox, setSolver accepts an optimoptions object as the second argument. For example, you can start with the default options for quadprog set by setSolver and then change the algorithm to 'trust-region-reflective' with no displayed output:

p = Portfolio;
options = optimoptions('quadprog', 'Algorithm', 'trust-region-reflective', 'Display', 'off');
p = setSolver(p, 'quadprog', options);
display(p.solverOptions.Algorithm)
display(p.solverOptions.Display)
trust-region-reflective
off

Using the Mixed Integer Nonlinear Programming (MINLP) Solver

The mixed integer nonlinear programming (MINLP) solver, configured using setSolverMINLP, enables you to specify associated solver options for portfolio optimization for a Portfolio object. The MINLP solver is used when any one, or any combination of 'Conditional' BoundType, MinNumAssets, or MaxNumAssets constraints are active. In this case, you formulate the portfolio problem by adding NumAssets binary variables, where 0 indicates not invested, and 1 is invested. For more information on using 'Conditional' BoundType, see setBounds. For more information on specifying MinNumAssets and MaxNumAssets, see setMinMaxNumAssets.

When using the estimate functions with a Portfolio object where 'Conditional' BoundType, MinNumAssets, or MaxNumAssets constraints are active, the mixed integer nonlinear programming (MINLP) solver is automatically used.

Solver Guidelines for Portfolio Objects

The following table provides guidelines for using setSolver and setSolverMINLP.

Portfolio ProblemPortfolio FunctionType of Optimization ProblemMain Solver Helper Solver
Portfolio without tracking error constraintsestimateFrontierByRiskOptimizing a portfolio for a certain risk level introduces a nonlinear constraint. Therefore, this problem has a linear objective with linear and nonlinear constraints.'fmincon' using setSolver

For 'min': quadratic objective, 'quadprog' or 'lcprog' using setSolver

For 'max': linear objective, 'linprog' or 'lcprog' using setSolver

Portfolio without tracking error constraintsestimateFrontierByReturnQuadratic objective with linear constraints'quadprog' or 'lcprog' using setSolver

For ‘min’: quadratic objective, 'quadprog' or 'lcprog' using setSolver

For ‘max’: linear objective, 'linprog' or 'lcprog' using setSolver

Portfolio without tracking error constraintsestimateFrontierLimits

Quadratic or linear objective with linear constraints

For ‘min’: quadratic objective, 'quadprog' or 'lcprog' using setSolver

For ‘max’: linear objective, 'linprog' or 'lcprog' using setSolver

Not applicable
Portfolio without tracking error constraintsestimateMaxSharpeRatioQuadratic objective with linear constraints'quadprog' using setSolver

Because estimateMaxSharpeRatio internally calls estimateFrontierLimits, all solvers needed by estimateFrontierLimits are the helper solvers

Portfolio with tracking error constraintsestimateFrontierByRiskLinear objective with linear and nonlinear constraints'fmincon' using setSolverNot applicable
Portfolio with tracking error constraintsestimateFrontierByReturnLinear objective with linear and nonlinear constraints'fmincon' using setSolverNot applicable
Portfolio with tracking error constraintsestimateFrontierLimitsQuadratic (minimum risk problem) or linear (maximum return problem) objective with linear and nonlinear constraints'fmincon' using setSolverNot applicable
Portfolio with tracking error constraintsestimateMaxSharpeRatioQuadratic objective with linear and nonlinear constraints'fmincon' using setSolverNot applicable
Portfolio with active 'Conditional' BoundType, MinNumAssets, and MaxNumAssetsestimateFrontierByRiskThe problem is formulated by introducing NumAssets binary variables to indicate whether the corresponding asset is invested or not. Therefore, it requires a mixed integer nonlinear programming solver. Three types of MINLP solvers are offered, see setSolverMINLP.Mixed integer nonlinear programming solver (MINLP) using setSolverMINLP'quadprog' or 'fmincon' are used when the estimate functions reduce the problem into NLP. These two solvers can be configured through setSolver.
Portfolio with active 'Conditional' BoundType, MinNumAssets, and MaxNumAssetsestimateFrontierByReturnThe problem is formulated by introducing NumAssets binary variables to indicate whether the corresponding asset is invested or not. Therefore, it requires a mixed integer nonlinear programming solver. Three types of MINLP solvers are offered, see setSolverMINLP.Mixed integer nonlinear programming solver (MINLP) using setSolverMINLP'quadprog' or 'fmincon' are used when the estimate functions reduce the problem into NLP. These two solvers can be configured through setSolver.
Portfolio with active 'Conditional' BoundType, MinNumAssets, and MaxNumAssetsestimateFrontierLimitsThe problem is formulated by introducing NumAssets binary variables to indicate whether the corresponding asset is invested or not. Therefore, it requires a mixed integer nonlinear programming solver. Three types of MINLP solvers are offered, see setSolverMINLP.Mixed integer nonlinear programming solver (MINLP) using setSolverMINLP'quadprog' or 'fmincon' are used when the estimate functions reduce the problem into NLP. These two solvers can be configured through setSolver.
Portfolio with active 'Conditional' BoundType, MinNumAssets, and MaxNumAssetsestimateMaxSharpeRatioThe problem is formulated by introducing NumAssets binary variables to indicate whether the corresponding asset is invested or not. Therefore, it requires a mixed integer nonlinear programming solver. Three types of MINLP solvers are offered, see setSolverMINLP.Mixed integer nonlinear programming solver (MINLP) using setSolverMINLP'quadprog' or 'fmincon' are used when the estimate functions reduce the problem into NLP. These two solvers can be configured through setSolver.

Solver Guidelines for Custom Objective Problems Using Portfolio Objects

The following table provides guidelines for using setSolver and setSolverMINLP when using estimateCustomObjectivePortfolio.

Portfolio ProblemPortfolio FunctionType of Optimization ProblemMain Solver Helper Solver
Portfolio with custom linear objective without tracking error constraintsestimateCustomObjectivePortfolioLinear objective with linear constraints'linprog' using setSolverNot applicable
Portfolio with custom quadratic objective without tracking error constraintsestimateCustomObjectivePortfolioQuadratic objective with linear constraints'quadprog' using setSolverNot applicable
Portfolio with custom nonlinear objective without tracking error constraintsestimateCustomObjectivePortfolio

Nonlinear objective with linear constraints

'fmincon' using setSolverNot applicable
Portfolio with custom linear objective with tracking error constraintsestimateCustomObjectivePortfolioLinear objective with linear and nonlinear constraints'fmincon' using setSolverNot applicable
Portfolio with custom quadratic objective with tracking error constraintsestimateCustomObjectivePortfolioQuadratic objective with linear and nonlinear constraints'fmincon' using setSolverNot applicable
Portfolio with custom nonlinear objective with tracking error constraintsestimateCustomObjectivePortfolioNonlinear objective with linear and nonlinear constraints'fmincon' using setSolverNot applicable
Portfolio with active 'Conditional' BoundType, MinNumAssets, or MaxNumAssets without tracking error constraintsestimateCustomObjectivePortfolioThe problem is formulated by introducing NumAssets binary variables to indicate whether the corresponding asset is invested or not. Therefore, it requires a mixed integer nonlinear programming solver. Three types of MINLP solvers are offered, see setSolverMINLP.Mixed integer nonlinear programming solver (MINLP) using setSolverMINLP'intlinprog' is used when the problem reduces to a mixed-integer linear problem. This solver can be configured using setSolverMINLP and its name-value argument IntMainSolverOptions.

See Also

| | |

Related Examples

More About

External Websites