Class: Portfolio

Choose main solver and specify associated solver options for portfolio optimization


obj = setSolver(obj,solverType)
obj = setSolver(obj,solverType,varargin)


obj = setSolver(obj,solverType) chooses the solver for portfolio optimization.

obj = setSolver(obj,solverType,varargin) chooses the solver and specifies associated solver options with additional options specified by one or more Name,Value pair arguments or an optimoptions object.

After you specify a solver, the varargin argument accepts either name-value pair arguments to set options or, for the case of solvers from Optimization Toolbox™ software, a structure created by optimoptions.


You can also use dot notation to choose the solver and specify associated solver options.

obj = obj.setSolver(solverType, varargin);

Input Arguments


Portfolio object [Portfolio].


Solver to use for portfolio optimization [string]. The default solver for the Portfolio object is 'lcprog' with the control variables 'maxiter', 'tiebreak', 'tolpiv'.

Default: 'lcprog'

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 single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.


Options to control the solver specified in solverType as name-value pair arguments or an optimoptions object. Note, optimoptions is the default and recommended method to set solver options, however optimset is also supported.

    Note:   The default solver for the Portfolio object is 'lcprog'. The Portfolio object can also use 'quadprog', which has several different options that can be set with optimoptions. Unlike Optimization Toolbox software which uses the trust-region-reflective algorithm as the default algorithm for quadprog, the portfolio optimization tools use the interior-point-convex algorithm. For more information about quadprog and quadratic programming algorithms and options, see Quadratic Programming Algorithms.

Output Arguments


Updated Portfolio object [Portfolio].



To learn about attributes of methods, see Method Attributes in the MATLAB® Object-Oriented Programming documentation.


expand all

Set Solver Type

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');

You can switch back to lcprog with:

p = setSolver(p, 'lcprog');
Was this topic helpful?