%% Create a Portfolio Object Using a Sequence of Steps
% 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 Portfolio 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 object assumes that you are defining a single-asset problem and produces an error at the call to set asset moments with four assets.
% Copyright 2015 The MathWorks, Inc.