setSolver
Choose main solver and specify associated solver options for portfolio optimization
Syntax
Description
selects the main solver and enables you to specify associated solver options for portfolio
optimization for obj = setSolver(obj,solverType)Portfolio, PortfolioCVaR, or PortfolioMAD objects. For details on the
respective workflows when using these different objects, see Portfolio Object Workflow, PortfolioCVaR Object Workflow, and PortfolioMAD Object Workflow.
selects the main solver and enables you to specify associated solver options for portfolio
optimization for portfolio objects with additional options specified by using one or more
obj = setSolver(obj,solverType,Name=Value)Name,Value arguments.
selects the main solver and enables you to specify associated solver options for portfolio
optimization for portfolio objects with an obj = setSolver(obj,solverType,optimoptions)optimoptions object.
Examples
If you use the default solver quadprog as the solverType, the default is the interior-point-convex version of quadprog.
load CAPMuniverse p = Portfolio('AssetList',Assets(1:12)); p = setDefaultConstraints(p); display(p.solverType);
quadprog
display(p.solverOptions);
quadprog options:
Options used by current Algorithm ('interior-point-convex'):
(Other available algorithms: 'active-set', 'trust-region-reflective')
Set properties:
Display: 'off'
OptimalityTolerance: 1.0000e-12
Default properties:
Algorithm: 'interior-point-convex'
ConstraintTolerance: 1.0000e-08
LinearSolver: 'auto'
MaxIterations: 200
ScaleProblem: 0
StepTolerance: 1.0000e-12
Show options not used by current Algorithm ('interior-point-convex')
You can switch to lcprog with:
p = setSolver(p, 'lcprog');
display(p.solverType);lcprog
display(p.solverOptions);
struct with fields:
MaxIter: []
TieBreak: []
TolPiv: 5.0000e-08
Use 'fmincon' as the solverType.
p = PortfolioCVaR;
p = setSolver(p, 'fmincon');
display(p.solverType);fmincon
Use 'fmincon' as the solverType and use name-value pair arguments to set the algorithm to 'interior-point' and to turn off the display.
p = PortfolioCVaR; p = setSolver(p, 'fmincon', 'Algorithm', 'interior-point', 'Display', 'off'); display(p.solverOptions.Algorithm);
interior-point
display(p.solverOptions.Display);
off
Use 'fmincon' as the solverType and use an optimoptions object to set the algorithm to 'interior-point' and to turn off the display.
p = PortfolioCVaR; options = optimoptions('fmincon', 'Algorithm', 'interior-point', 'Display', 'off'); p = setSolver(p, 'fmincon', options); display(p.solverOptions.Algorithm);
interior-point
display(p.solverOptions.Display);
off
Use 'TrustRegionCP' as the solverType with default options.
p = PortfolioCVaR;
p = setSolver(p,'TrustRegionCP');
display(p.solverType);trustregioncp
display(p.solverOptions);
struct with fields:
MaxIterations: 1000
AbsoluteGapTolerance: 1.0000e-07
RelativeGapTolerance: 1.0000e-05
NonlinearScalingFactor: 1000
ObjectiveScalingFactor: 1000
MainSolverOptions: [1×1 optim.options.Linprog]
Display: 'off'
CutGeneration: 'basic'
MaxIterationsInactiveCut: 15
ActiveCutTolerance: 1.0000e-07
CutSelectionHeuristic: 'quantile'
QuantileThreshold: 0.6000
ShrinkRatio: 0.7500
TrustRegionStartIteration: 2
InitialDelta: 0.5000
DeltaLimit: 1000000
Use the name-value pair 'ShrinkRatio' to shrink the size of the trust region by 0.75.
p = PortfolioCVaR; p = setSolver(p,'TrustRegionCP','ShrinkRatio',0.75); display(p.solverType);
trustregioncp
display(p.solverOptions);
struct with fields:
MaxIterations: 1000
AbsoluteGapTolerance: 1.0000e-07
RelativeGapTolerance: 1.0000e-05
NonlinearScalingFactor: 1000
ObjectiveScalingFactor: 1000
MainSolverOptions: [1×1 optim.options.Linprog]
Display: 'off'
CutGeneration: 'basic'
MaxIterationsInactiveCut: 15
ActiveCutTolerance: 1.0000e-07
CutSelectionHeuristic: 'quantile'
QuantileThreshold: 0.6000
ShrinkRatio: 0.7500
TrustRegionStartIteration: 2
InitialDelta: 0.5000
DeltaLimit: 1000000
For the main solver, continue using the dual-simplex algorithm with no display, but tighten its termination tolerance to 1e8.
p = PortfolioCVaR; options = optimoptions('linprog','Algorithm','Dual-Simplex','Display','off','OptimalityTolerance',1e8); p = setSolver(p,'TrustRegionCP','MainSolverOptions',options); display(p.solverType)
trustregioncp
display(p.solverOptions)
struct with fields:
MaxIterations: 1000
AbsoluteGapTolerance: 1.0000e-07
RelativeGapTolerance: 1.0000e-05
NonlinearScalingFactor: 1000
ObjectiveScalingFactor: 1000
MainSolverOptions: [1×1 optim.options.Linprog]
Display: 'off'
CutGeneration: 'basic'
MaxIterationsInactiveCut: 15
ActiveCutTolerance: 1.0000e-07
CutSelectionHeuristic: 'quantile'
QuantileThreshold: 0.6000
ShrinkRatio: 0.7500
TrustRegionStartIteration: 2
InitialDelta: 0.5000
DeltaLimit: 1000000
display(p.solverOptions.MainSolverOptions.Algorithm)
dual-simplex-highs
display(p.solverOptions.MainSolverOptions.Display)
off
display(p.solverOptions.MainSolverOptions.TolFun)
100000000
For the main solver, use the interior-point algorithm with no display and with a termination tolerance of 1e7.
p = PortfolioCVaR; options = optimoptions('linprog','Algorithm','interior-point','Display','off','OptimalityTolerance',1e7); p = setSolver(p,'TrustRegionCP','MainSolverOptions',options); display(p.solverType)
trustregioncp
display(p.solverOptions)
struct with fields:
MaxIterations: 1000
AbsoluteGapTolerance: 1.0000e-07
RelativeGapTolerance: 1.0000e-05
NonlinearScalingFactor: 1000
ObjectiveScalingFactor: 1000
MainSolverOptions: [1×1 optim.options.Linprog]
Display: 'off'
CutGeneration: 'basic'
MaxIterationsInactiveCut: 15
ActiveCutTolerance: 1.0000e-07
CutSelectionHeuristic: 'quantile'
QuantileThreshold: 0.6000
ShrinkRatio: 0.7500
TrustRegionStartIteration: 2
InitialDelta: 0.5000
DeltaLimit: 1000000
display(p.solverOptions.MainSolverOptions.Algorithm)
interior-point
display(p.solverOptions.MainSolverOptions.Display)
off
display(p.solverOptions.MainSolverOptions.TolFun)
10000000
Use 'fmincon' as the solverType.
p = PortfolioMAD;
p = setSolver(p, 'fmincon');
display(p.solverType);fmincon
Use 'fmincon' as the solverType and use name-value pair arguments to set the algorithm to 'sqp' and to turn on the display.
p = PortfolioMAD; p = setSolver(p, 'fmincon', 'Algorithm', 'sqp', 'Display', 'final'); display(p.solverOptions.Algorithm);
sqp
display(p.solverOptions.Display);
final
Use 'fmincon' as the solverType and use an optimoptions object to set the algorithm to 'trust-region-reflective' and to turn off the display.
p = PortfolioMAD; options = optimoptions('fmincon', 'Algorithm', 'trust-region-reflective', 'Display', 'off'); p = setSolver(p, 'fmincon', options); display(p.solverOptions.Algorithm);
trust-region-reflective
display(p.solverOptions.Display);
off
Use 'fmincon' as the solverType and use an optimoptions object to set the algorithm to 'active-set' and to set the gradients flag 'on' for 'GradObj' and turn off the display.
p = PortfolioMAD; options = optimoptions('fmincon','algorithm','active-set','display','off','gradobj','on'); p = setSolver(p, 'fmincon', options); display(p.solverOptions.Algorithm);
active-set
display(p.solverOptions.Display);
off
Input Arguments
Object for portfolio, specified using Portfolio,
PortfolioCVaR, or PortfolioMAD object. For more
information on creating a portfolio object, see
Data Types: object
Solver to use for portfolio optimization, specified using a character vector or
string for the supported solverType.
The solverType input argument depends on which type of object
(obj) is being used for a portfolio optimization.
Using Portfolio Object
For a Portfolio object, the supported
solverType are:
'quadprog'(Default).The default algorithm for
'quadprog'isinterior-point-convex. For more information about'quadprog'name-value options, see Portfolio Object Name-Value Arguments.
'lcprog'The
'lcprog'solver uses linear complementary programming with Lemke's algorithm with control variables name-value arguments for'maxiter','tiebreak','tolpiv'. For more information about'lcprog'name-value options, see Portfolio Object Name-Value Arguments.
'fmincon'The default algorithm for
'fmincon'is'sqp'. For more information about'fmincon'name-value options, see Portfolio Object Name-Value Arguments.
Using PortfolioCVaR Object
For a PortfolioCVaR object, the supported
solverType are:
'TrustRegionCP'(Default)'TrustRegionCP'is an implementation of Kelley's [1] cutting-plane method for convex optimization. For more information about'TrustRegionCP'name-value options, see Name-Value Arguments for 'TrustRegionCP' and 'ExtendedCP'.
'ExtendedCP''ExtendedCP'is an implementation of Kelley's [1] cutting-plane method for convex optimization. For more information about'ExtendedCP'name-value options, see Name-Value Arguments for 'TrustRegionCP' and 'ExtendedCP'.
'fmincon'The default algorithm for
'fmincon'is'sqp'. For more information about'fmincon'name-value options, see PortfolioCVaR Object Name-Value Arguments.
'cuttingplane'The
'cuttingplane'solver is an implementation of Kelley's [1] cutting-plane method for convex optimization with name-value arguments for'MaxIter','Abstol','Reltol'and'MainSolverOptions'. For more information about'cuttingplane'name-value options, see PortfolioCVaR Object Name-Value Arguments.
Using PortfolioMAD Object
For a PortfolioMAD object, the supported
solverType are:
'TrustRegionCP'(Default)'TrustRegionCP'is an implementation of Kelley's [1] cutting-plane method for convex optimization. For more information about'TrustRegionCP'name-value options, see Name-Value Arguments for 'TrustRegionCP' and 'ExtendedCP'.
'ExtendedCP''ExtendedCP'is an implementation of Kelley's [1] cutting-plane method for convex optimization. For more information about'ExtendedCP'name-value options, see Name-Value Arguments for 'TrustRegionCP' and 'ExtendedCP'.
'fmincon'The default algorithm for
'fmincon'is the'sqp'algorithm and'GradObj'set to'on'. For more information about'fmincon'name-value options, see PortfolioMAD Object Name-Value Arguments.
Note
setSolver can also configure solver options for
'linprog'. linprog is a helper solver used in estimating efficient frontier
problems for a Portfolio, PorfolioCVaR, or
PortfolioMAD object. The default algorithm for
'linprog' is 'dual-simplex-highs'. For more
information about 'linprog' name-value options, see Name-Value Arguments. For more details on using a helper solver, see Solver Guidelines for Portfolio Objects, Solver Guidelines for PortfolioCVaR Objects, or Solver Guidelines for PortfolioMAD Objects.
Data Types: char | string
(Optional) optimoptions object, specified as an
optimoptions object that is created using optimoptions from Optimization Toolbox™. For example:
p =
setSolver(p,'fmincon',optimoptions('fmincon','Display','iter'));
Note
optimoptions is the default and
recommended method to set solver options, however optimset is also supported.
Data Types: object
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 = setSolver(p,'cuttingplane','MainSolverOptions',options)
sets cuttingplane options for a PortfolioCVaR
object.
Depending on the obj type (Portfolio,
PortfolioCVaR, or PortfolioMAD) and the specified
solverType, the options for the associated name-value arguments are
different.
Portfolio Object Name-Value ArgumentsFor a
Portfolioobject using asolverTypeoflcprog, choose a name-value value in this table.Value Description 'maxiter'Maximum number of iterations,specified as the comma-separated pair consisting of
'MaxIter'and a positive integer. The default value is1 + n3, where n is the dimension of the input.'tiebreak'Method to break ties for pivot selection, specified as the comma-separated pair consisting of
'tiebreak'and one of the following options:first- Select pivot with lowest index.last- Select pivot with highest index.random- Select a pivot at random.
The default value is
first.'tolpiv'Pivot tolerance below which a number is considered to be zero, specified as the comma-separated pair consisting of
'tolpiv'and a numeric value. The default value is1.0e-9.For a
Portfolioobject using asolverTypeoffmincon, see options to choose name-value arguments.For a
Portfolioobject using asolverTypeoflinprog, see options to choose name-value arguments.For a
Portfolioobject using asolverTypeofquadprog, see options to choose name-value arguments.
PortfolioCVaR Object Name-Value ArgumentsFor a
PortfolioCVaRobject using asolverTypeoffmincon, see options to choose name-value arguments.For a
PorfolioCVaRobject using asolverTypeof'TrustRegionCP'or'ExtendedCP', see Name-Value Arguments for 'TrustRegionCP' and 'ExtendedCP' to choose name-value arguments.For a
PorfolioCVaRobject using asolverTypeof'cuttingplane', choose a name-value value in this table.Value Description 'MaxIter'Maximum number of iterations, specified as the comma-separated pair consisting of
'MaxIter'and a positive integer. The default value is1000.'AbsTol'Absolute stopping tolerance, specified as the comma-separated pair consisting of
'AbsTol'and a positive scalar. The default value is1e6.'RelTol'Relative stopping tolerance, specified as the comma-separated pair consisting of
'RelTol'and a positive scalar. The default value is1e5.'MainSolverOptions'Options for the main solver
linprog, specified as the comma-separated pair consisting of'MainSolverOptions'and anoptimoptionsobject. The default isoptimoptions('linprog','Algorithm','dual-simplex-highs','Display','off').For a
PortfolioCVaRobject using asolverTypeoflinprog, see options to choose name-value arguments.
PortfolioMAD Object Name-Value ArgumentsFor a
PortfolioMADobject using asolverTypeoffmincon, see options to choose name-value arguments.For a
PorfolioMADobject using asolverTypeof'TrustRegionCP'or'ExtendedCP', see Name-Value Arguments for 'TrustRegionCP' and 'ExtendedCP' to choose name-value arguments.For a
PortfolioMADobject using asolverTypeoflinprog, see options to choose name-value arguments.
'TrustRegionCP' and
'ExtendedCP'For a PortfolioCVaR or PortfolioMAD object using
a solverType of 'TrustRegionCP' or
'ExtendedCP', choose a name-value pair in this table.
| Value | Description |
|---|---|
'MaxIterations' | Maximum number of iterations, specified as the comma-separated pair
consisting of |
'NonlinearScalingFactor' | Scales the nonlinear function and its gradient by a factor, specified
as the comma-separated pair consisting of
|
'ObjectiveScalingFactor' | Scales the objective function by a factor, specified as the
comma-separated pair consisting of |
'AbsoluteGapTolerance' | Solver stops if the absolute difference between the approximated nonlinear
function value and its true value is less than or equal to
AbsoluteGapTolerance, specified as the comma-separated pair
consisting of 'AbsoluteGapTolerance' and a positive real
number. The default value is 1e-7. |
'RelativeGapTolerance' | Solver stops if the relative difference between the approximated nonlinear
function value and its true value is less than or equal to
RelativeGapTolerance, specified as the comma-separated pair
consisting of 'RelativeGapTolerance' and a positive real
number. The default value is 1e-5. |
'Display' | Level of display, specified as the comma-separated pair consisting of
'Display' and a supported value of:
|
'CutGeneration' | Method to add the cut, specified as the comma-separated pair consisting of
'CutGeneration' and a supported value of:
|
In R2026a: | Type of cut selection heuristic, specified as the comma-separated pair
consisting of 'CutSelectionHeuristic' and a supported value
of:
|
In R2026a: | Controls the quantile threshold under which cuts are considered inactive,
specified as the comma-separated pair consisting of
'QuantileThreshold' and a value between
0 and 1. The default is
0.60. |
'MaxIterationsInactiveCut' | Removes constraints that are not active for the last
MaxIterationsInactiveCut iterations, specified as the
comma-separated pair consisting of 'MaxIterationsInactiveCut'
and a positive integer.
|
'ActiveCutTolerance' | Determines if the cuts are active and is used together with
MaxIterationsInactiveCut to decide which cuts to remove
from the LP subproblem, specified as the comma-separated pair consisting of
'ActiveCutTolerance' and a real number. The default value
is 1e7. |
'MainSolverOptions' | Options for the main solver linprog, specified as the comma-separated pair consisting of
'MainSolverOptions' and an optimoptions object. The default is
optimoptions('linprog','Algorithm','dual-simplex-highs','Display','off'). |
'TrustRegionStartIteration' | Use this parameter only for a solverType of
'TrustRegionCP'. Solver starts to apply the trust region
heuristic at TrustRegionStartIteration. Nonnegative integer.
Default is 2. |
'ShrinkRatio' | Use this parameter only for a solverType of
'TrustRegionCP'. If the approximated functions are not
agreeing well in the previous iterations, the algorithm will shrink the size of
trust region by the ShrinkRatio. Nonnegative real between
0 and 1. Default is
0.75. |
'InitialDelta' | Use this parameter only for a solverType of
'TrustRegionCP'. Value to initialize trust region.
Nonnegative real. Default is 0.5. |
'DeltaLimit' | Use this parameter only for a solverType of
'TrustRegionCP'. The trust region of the approximated
functions is bounded by DeltaLimit during the iterations. The
DeltaLimit value is a nonnegative real and the default
value is 1e6.Note Modifying If you modify |
'DeltaLowerBound' | Use this parameter only for a solverType of
'TrustRegionCP'. Use 'DeltaLowerBound'
to set the lower bound for the trust-region radius. The
'DeltaLowerBound' numeric value must be in
[0,1] and you can include
0 and 1. The default value is
0.01. |
Output Arguments
Updated portfolio object, returned as a Portfolio,
PortfolioCVaR, or PortfolioMAD object. For more
information on creating a portfolio object, see
Tips
You can also use dot notation to choose the solver and specify associated solver options.
obj = obj.setSolver(solverType,Name=Value);
Algorithms
To solve the efficient frontier of a portfolio, one version of the portfolio optimization
problem minimizes the portfolio risk Risk(x), subject to
a target return, and other linear constraints specified for the Portfolio, PortfolioCVaR, or PortfolioMAD object. For the definition of portfolio risk and return, see Risk Proxy and
Return Proxy.
An alternative version of the portfolio optimization problem maximizes the expected return
of the portfolio, subject to a target risk and other linear constraints specified for the
Portfolio, PortfolioCVaR, or PortfolioMAD object.
The return proxy is always a linear function. Therefore, depending on the risk proxy and
whether it is used as the objective or constraints, the problem needs to be solved by
different solvers. For example, quadprog is appropriate for problems with a
quadratic function as the objective and only linear constraints, and fmincon is appropriate for problems with nonlinear objective or constraints. In
addition, there are solvers in Financial Toolbox™ suitable for certain special types of problems, such as the
solverType
lcprog, 'TrustRegionCP', or
'ExtendedCP'.
References
[1] Kelley, J. E. "The Cutting-Plane Method for Solving Convex Programs." Journal of the Society for Industrial and Applied Mathematics. Vol. 8, No. 4, December 1960, pp. 703–712.
[2] Rockafellar, R. T. and S. Uryasev "Optimization of Conditional Value-at-Risk." Journal of Risk. Vol. 2, No. 3, Spring 2000, pp. 21–41.
[3] Rockafellar, R. T. and S. Uryasev "Conditional Value-at-Risk for General Loss Distributions." Journal of Banking and Finance. Vol. 26, 2002, pp. 1443–1471.
Version History
Introduced in R2011aThe default for name-value argument CutSelectionHeuristic for
specifying a cut selection heuristic changed to
CutSelectionHeuristic='quantile'. To use the old cut
selection heuristic, use
CutSelectionHeuristic='violation'.
setSolver has a new name-value argument
QuantileThreshold to set the quantile threshold for the new
'quantile' heuristic.
The default for the new quantile-based cut heuristic for the property
MaxIterationsInactiveCut is now 1. The default for
the old violation-based cut heuristic for the property
MaxIterationsInactiveCut remains 30.
The updated default value of setSolver for the
Portfolio object is quadprog (instead of
lcprog). To get the previous behavior, use setSolver
to set the input argument solverType to lcprog.
The updated default options for the name-value argument
MainSolverOptions is
optimoptions('linprog','Algorithm','dual-simplex-highs','Display','off').
When using a solverType of 'TrustRegionCP', you
can use the name-value argument 'DeltaLowerBound' to set the lower bound
for the trust-region radius.
The 'MasterSolverOptions' name-value
argument is renamed to 'MainSolverOptions'. The use of
'MasterSolverOptions' name-value argument
is discouraged.
See Also
getOneWayTurnover | setTurnover | setInitPort | setCosts | setSolverMINLP
Topics
- Working with One-Way Turnover Constraints Using Portfolio Object
- Working with One-Way Turnover Constraints Using PortfolioCVaR Object
- Working with One-Way Turnover Constraints Using PortfolioMAD Object
- Portfolio Optimization Examples Using Financial Toolbox
- Supported Constraints for Portfolio Optimization Using Portfolio Objects
- Supported Constraints for Portfolio Optimization Using PortfolioCVaR Object
- Supported Constraints for Portfolio Optimization Using PortfolioMAD Object
- Solver Guidelines for Portfolio Objects
- Choosing and Controlling the Solver for Mean-Variance Portfolio Optimization
- Choosing and Controlling the Solver for PortfolioCVaR Optimizations
- Choosing and Controlling the Solver for PortfolioMAD Optimizations
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)