A standard Quadratic Programming formulation for the optimal portfolio problem looks like:

min x'Qx
r'x >= R
Ax=b
x>=0

The Q matrix is often a variance-covariance matrix. r(i) is the return on investment instrument i and R is the required return on the portfolio. Several variations of the model have been proposed. For instance it is possible to investigate the trade-offs between risk and return by solving the model:

min x'Qx-lambda*r'x
Ax=b
x>=0

for different values of lambda. However this is not the subject of this example. In this series of models we present some reformulations of the standard QP model that give substantial computational savings.

This first model shows a standard QP model . The data is sitting in an include file qpdata.inc. The variance-covariance matrix is calculated based on these historical data. As this matrix is symmetric we only store the upper-triangular part. Therefore the objective function is split into two parts:

z=e=sum(upper(s,t), x(s)*covar(s,t)*x(t)) +
sum(lower(s,t), x(s)*covar(t,s)*x(t));

The syntax sum(upper(s,t),.... is probably new to many users. upper functions here as a filter on s and t. The summation is only performed over the s and t that are in upper. In this case the result is the same as we would have said: sum((s,t)\$upper(s,t),...

The sets upper and lower are calculated as follows:

upper(s,t)\$(ord(s) <= ord(t)) = YES;
lower(s,t)\$(ord(s) > ord(t)) = YES;