Main Content

setMinMaxNumAssets

Set cardinality constraints on the number of assets invested in a portfolio

Description

example

obj = setMinMaxNumAssets(obj,MinNumAssets,MaxNumAssets) sets cardinality constraints for a Portfolio, PortfolioCVaR, or PortfolioMAD 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 respective workflows when using these different objects, see Portfolio Object Workflow, PortfolioCVaR Object Workflow, and PortfolioMAD 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.2437
    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

Suppose you have a universe of 12 stocks where you want to find the optimal portfolios with targeted returns and you want to set semicontinuous and cardinality constraints for the portfolio.

load CAPMuniverse
p = PortfolioCVaR('AssetList',Assets(1:12));
p = simulateNormalScenariosByData(p, Data(:,1:12), 20000 ,'missingdata',true);
p = setProbabilityLevel(p, 0.80);

When working with a PortfolioCVaR object, the setMinMaxNumAssets function enables you to set up the limits on the number of assets invested. The following example specifies that a minimum of five assets and a maximum of 10 assets should be invested using setMinMaxNumAssets and the investments should be greater than 4% and less than 45% using setBounds.

p = setMinMaxNumAssets(p, 5, 10);  
p = setBounds(p, 0.04, 0.45, 'BoundType', 'conditional'); 

Use estimateFrontierByReturn to estimate optimal portfolios with targeted portfolio returns.

pwgt = estimateFrontierByReturn(p,[ 0.00026, 0.00038 ])
pwgt = 12×2

    0.0400    0.0400
         0         0
         0         0
         0         0
         0         0
    0.0507    0.0786
    0.0400    0.0400
    0.0400    0.0400
         0         0
    0.0400    0.0400
      ⋮

Suppose you have a universe of 12 stocks where you want to find the optimal portfolios with targeted returns and you want to set semicontinuous and cardinality constraints for the portfolio.

load CAPMuniverse
p = PortfolioMAD('AssetList',Assets(1:12));
p = simulateNormalScenariosByData(p, Data(:,1:12), 20000 ,'missingdata',true);

When working with a PortfolioMAD object, the setMinMaxNumAssets function enables you to set up the limits on the number of assets invested. The following example specifies that a minimum of five assets and a maximum of 10 assets should be invested using setMinMaxNumAssets and the investments should be greater than 4% and less than 45% using setBounds.

p = setMinMaxNumAssets(p, 5, 10);  
p = setBounds(p, 0.04, 0.45, 'BoundType', 'conditional'); 

Use estimateFrontierByReturn to estimate optimal portfolios with targeted portfolio returns.

pwgt = estimateFrontierByReturn(p,[ 0.00026, 0.00038 ])
pwgt = 12×2

    0.0400    0.0400
    0.0400         0
         0         0
         0         0
         0         0
    0.0439    0.0786
         0    0.0400
    0.0400    0.0400
         0         0
    0.0400    0.0400
      ⋮

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

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, PortfolioCVaR, or PortfolioMAD object.

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, PortfolioCVaR, or PortfolioMAD object.

Version History

Introduced in R2018b