Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

Portfolio

Create Portfolio object for mean-variance portfolio optimization

Use the Portfolio function to create a Portfolio object for mean-variance portfolio optimization. For more information, see Portfolio.

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;
This syntax creates a Portfolio object, p, such that all object properties are empty.

The Portfolio function also accepts collections of argument name-value pair arguments for properties and their values. The Portfolio function accepts inputs for properties with the general syntax:

	p = Portfolio('property1', value1, 'property2', value2, ... );

If a Portfolio object exists, the syntax permits the first (and only the first argument) of the Portfolio function to be an existing object with subsequent argument name-value 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 case-sensitive, 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, ...)

After creating a Portfolio object, you can use the associated object functions to set portfolio constraints, analyze the efficient frontier, and validate the portfolio model.

For details on this workflow, see Portfolio Object Workflow and for more detailed information on the theoretical basis for mean-variance optimization, see Portfolio Optimization Theory.

Syntax

  • p = Portfolio(p,Name,Value)
    example

Description

example

p = Portfolio constructs an empty Portfolio object for mean-variance portfolio optimization and analysis. You can then add elements to the Portfolio object using the supported add and set functions. For more information, see Creating the Portfolio Object..

example

p = Portfolio(Name,Value) constructs a Portfolio object for mean-variance portfolio optimization and analysis with additional options specified by one or more Name,Value arguments.

example

p = Portfolio(p,Name,Value) constructs a Portfolio object for mean-variance portfolio optimization and analysis using a previously constructed Portfolio object p with additional options specified by one or more Name,Value arguments.

Examples

collapse all

You can create a Portfolio object, p, with no input arguments and display it using disp.

p = Portfolio;
disp(p);
  Portfolio with properties:

          BuyCost: []
         SellCost: []
     RiskFreeRate: []
        AssetMean: []
       AssetCovar: []
    TrackingError: []
     TrackingPort: []
         Turnover: []
      BuyTurnover: []
     SellTurnover: []
             Name: []
        NumAssets: []
        AssetList: []
         InitPort: []
      AInequality: []
      bInequality: []
        AEquality: []
        bEquality: []
       LowerBound: []
       UpperBound: []
      LowerBudget: []
      UpperBudget: []
      GroupMatrix: []
       LowerGroup: []
       UpperGroup: []
           GroupA: []
           GroupB: []
       LowerRatio: []
       UpperRatio: []

This approach provides a way to set up a portfolio optimization problem with the Portfolio function. You can then use the associated set functions to set and modify collections of properties in the Portfolio object.

You can use the Portfolio function 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)
p = 

  Portfolio with properties:

          BuyCost: []
         SellCost: []
     RiskFreeRate: []
        AssetMean: [4×1 double]
       AssetCovar: [4×4 double]
    TrackingError: []
     TrackingPort: []
         Turnover: []
      BuyTurnover: []
     SellTurnover: []
             Name: []
        NumAssets: 4
        AssetList: []
         InitPort: []
      AInequality: []
      bInequality: []
        AEquality: []
        bEquality: []
       LowerBound: [4×1 double]
       UpperBound: []
      LowerBudget: 1
      UpperBudget: 1
      GroupMatrix: []
       LowerGroup: []
       UpperGroup: []
           GroupA: []
           GroupB: []
       LowerRatio: []
       UpperRatio: []

Note that the LowerBound property value undergoes scalar expansion since AssetMean and AssetCovar provide the dimensions of the problem.

Using a sequence of steps is 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 case sensitive).

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 single-asset problem and produces an error at the call to set asset moments with four assets.

You can create a Portfolio object, p with the Portfolio function using shortcuts for property names.

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)
p = 

  Portfolio with properties:

          BuyCost: []
         SellCost: []
     RiskFreeRate: []
        AssetMean: [4×1 double]
       AssetCovar: [4×4 double]
    TrackingError: []
     TrackingPort: []
         Turnover: []
      BuyTurnover: []
     SellTurnover: []
             Name: []
        NumAssets: 4
        AssetList: []
         InitPort: []
      AInequality: []
      bInequality: []
        AEquality: []
        bEquality: []
       LowerBound: [4×1 double]
       UpperBound: []
      LowerBudget: 1
      UpperBudget: 1
      GroupMatrix: []
       LowerGroup: []
       UpperGroup: []
           GroupA: []
           GroupB: []
       LowerRatio: []
       UpperRatio: []

Although not recommended, you can set properties directly, however no error-checking 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));
disp(p)
  Portfolio with properties:

          BuyCost: []
         SellCost: []
     RiskFreeRate: []
        AssetMean: [4×1 double]
       AssetCovar: [4×4 double]
    TrackingError: []
     TrackingPort: []
         Turnover: []
      BuyTurnover: []
     SellTurnover: []
             Name: []
        NumAssets: 4
        AssetList: []
         InitPort: []
      AInequality: []
      bInequality: []
        AEquality: []
        bEquality: []
       LowerBound: [4×1 double]
       UpperBound: []
      LowerBudget: 1
      UpperBudget: 1
      GroupMatrix: []
       LowerGroup: []
       UpperGroup: []
           GroupA: []
           GroupB: []
       LowerRatio: []
       UpperRatio: []

