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
lcprog
with this
code:p = setSolver(p, 'lcprog');
display(p.solverType);
display(p.solverOptions)
lcprog MaxIter: [] TieBreak: [] TolPiv: 5.0000e-08
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 Problem | Portfolio Function | Type of Optimization Problem | Main Solver | Helper Solver |
---|---|---|---|---|
Portfolio without tracking error constraints | estimateFrontierByRisk | Optimizing 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 For
|
Portfolio without tracking error constraints | estimateFrontierByReturn | Quadratic objective with linear constraints | 'quadprog' or 'lcprog'
using setSolver | For For
|
Portfolio without tracking error constraints | estimateFrontierLimits | Quadratic or linear objective with linear constraints | For For
| Not applicable |
Portfolio without tracking error constraints | estimateMaxSharpeRatio | Quadratic objective with linear constraints | 'quadprog' using setSolver | Because |
Portfolio with tracking error constraints | estimateFrontierByRisk | Linear objective with linear and nonlinear constraints | 'fmincon' using setSolver | Not applicable |
Portfolio with tracking error constraints | estimateFrontierByReturn | Linear objective with linear and nonlinear constraints | 'fmincon' using setSolver | Not applicable |
Portfolio with tracking error constraints | estimateFrontierLimits | Quadratic (minimum risk problem) or linear (maximum return problem) objective with linear and nonlinear constraints | 'fmincon' using setSolver | Not applicable |
Portfolio with tracking error constraints | estimateMaxSharpeRatio | Quadratic objective with linear and nonlinear constraints | 'fmincon' using setSolver | Not applicable |
Portfolio with active 'Conditional'
BoundType , MinNumAssets ,
MaxNumAssets , or conditional budget
constraints | estimateFrontierByRisk | The 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 ,
MaxNumAssets , or conditional budget
constraints | estimateFrontierByReturn | The 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 ,
MaxNumAssets , or conditional budget
constraints | estimateFrontierLimits | The 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 ,
MaxNumAssets , or conditional budget
constraints | estimateMaxSharpeRatio | The 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 Problem | Portfolio Function | Type of Optimization Problem | Main Solver | Helper Solver |
---|---|---|---|---|
Portfolio with custom linear objective without tracking error constraints | estimateCustomObjectivePortfolio | Linear objective with linear constraints | 'linprog' using setSolver | Not applicable |
Portfolio with custom quadratic objective without tracking error constraints | estimateCustomObjectivePortfolio | Quadratic objective with linear constraints | 'quadprog' using setSolver | Not applicable |
Portfolio with custom nonlinear objective without tracking error constraints | estimateCustomObjectivePortfolio | Nonlinear objective with linear constraints | 'fmincon' using setSolver | Not applicable |
Portfolio with custom linear objective with tracking error constraints | estimateCustomObjectivePortfolio | Linear objective with linear and nonlinear constraints | 'fmincon' using setSolver | Not applicable |
Portfolio with custom quadratic objective with tracking error constraints | estimateCustomObjectivePortfolio | Quadratic objective with linear and nonlinear constraints | 'fmincon' using setSolver | Not applicable |
Portfolio with custom nonlinear objective with tracking error constraints | estimateCustomObjectivePortfolio | Nonlinear objective with linear and nonlinear constraints | 'fmincon' using setSolver | Not applicable |
Portfolio with active 'Conditional'
BoundType , MinNumAssets ,
MaxNumAssets , or conditional budget
constraints | estimateCustomObjectivePortfolio | The 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
Portfolio
| estimatePortReturn
| estimatePortMoments
| plotFrontier
| setConditionalBudget
Related Examples
- Plotting the Efficient Frontier for a Portfolio Object
- Creating the Portfolio Object
- Working with Portfolio Constraints Using Defaults
- Estimate Efficient Portfolios for Entire Efficient Frontier for Portfolio Object
- Postprocessing Results to Set Up Tradable Portfolios
- Asset Allocation Case Study
- Portfolio Optimization Examples Using Financial Toolbox
- Portfolio Optimization with Semicontinuous and Cardinality Constraints
- Black-Litterman Portfolio Optimization Using Financial Toolbox
- Portfolio Optimization Using Factor Models
- Portfolio Optimization Using Social Performance Measure
- Diversify Portfolios Using Custom Objective
- Mixed-Integer Mean-Variance Portfolio Optimization Problem
- Adding Constraints to Satisfy UCITS Directive
More About
- Portfolio Object
- Portfolio Optimization Theory
- Choose MINLP Solvers for Portfolio Problems
- Portfolio Object Workflow
- Role of Convexity in Portfolio Problems