# constrained portfolio optimization by fmincon

I am working through this paper, http://www.nber.org/papers/w8922.pdf

I want to implement the portfolio weight constraints see page 6-7.

Here is the brief overview of my problem:

Let w be the set of weights representing a portfolio. Then, mean-variance problem is to find the portfolio weights that minimizes portfolio variance, argmin w'Sw subject to w'I = 1 which represents weights sum up to 1 and S is the estimated covariance matrix.

In this framework, portfolio weights are constrained by lower and upper bounds such as:

Then, the authors show that the following proposition is for the symmetric and positive semi-definite covariance matrix for the minimum global variance portfolios:

Here new covariance matrix is the shrunk version of S. I am trying to implement this in Matlab by fmincon function. I also add an target return constraint such as w'mean = rho where mean is column vector expected return of the assets and rho is the targetted return.

I create portrisk.m file for objective function:

function f = portrisk(w, covmat)
f = w'* covmat * w;
end


And nonlinear constraints are organized in constraint.m file file in matlab.

function [c,ceq] =  constraint (w)
c=[-w];                                % nonlinear inequality constraints
ceq = [];                              % nonlinear equality constraints
end


Here is the codes:

% initialization
x0=[ones(p,1)/p];                              % initialiazed to 1/p

% linear equality constraints (w'I=1, sum of the weights has to be 1 and target return)
Aeq = [meanx; repmat(1, 1, p)];                % matrix for linear equality constraints
rho = 0.0012
beq = [rho; 1];                                % vector for linear equality constraint

% upper and lower bound constraints
lb = zeros(p,1);
ub = ones(p,1);

% constraints as both less or higher than a constant
A = [repmat(1, 1, p); repmat(-1, 1, p) ];
b = [1; 0];

% options
options = optimoptions('fmincon','Algorithm','interior-point','Display','iter');

% run optimization function, lambda is the langrange multipliers
[w, fval, exitflag, output, lambda, grad, hessian]  = fmincon(@portrisk, x0 , A, b,
Aeq, beq, lb, ub,@constraint,options);


However, I could not get a solution. Could you help me where I am wrong? Thank you for any help.

• As a general rule, I would recommend starting with the simplest possible case and then making it more complicated. The only thing that sticks out to me is that when you use the portrisk function in fmincon you may not be passing the covmat variable with it. See the answer here: stackoverflow.com/questions/18946407/… – John May 18 '15 at 16:22

It is difficult to say what is not working with your code.

$$x = quadprog(H,f,A,b,Aeq,beq,lb,ub)$$