Choosing and Controlling the Solver for PortfolioMAD Optimizations
When solving portfolio optimizations for a PortfolioMAD
object, you
are solving nonlinear optimization problems with either nonlinear objective or nonlinear
constraints. You can use 'TrustRegionCP'
(default) or
'ExtendedCP'
solvers that implement Kelley’s cutting plane method
(see Kelley [45] at Portfolio Optimization). Alternatively, you can use
fmincon
and all variations of
fmincon
from Optimization Toolbox™ are supported. When using fmincon
as the solverType
, 'sqp'
is the default algorithm for fmincon
.
Using 'TrustRegionCP'
and 'ExtendedCP'
SolverTypes
The 'TrustRegionCP'
and 'ExtendedCP'
solvers
have options to control the number iterations and stopping tolerances. Moreover,
these solvers use linprog
as the primary solver, and all
linprog
options are supported using optimoptions
structures. All these options are set using setSolver
.
For example, you can use setSolver
to increase the number of
iterations for 'TrustRegionCP'
:
p = PortfolioMAD; p = setSolver(p, 'TrustRegionCP', 'MaxIterations', 2000); display(p.solverType) display(p.solverOptions)
trustregioncp MaxIterations: 2000 AbsoluteGapTolerance: 1.0000e07 RelativeGapTolerance: 1.0000e05 NonlinearScalingFactor: 1000 ObjectiveScalingFactor: 1000 MasterSolverOptions: [1×1 optim.options.Linprog] Display: 'off' CutGeneration: 'basic' MaxIterationsInactiveCut: 30 ActiveCutTolerance: 1.0000e07 ShrinkRatio: 0.7500 TrustRegionStartIteration: 2 DeltaLimit: 1
To change the primary solver algorithm to 'interiorpoint'
,
with no display, use setSolver
to modify
'MasterSolverOptions'
:
p = PortfolioMAD; options = optimoptions('linprog','Algorithm','interiorpoint','Display','off'); p = setSolver(p,'TrustRegionCP','MasterSolverOptions',options); display(p.solverType) display(p.solverOptions) display(p.solverOptions.MasterSolverOptions.Algorithm) display(p.solverOptions.MasterSolverOptions.Display)
trustregioncp MaxIterations: 1000 AbsoluteGapTolerance: 1.0000e07 RelativeGapTolerance: 1.0000e05 NonlinearScalingFactor: 1000 ObjectiveScalingFactor: 1000 MasterSolverOptions: [1×1 optim.options.Linprog] Display: 'off' CutGeneration: 'basic' MaxIterationsInactiveCut: 30 ActiveCutTolerance: 1.0000e07 ShrinkRatio: 0.7500 TrustRegionStartIteration: 2 DeltaLimit: 1 interiorpoint off
Using 'fmincon'
SolverType
Unlike Optimization Toolbox which uses the 'interiorpoint'
algorithm as the
default algorithm for fmincon
, the portfolio optimization for
a PortfolioMAD
object uses the 'sqp'
algorithm
as the default. For details about fmincon
and constrained nonlinear optimization algorithms and
options, see Constrained Nonlinear Optimization Algorithms.
To modify fmincon
options for MAD portfolio
optimizations, use setSolver
to set the hidden
properties solverType
and solverOptions
to
specify and control the solver. Since these solver properties are hidden, you cannot
set them using the PortfolioMAD
object. The default for
the fmincon
solver is the
'sqb'
algorithm and no displayed output, so you do not need
to use setSolver
to specify the
'sqp'
algorithm for fmincon
.
p = PortfolioMAD;
p = setSolver(p, 'fmincon');
display(p.solverOptions.Algorithm)
display(p.solverOptions.Display)
sqp off
If you want to specify additional options associated with the fmincon
solver, setSolver
accepts these options as
namevalue pair arguments. For example, if you want to use fmincon
with the 'activeset'
algorithm and with
displayed output, use setSolver
with:
p = PortfolioMAD; p = setSolver(p, 'fmincon', 'Algorithm', 'activeset', 'Display', 'final'); display(p.solverOptions)
fmincon options: Options used by current Algorithm ('activeset'): (Other available algorithms: 'interiorpoint', 'sqp', 'sqplegacy', 'trustregionreflective') Set properties: Algorithm: 'activeset' Display: 'final' Default properties: CheckGradients: 0 ConstraintTolerance: 1.0000e06 FiniteDifferenceStepSize: 'sqrt(eps)' FiniteDifferenceType: 'forward' FunctionTolerance: 1.0000e06 MaxFunctionEvaluations: '100*numberOfVariables' MaxIterations: 400 OptimalityTolerance: 1.0000e06 OutputFcn: [] PlotFcn: [] SpecifyConstraintGradient: 0 SpecifyObjectiveGradient: 0 StepTolerance: 1.0000e06 TypicalX: 'ones(numberOfVariables,1)' UseParallel: 0
Alternatively, the setSolver
function accepts an
optimoptions
object as the second
argument. For example, you can change the algorithm to
'activeset'
with no displayed output as
follows:
p = PortfolioMAD; options = optimoptions('fmincon', 'Algorithm', 'activeset', 'Display', 'off'); p = setSolver(p, 'fmincon', options); display(p.solverOptions.Algorithm) display(p.solverOptions.Display)
activeset 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
PortfolioMAD
object. The MINLP solver
is used 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, 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
PortfolioMAD
object where 'Conditional'
BoundType
, MinNumAssets
, or
MaxNumAssets
constraints are active, the mixed integer
nonlinear programming (MINLP) solver is automatically used.
Solver Guidelines for PortfolioMAD Objects
The following table provides guidelines for using setSolver
and setSolverMINLP
.
PortfolioMAD Problem  PortfolioMAD Function  Type of Optimization Problem  Main Solver  Helper Solver 

PortfolioMAD without active 'Conditional'
BoundType , MinNumAssets ,
and MaxNumAssets  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.  'TrustRegionCP' ,
'ExtendedCP' , or
'fmincon' using setSolver 

PortfolioMAD without active 'Conditional'
BoundType , MinNumAssets ,
and MaxNumAssets  estimateFrontierByReturn  Nonlinear objective with linear constraints  'TrustRegionCP' ,
'ExtendedCP' , or
'fmincon' using setSolver 

PortfolioMAD without active 'Conditional'
BoundType , MinNumAssets ,
and MaxNumAssets  estimateFrontierLimits  Nonlinear or linear objective with linear constraints  For For
 Not applicable 
PortfolioMAD 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  'fmincon' is used when the
estimate functions reduce the problem
into NLP. This solver is configured through setSolver . 
PortfolioMAD 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  'fmincon' is used when the
estimate functions reduce the problem
into NLP. This solver is configured through setSolver 
PortfolioMAD 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  'fmincon' is used when the
estimate functions reduce the problem
into NLP. This solver is configured through setSolver 
See Also
PortfolioMAD
 estimateFrontier
 estimateFrontierLimits
 estimateFrontierByReturn
 estimatePortReturn
 estimateFrontierByRisk
 estimatePortRisk
 estimateFrontierByRisk
 setSolver
 setSolverMINLP
Related Examples
 Estimate Efficient Portfolios Along the Entire Frontier for PortfolioMAD Object
 Creating the PortfolioMAD Object
 Working with MAD Portfolio Constraints Using Defaults
 Estimate Efficient Frontiers for PortfolioMAD Object
 Asset Returns and Scenarios Using PortfolioMAD Object
 Portfolio Optimization with Semicontinuous and Cardinality Constraints