%% Estimate the Mean of Portfolio Returns for a Portfolio Object with Integrality Constraints
% Create a Portfolio object for three assets.

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

% Use setBounds with semi-continuous constraints to set xi=0 or 0.02<=xi<=0.5 for all i=1,...NumAssets.

p = setBounds(p, 0.02, 0.5,'BoundType', 'Conditional', 'NumAssets', 3);                    

% When working with a Portfolio object, the setMinMaxNumAssets function enables you to set up cardinality constraints for a long-only portfolio. This sets the cardinality constraints for the Portfolio object, where the total number of allocated assets satisfying the nonzero semi-continuous constraints are between MinNumAssets and MaxNumAssets. By setting MinNumAssets=MaxNumAssets=2, only two of the three assets are invested in the portfolio.

p = setMinMaxNumAssets(p, 2, 2);  

% Use estimatePortReturn to estimate the mean of portfolio returns for a Portfolio object.

pwgt = estimateFrontierLimits(p);
pret = estimatePortReturn(p, pwgt)

% The estimatePortReturn function uses the MINLP solver to solve this problem. Use the setSolverMINLP function to configure the SolverType and options.

p.solverOptionsMINLP

% Copyright 2018 The MathWorks, Inc.