The default solver for meanvariance 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 meanvariance portfolio
optimization tools let you use any of the variations of quadprog
from Optimization
Toolbox™ software. Like Optimization
Toolbox which uses the interiorpointconvex
algorithm as the
default algorithm for quadprog
, the portfolio optimization
tools also use the interiorpointconvex
algorithm as the default.
For details about quadprog
and quadratic programming
algorithms and options, see Quadratic Programming Algorithms (Optimization Toolbox).
'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. Since the solver properties are hidden, you
cannot set these 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
interiorpointconvex
algorithm of quadprog
using:
p = Portfolio;
p = setSolver(p, 'quadprog');
display(p.solverType);
display(p.solverOptions);
quadprog quadprog options: Options used by current Algorithm ('interiorpointconvex'): (Other available algorithms: 'trustregionreflective') Set properties: Algorithm: 'interiorpointconvex' Display: 'off' OptimalityTolerance: 1.0000e12 Default properties: ConstraintTolerance: 1.0000e08 LinearSolver: 'auto' MaxIterations: 200 StepTolerance: 1.0000e12
lcprog
with:p = setSolver(p, 'lcprog');
display(p.solverType);
display(p.solverOptions);
lcprog MaxIter: [] TieBreak: [] TolPiv: 5.0000e08
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 argument namevalue pair arguments in the function call. For example, if you
intend to use quadprog
and want to use the
'trustregionreflective'
algorithm, call setSolver
with:p = Portfolio; p = setSolver(p, 'quadprog', 'Algorithm', 'trustregionreflective'); display(p.solverOptions);
quadprog options: Options used by current Algorithm ('trustregionreflective'): (Other available algorithms: 'interiorpointconvex') Set properties: Algorithm: 'trustregionreflective' Default properties: Display: 'final' FunctionTolerance: 'default dependent on problem' HessianMultiplyFcn: [] MaxIterations: 'default dependent on problem' OptimalityTolerance: 'default dependent on problem' StepTolerance: 2.2204e14 SubproblemAlgorithm: 'cg' TypicalX: 'ones(numberOfVariables,1)'
In addition, if you want to specify any of the options for quadprog
that are normally 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 'trustregionreflective'
with no displayed output:
p = Portfolio; options = optimoptions('quadprog', 'Algorithm', 'trustregionreflective', 'Display', 'off'); p = setSolver(p, 'quadprog', options); display(p.solverOptions.Algorithm); display(p.solverOptions.Display);
trustregionreflective off
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, the
portfolio problem is formulated 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.
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 (min risk problem) or linear (max 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 ,
and MaxNumAssets  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 ,
and MaxNumAssets  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 ,
and MaxNumAssets  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 ,
and MaxNumAssets  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 
Portfolio
 estimatePortMoments
 estimatePortReturn
 plotFrontier