This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

setSolver

Choose main solver and specify associated solver options for portfolio optimization

Syntax

obj = setSolver(obj,solverType)
obj = setSolver(obj,solverType,Name,Value)
obj = setSolver(obj,solverType,optimoptions)

Description

example

obj = setSolver(obj,solverType) selects the main solver and enables you to specify associated solver options for portfolio optimization for 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.

example

obj = setSolver(obj,solverType,Name,Value) 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 Name,Value pair arguments.

example

obj = setSolver(obj,solverType,optimoptions) selects the main solver and enables you to specify associated solver options for portfolio optimization for portfolio objects with an optimoptions object.

Examples

collapse all

If you use the quadprog function as the solverType, the default is the interior-point-convex version of quadprog.

load CAPMuniverse
p = Portfolio('AssetList',Assets(1:12));
p = setDefaultConstraints(p);
p = setSolver(p, 'quadprog');
display(p.solverType);
quadprog

You can switch back to lcprog with:

p = setSolver(p, 'lcprog');
display(p.solverType);
lcprog

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 'cuttingplane' as the solverType with default options.

p = PortfolioCVaR;
p = setSolver(p,'cuttingplane');
display(p.solverType);
cuttingplane

Use the Name-Value pair 'MaxIter' to set the maximum number of iterations to 1500.

p = PortfolioCVaR;
p = setSolver(p,'cuttingplane','MaxIter',1500);
display(p.solverType);
cuttingplane
display(p.solverOptions);
                MaxIter: 1500
                 AbsTol: 1.0000e-06
                 RelTol: 1.0000e-05
    MasterSolverOptions: [1x1 optim.options.Linprog]

For the master solver, continue using the dual-simplex algorithm with no display, but tighten its termination tolerance to 1e-8.

p = PortfolioCVaR;
options = optimoptions('linprog','Algorithm','Dual-Simplex','Display','off','OptimalityTolerance',1e-8);
p = setSolver(p,'cuttingplane','MasterSolverOptions',options);
display(p.solverType)
cuttingplane
display(p.solverOptions)
                MaxIter: 1000
                 AbsTol: 1.0000e-06
                 RelTol: 1.0000e-05
    MasterSolverOptions: [1x1 optim.options.Linprog]
display(p.solverOptions.MasterSolverOptions.Algorithm)
dual-simplex
display(p.solverOptions.MasterSolverOptions.Display)
off
display(p.solverOptions.MasterSolverOptions.TolFun)
   1.0000e-08

For the master solver, use the interior-point algorithm with no display, and with a termination tolerance of 1e-7.

p = PortfolioCVaR;
options = optimoptions('linprog','Algorithm','interior-point','Display','off','OptimalityTolerance',1e-7);
p = setSolver(p,'cuttingplane','MasterSolverOptions',options);
display(p.solverType)
cuttingplane
display(p.solverOptions)
                MaxIter: 1000
                 AbsTol: 1.0000e-06
                 RelTol: 1.0000e-05
    MasterSolverOptions: [1x1 optim.options.Linprog]
display(p.solverOptions.MasterSolverOptions.Algorithm)
interior-point
display(p.solverOptions.MasterSolverOptions.Display)
off
display(p.solverOptions.MasterSolverOptions.TolFun)
   1.0000e-07

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

collapse all

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.

For a Portfolio object, the supported solverType are:

  • 'lcprog' (Default).

    • The 'lcprog' solver uses linear complementary programming with Lemke's algorithm with control variables name-value pair arguments for 'maxiter', 'tiebreak', 'tolpiv'. For more information about 'lcprog' name-value pair options, see Portfolio Object Name-Value Pair Arguments.

  • 'fmincon'

  • 'quadprog'

For a PortfolioCVaR object, the supported solverType are:

  • 'fmincon' (Default)

  • 'cuttingplane'

    • The 'cuttingplane' solver is an implementation of Kelley's [1] cutting-plane method for convex optimization with name-value pair arguments for 'MaxIter', 'Abstol', 'Reltol' and 'MasterSolverOptions'. For more information about 'cuttingplane' name-value pair options, see PortfolioCVaR Object Name-Value Pair Arguments.

For a PortfolioMAD object, the supported solverType are:

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'. For more information about 'linprog' name-value pair options, see Name-Value Pair 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 Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: p = setSolver(p,'cuttingplane','MasterSolverOptions',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 pair arguments are different.

Portfolio Object Name-Value Pair Arguments

  • For a Portfolio object using a solverType of lcprog, choose a name-value value in this table.

    ValueDescription
    'maxiter'

    Maximum number of iterations,specified as the comma-separated pair consisting of 'MaxIter' and a positive integer. The default value is 1 + 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 is 1.0e-9.

  • For a Portfolio object using a solverType of fmincon, see options (Optimization Toolbox) to choose name-value pair arguments.

  • For a Portfolio object using a solverType of linprog, see options (Optimization Toolbox) to choose name-value pair arguments.

  • For a Portfolio object using a solverType of quadprog, see options (Optimization Toolbox) to choose name-value pair arguments.

PortfolioCVaR Object Name-Value Pair Arguments

  • For a PortfolioCVaR object using a solverType of fmincon, see options (Optimization Toolbox) to choose name-value pair arguments.

  • For a PorfolioCVaR object using a solverType of 'cuttingplane', choose a name-value pair value in this table.

    ValueDescription
    'MaxIter'

    Maximum number of iterations, specified as the comma-separated pair consisting of 'MaxIter' and a positive integer. The default value is 1000.

    'AbsTol'

    Absolute stopping tolerance, specified as the comma-separated pair consisting of 'AbsTol' and a positive scalar. The default value is 1e-6.

    'RelTol'

    Relative stopping tolerance, specified as the comma-separated pair consisting of 'RelTol' and a positive scalar. The default value is 1e-5.

    'MasterSolverOptions'

    Options for the master solver linprog, specified as the comma-separated pair consisting of 'MasterSolverOptions' and an optimoptions object. The default is optimoptions('linprog','Algorithm','Dual-Simplex','Display','off').

  • For a PortfolioCVaR object using a solverType of linprog, see options (Optimization Toolbox) to choose name-value pair arguments.

PortfolioMAD Object Name-Value Pair Arguments

  • For a PortfolioMAD object using a solverType of fmincon, see options (Optimization Toolbox) to choose name-value pair arguments.

  • For a PortfolioMAD object using a solverType of linprog, see options (Optimization Toolbox) to choose name-value pair arguments.

Output Arguments

collapse all

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.

MinimizexRisk(x)subject to  Return(x)TargetReturnAxbAeqx=beqlbxub

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.

MaximizexReturn(x)subject to  Risk(x)TargetRiskAxbAeqx=beqlbxub

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 and cuttingplane.

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.

Introduced in R2011a