To create a fully specified meanvariance portfolio optimization
problem, instantiate the Portfolio object using the Portfolio
function. For information on
the workflow when using Portfolio objects, see Portfolio Object Workflow.
Use the Portfolio
function
to create an instance of an object of the Portfolio
class.
You can use the Portfolio
function
in several ways. To set up a portfolio optimization problem in a Portfolio
object, the simplest syntax is:
p = Portfolio;
p
, such that
all object properties are empty. The Portfolio
function
also accepts collections of argument namevalue pair arguments for
properties and their values. The Portfolio
function
accepts inputs for public properties with the general syntax:
p = Portfolio('property1', value1, 'property2', value2, ... );
If a Portfolio object already exists, the syntax permits the
first (and only the first argument) of the Portfolio
function
to be an existing object with subsequent argument namevalue pair
arguments for properties to be added or modified. For example, given
an existing Portfolio object in p
, the general
syntax is:
p = Portfolio(p, 'property1', value1, 'property2', value2, ... );
Input argument names are not casesensitive, but must be completely
specified. In addition, several properties can be specified with alternative
argument names (see Shortcuts for Property Names). The Portfolio
function
tries to detect problem dimensions from the inputs and, once set,
subsequent inputs can undergo various scalar or matrix expansion operations
that simplify the overall process to formulate a problem. In addition,
a Portfolio object is a value object so that, given portfolio p
,
the following code creates two objects, p
and q
,
that are distinct:
q = Portfolio(p, ...)
A meanvariance portfolio optimization is completely specified with the Portfolio object if these two conditions are met:
The moments of asset returns must be specified such
that the property AssetMean
contains a valid finite
mean vector of asset returns and the property AssetCovar
contains
a valid symmetric positivesemidefinite matrix for the covariance
of asset returns.
The first condition is satisfied by setting the properties associated with the moments of asset returns.
The set of feasible portfolios must be a nonempty compact set, where a compact set is closed and bounded.
The second condition is satisfied by an extensive collection
of properties that define different types of constraints to form a
set of feasible portfolios. Since such sets must be bounded, either
explicit or implicit constraints can be imposed, and several functions,
such as estimateBounds
, provide
ways to ensure that your problem is properly formulated.
Although the general sufficiency conditions for meanvariance portfolio optimization go beyond these two conditions, the Portfolio object implemented in Financial Toolbox™ implicitly handles all these additional conditions. For more information on the Markowitz model for meanvariance portfolio optimization, see Portfolio Optimization.
If you create a Portfolio object, p
, with
no input arguments, you can display it using disp
:
p = Portfolio; disp(p); Portfolio
Portfolio with properties: BuyCost: [] SellCost: [] RiskFreeRate: [] AssetMean: [] AssetCovar: [] Turnover: [] BuyTurnover: [] SellTurnover: [] Name: [] NumAssets: [] AssetList: [] InitPort: [] AInequality: [] bInequality: [] AEquality: [] bEquality: [] LowerBound: [] UpperBound: [] LowerBudget: [] UpperBudget: [] GroupMatrix: [] LowerGroup: [] UpperGroup: [] GroupA: [] GroupB: [] LowerRatio: [] UpperRatio: []
The approaches listed provide a way to set up a portfolio optimization
problem with the Portfolio
function.
The set functions offer additional ways to set and modify collections
of properties in the Portfolio object.
You can use the Portfolio
function
to directly set up a "standard" portfolio optimization
problem, given a mean and covariance of asset returns in the variables m
and C
:
m = [ 0.05; 0.1; 0.12; 0.18 ]; C = [ 0.0064 0.00408 0.00192 0; 0.00408 0.0289 0.0204 0.0119; 0.00192 0.0204 0.0576 0.0336; 0 0.0119 0.0336 0.1225 ]; p = Portfolio('assetmean', m, 'assetcovar', C, ... 'lowerbudget', 1, 'upperbudget', 1, 'lowerbound', 0);
LowerBound
property
value undergoes scalar expansion since AssetMean
and AssetCovar
provide
the dimensions of the problem.You can use dot notation with the function plotFrontier
.
p.plotFrontier;
An alternative way to accomplish the same task of setting up
a "standard" portfolio optimization problem, given a
mean and covariance of asset returns in the variables m
and C
(which
also illustrates that argument names are not casesensitive):
m = [ 0.05; 0.1; 0.12; 0.18 ]; C = [ 0.0064 0.00408 0.00192 0; 0.00408 0.0289 0.0204 0.0119; 0.00192 0.0204 0.0576 0.0336; 0 0.0119 0.0336 0.1225 ]; p = Portfolio; p = Portfolio(p, 'assetmean', m, 'assetcovar', C); p = Portfolio(p, 'lowerbudget', 1, 'upperbudget', 1); p = Portfolio(p, 'lowerbound', 0); plotFrontier(p);
This way
works because the calls to the Portfolio
function
are in this particular order. In this case, the call to initialize AssetMean
and AssetCovar
provides
the dimensions for the problem. If you were to do this step last,
you would have to explicitly dimension the LowerBound
property
as follows:
m = [ 0.05; 0.1; 0.12; 0.18 ]; C = [ 0.0064 0.00408 0.00192 0; 0.00408 0.0289 0.0204 0.0119; 0.00192 0.0204 0.0576 0.0336; 0 0.0119 0.0336 0.1225 ]; p = Portfolio; p = Portfolio(p, 'LowerBound', zeros(size(m))); p = Portfolio(p, 'LowerBudget', 1, 'UpperBudget', 1); p = Portfolio(p, 'AssetMean', m, 'AssetCovar', C); plotFrontier(p);
If you did
not specify the size of LowerBound
but, instead,
input a scalar argument, the Portfolio
function
assumes that you are defining a singleasset problem and produces
an error at the call to set asset moments with four assets.
The Portfolio
function
has shorter argument names that replace longer argument names associated
with specific properties of the Portfolio object. For example, rather
than enter 'assetcovar'
, the Portfolio
function accepts the caseinsensitive
name 'covar'
to set the AssetCovar
property
in a Portfolio object. Every shorter argument name corresponds with
a single property in the Portfolio
function.
The one exception is the alternative argument name 'budget'
,
which signifies both the LowerBudget
and UpperBudget
properties.
When 'budget'
is used, then the LowerBudget
and UpperBudget
properties
are set to the same value to form an equality budget constraint.
Shortcuts for Property Names
Shortcut Argument Name  Equivalent Argument / Property Name 



























For example, this call to the Portfolio
function
uses these shortcuts for properties and is equivalent to the previous
examples:
m = [ 0.05; 0.1; 0.12; 0.18 ]; C = [ 0.0064 0.00408 0.00192 0; 0.00408 0.0289 0.0204 0.0119; 0.00192 0.0204 0.0576 0.0336; 0 0.0119 0.0336 0.1225 ]; p = Portfolio('mean', m, 'covar', C, 'budget', 1, 'lb', 0); plotFrontier(p);
Although not recommended, you can set properties directly, however no errorchecking is done on your inputs:
m = [ 0.05; 0.1; 0.12; 0.18 ]; C = [ 0.0064 0.00408 0.00192 0; 0.00408 0.0289 0.0204 0.0119; 0.00192 0.0204 0.0576 0.0336; 0 0.0119 0.0336 0.1225 ]; p = Portfolio; p.NumAssets = numel(m); p.AssetMean = m; p.AssetCovar = C; p.LowerBudget = 1; p.UpperBudget = 1; p.LowerBound = zeros(size(m)); plotFrontier(p);