%% Estimate Efficient Portfolio that Maximizes the Sharpe Ratio for a Portfolio Object Using Solver Options with the Direct Method
% Estimate the efficient portfolio that maximizes the Sharpe ratio. The estimateMaxSharpeRatio function maximizes the Sharpe ratio among portfolios on the efficient frontier. This example uses the 'direct' method for a Portfolio object (p) that does not specify a tracking error and only uses linear constraints. The setSolver function is used to control the SolverType and SolverOptions. In this case, the SolverType is quadprog. For more information on the 'direct' method, see Algorithms.

p = Portfolio('AssetMean',[0.3, 0.1, 0.5], 'AssetCovar',...
[0.01, -0.010,  0.004; -0.010,  0.040, -0.002;  0.004, -0.002,  0.023]);
p = setDefaultConstraints(p);
plotFrontier(p, 20);
p = setSolver(p,'quadprog','Display','off','ConstraintTolerance',1.0e-8,'OptimalityTolerance',1.0e-8,'StepTolerance',1.0e-8,'MaxIterations',10000); 
weights = estimateMaxSharpeRatio(p); 
[risk, ret] = estimatePortMoments(p, weights);
hold on
plot(risk,ret,'*r');

% Copyright 2012 The MathWorks, Inc.