%% Configure MINLP Solver and Options When Using a Portfolio Object
% Configure the MINLP solver 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);

% When working with a Portfolio object, use setBounds with a 'Conditional'BoundType constraint 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, use setMinMaxNumAssets function to set up MinNumAssets and MaxNumAssets constraints for a portfolio. This sets limit constraints for the Portfolio object, where the total number of allocated assets satisfying the constraints is between MinNumAssets and MaxNumAssets. Setting MinNumAssets = MaxNumAssets = 2, specifies that only two of the three assets are invested in the portfolio.

p = setMinMaxNumAssets(p, 2, 2); 

% Three different MINLP solvers (OuterApproximation, ExtendedCP, TrustRegionCP) use the cutting plane method. Use the setSolverMINLP function to configure the OuterApproximation solver and options.

pint = setSolverMINLP(p,'OuterApproximation', 'NonlinearScalingFactor', 1e4, 'Display', 'iter', 'CutGeneration', 'basic');
pint.solverTypeMINLP
pint.solverOptionsMINLP

% You can also configure the options for intlinprog,which is the Master solver for mixed integer linear programming problems in the MINLP solver.

pint = setSolverMINLP(p,'OuterApproximation', 'IntMasterSolverOptions', optimoptions('intlinprog','Display','off'));
pint.solverOptionsMINLP.IntMasterSolverOptions

% Copyright 2018 The MathWorks, Inc.