5
$\begingroup$

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: enter image description here enter image description here

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

enter image description here

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.

$\endgroup$
1
  • 1
    $\begingroup$ 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/… $\endgroup$
    – John
    May 18, 2015 at 16:22

1 Answer 1

3
$\begingroup$

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

Try Matlab's quadratic programming function quadprog() instead. This function specializes in solving this optimization problem.

The syntax is:

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

$\endgroup$
6
  • $\begingroup$ Everything seems normal with the code. I check and compare with the other codes written with fmincon but I could not figure out what is wrong. Thank you very much for the comment. I will try quadprog as well. $\endgroup$
    – active
    Feb 17, 2015 at 16:59
  • $\begingroup$ I think quadprog requires positive definite covariance matrix. My covariance matrix is not positive definite that's why I am constructing a new shrunk matrix of consisted of combined version of lagrange multipliers and old covariance matrix. In this sense it seems impracticable. Which method should I use else? $\endgroup$
    – active
    Feb 17, 2015 at 23:14
  • $\begingroup$ You need a positive definite covariance matrix to do QP. $\endgroup$
    – jaamor
    Feb 18, 2015 at 19:48
  • $\begingroup$ In the new constructed (S tilda) covariance matrix formulation above we need lagrange multipliers which are obtained from the solving quadratic function. This created matrix is going to be positive-deifinite. I think I need global optimizer that does not require positive deficency to solve the function in order to get multipliers, but I do not know which one. $\endgroup$
    – active
    Feb 18, 2015 at 20:31
  • $\begingroup$ There are methods with which you can repair your covariance matrix to make it positive definite without a large loss of precision. $\endgroup$
    – jaamor
    Feb 20, 2015 at 1:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.