Formulating Constrained Minimum-Variance Portfolios in MATLAB
Summary
The document describes a mean-variance allocation problem that minimizes portfolio variance under a full-investment constraint, weight bounds, and an optional target-return constraint. It also mentions a covariance shrinkage result for minimum global variance portfolios and shows an attempted MATLAB implementation using fmincon with a quadratic objective and linear constraints.
The response recommends MATLAB’s quadprog because the objective is quadratic and the constraints are linear, making it a specialized fit for this optimization. It provides the solver’s general input structure but does not diagnose the original implementation or give a corrected formulation. The source paper’s proposition and the specific constraint setup are not explained in enough detail to assess the shrinkage result or determine why fmincon failed.
Key ideas
- Minimum-variance allocation minimizes portfolio variance subject to investment and risk constraints.
- Weight bounds, a target return, and a full-investment condition can be expressed as optimization constraints.
- A quadratic programming solver is suggested for this quadratic objective with linear constraints.
- The brief answer does not identify the specific error in the submitted MATLAB formulation.
Tags
Full text
# constrained portfolio optimization by fmincon
# 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.
## Answer by jaamor (score 3)
https://quant.stackexchange.com/a/16608
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) $$Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.