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.

setMinMaxNumAssets

Set cardinality constraints on the number of assets invested in a Portfolio object

Syntax

obj = setMinMaxNumAssets(obj,MinNumAssets,MaxNumAssets)

Description

example

obj = setMinMaxNumAssets(obj,MinNumAssets,MaxNumAssets) sets cardinality constraints for a Portfolio object. MinNumAssets and MaxNumAssets are the minimum and maximum number of assets invested in the portfolio, respectively. The total number of allocated assets satisfying the Bound constraints is between [MinNumAssets, MaxNumAssets]. For details on the workflow when using a Portfolio object, see Portfolio Object Workflow.

Examples

collapse all

Set the maximum cardinality constraint for a three-asset portfolio for which you have the mean and covariance values of the asset returns.

AssetMean = [ 0.0101110; 0.0043532; 0.0137058 ];
AssetCovar = [ 0.00324625 0.00022983 0.00420395;
               0.00022983 0.00049937 0.00019247;
               0.00420395 0.00019247 0.00764097 ]; 
           
p = Portfolio('AssetMean', AssetMean, 'AssetCovar', AssetCovar);
p = setDefaultConstraints(p); 

When working with a Portfolio object, the setMinMaxNumAssets function enables you to set up the limits on the number of assets invested. Use setMinMaxNumAssets to limit the total number of allocated assets to no more than two.

 p = setMinMaxNumAssets(p, [], 2);

Use estimateFrontierByReturn to estimate optimal portfolios with targeted portfolio returns.

pwgt = estimateFrontierByReturn(p,[ 0.008, 0.01 ])
pwgt = 3×2

         0         0
    0.6101    0.3962
    0.3899    0.6038

Set the minimum cardinality constraint for a three-asset portfolio for which you have the mean and covariance values of the asset returns.

AssetMean = [ 0.0101110; 0.0043532; 0.0137058 ];
AssetCovar = [ 0.00324625 0.00022983 0.00420395;
               0.00022983 0.00049937 0.00019247;
               0.00420395 0.00019247 0.00764097 ];  
           
p = Portfolio('AssetMean', AssetMean, 'AssetCovar', AssetCovar);
p = setDefaultConstraints(p); 

When working with a Portfolio object, the setMinMaxNumAssets function enables you to set up limits on the number of assets invested. These limits are also known as cardinality constraints. When managing a portfolio, it is common that you want to invest in at least a certain number of assets. In addition, you should also clearly define the weight requirement for each invested asset. You can do this using setBounds with a 'Conditional' BoundType. If you do not specify a 'Conditional' BoundType, the optimizer cannot understand which assets are invested assets and cannot formulate the MinNumAssets constraint.

The following example specifies that at least two assets should be invested and the investments should be greater than 16%.

p = setMinMaxNumAssets(p, 2, []);  
p = setBounds(p, 0.16, 'BoundType', 'conditional');

Use estimateFrontierByReturn to estimate optimal portfolios with targeted portfolio returns.

pwgt = estimateFrontierByReturn(p,[ 0.008, 0.01 ])
pwgt = 3×2

    0.2861    0.3967
    0.5001    0.2438
    0.2138    0.3595

Set the minimum and maximum cardinality constraints and a 'Conditional' BoundType for a three-asset portfolio for which you have the mean and covariance values of the asset returns.

AssetMean = [ 0.0101110; 0.0043532; 0.0137058 ];
AssetCovar = [ 0.00324625 0.00022983 0.00420395;
               0.00022983 0.00049937 0.00019247;
               0.00420395 0.00019247 0.00764097 ];  
           
p = Portfolio('AssetMean', AssetMean, 'AssetCovar', AssetCovar);
p = setDefaultConstraints(p); 

When working with a Portfolio object, the setMinMaxNumAssets function enables you to set up the limits on the number of assets invested. The following example specifies that exactly two assets should be invested using setMinMaxNumAssets and the investment should be equally allocated among the two assets using setBounds.

p = setMinMaxNumAssets(p, 2, 2);  
p = setBounds(p, 0.5, 0.5, 'BoundType', 'conditional'); 

Use estimateFrontierByReturn to estimate optimal portfolios with targeted portfolio returns.

pwgt = estimateFrontierByReturn(p,[ 0.008, 0.01 ])
pwgt = 3×2

         0    0.5000
    0.5000         0
    0.5000    0.5000

Input Arguments

collapse all

Object for portfolio, specified using a Portfolio object. For more information on creating a portfolio object, see Portfolio.

Data Types: object

Minimum number of assets allocated in the portfolio, specified using a scalar numeric.

Data Types: double

Maximum number of assets allocated in the portfolio, specified using a scalar numeric.

Data Types: double

Output Arguments

collapse all

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

Tips

  • You can also use dot notation to set up a list of identifiers for assets.

    obj = obj.setMinMaxNumAssets(MinNumAssets,MaxNumAssets);

  • Specifying empty values ([[]) for MinNumAssets and MaxNumAsssets removes limit constraints from the Portfolio object.

Introduced in R2018b