Create efficient portfolios:

load CAPMuniverse

p = Portfolio('AssetList',Assets(1:12));
p = estimateAssetMoments(p, Data(:,1:12),'missingdata',true);
p = setDefaultConstraints(p);
plotFrontier(p);

pwgt = estimateFrontier(p, 5);

pnames = cell(1,5);
for i = 1:5
	pnames{i} = sprintf('Port%d',i);
end

Blotter = dataset([{pwgt},pnames],'obsnames',p.AssetList);

disp(Blotter);
            Port1        Port2       Port3       Port4      Port5
    AAPL     0.017926    0.058247    0.097816    0.12955    0    
    AMZN            0           0           0          0    0    
    CSCO            0           0           0          0    0    
    DELL    0.0041906           0           0          0    0    
    EBAY            0           0           0          0    0    
    GOOG      0.16144     0.35678     0.55228    0.75116    1    
    HPQ      0.052566    0.032302    0.011186          0    0    
    IBM       0.46422     0.36045     0.25577    0.11928    0    
    INTC            0           0           0          0    0    
    MSFT      0.29966     0.19222    0.082949          0    0    
    ORCL            0           0           0          0    0    
    YHOO            0           0           0          0    0    

Related Examples

Input Arguments

collapse all

Previously constructed Portfolio object, specified using the Portfolio function

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.

Example: p = Portfolio('AssetList',Assets(1:12));

collapse all

Linear equality constraint matrix, specified as a matrix.

Data Types: double

Linear inequality constraint matrix, specified as a matrix.

Data Types: double

Covariance of asset returns, specified as a square matrix.

Data Types: double

Names or symbols of assets in the universe, specified as a cell array of character vectors.

Data Types: cell

Mean of asset returns, specified as a vector.

Data Types: double

Linear equality constraint vector, specified as a vector.

Data Types: double

Linear inequality constraint vector, specified as a vector.

Data Types: double

Proportional purchase costs, specified as a vector.

Data Types: double

Turnover constraint on purchases, specified as a scalar.

Data Types: double

Group A weights to be bounded by weights in group B, specified as a matrix.

Data Types: double

Group B weights, specified as a matrix.

Data Types: double

Group membership matrix, specified as a matrix.

Data Types: double

Initial portfolio, specified as a vector.

Data Types: double

Lower-bound constraint, specified as a vector.

Data Types: double

Lower-bound budget constraint, specified as a scalar.

Data Types: double

Lower-bound group constraint, specified as a vector.

Data Types: double

Minimum ratio of allocations between GroupA and GroupB, specified as a vector.

Data Types: double

Name for instance of the Portfolio object, specified as a character vector.

Data Types: char

Number of assets in the universe, specified as an integer scalar.

Data Types: double

Risk-free rate, specified as a scalar.

Data Types: double

Proportional sales costs, specified as a vector.

Data Types: double

Turnover constraint on sales, specified as a scalar.

Data Types: double

Upper bound for tracking error constraint, specified as a scalar.

Data Types: double

Tracking portfolio for tracking error constraint, specified as a vector.

Data Types: double

Turnover constraint, specified as a scalar.

Data Types: double

Upper-bound constraint, specified as a vector.

Data Types: double

Upper-bound budget constraint, specified as a scalar.

Data Types: double

Upper-bound group constraint, specified as a vector.

Data Types: double

Maximum ratio of allocations between GroupA and GroupB, specified as a vector.

Data Types: double

Output Arguments

collapse all

Updated portfolio object, returned as a Portfolio, For more information on using the Portfolio object, see Portfolio.

More About

collapse all

Mean-Variance Portfolio Optimization

For more information on the theory and definition of mean-variance optimization supported by portfolio optimization tools in Financial Toolbox™, see Portfolio Optimization Theory.

Portfolio Problem Sufficiency

A mean-variance 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 AssetMean contains a valid symmetric positive-semidefinite 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 mean-variance 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 mean-variance portfolio optimization, see Portfolio Optimization.

Shortcuts for Property Names

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 case-insensitive 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

ae

AEquality

ai

AInequality

covar

AssetCovar

assetnames or assets

AssetList

mean

AssetMean

be

bEquality

bi

bInequality

group

GroupMatrix

lb

LowerBound

n or num

NumAssets

rfr

RiskFreeRate

ub

UpperBound

budget

UpperBudget and LowerBudget

References

For a complete list of references for the Portfolio object, see Portfolio Optimization.

Introduced in R2011a

Was this topic helpful?