Question: Cardinality Constraint for QP Matrix form

This question is related to the Question Maximize Risk Adjusted Return in QP Matrix Form

Ok, when I run the below code which maximize the risk adjuested portfolio returns
(long and short positions) in QP matrix form on empirical data I get very strange
allocations ie we go 100% or 100% short in almost all stocks except for a few
where the allocations are more appropriate like 0.2 etc.


# Maximize Risk Adjuested Return Matrix Form
# Minimize W'.Cov.W−W'.EV
# R=Return Matrix

EV := Vector([seq(ExpectedValue(Column(R, i)), i = 1 .. N)], datatype = float[8]):
A := Matrix([[seq(1, i = 1 .. N)]], datatype = float[8]):
b := Vector([1], datatype = float[8]):
bl := Vector(N, fill = -1, datatype = float[8]):
bu := Vector(N, fill = 1, datatype = float[8]):
sol1 := QPSolve([-EV, 2*Cov], [A, b], [bl, bu]); 

 

It is obvious that our constraint is not working for a long-short portfolio.
Now Robert has suggested a good way to impliment a cardinality constraint
when the problem is expresed in algebraic form by introducing a new varible
v[i]. The constraints are then:

seq(w[i] >= -1, i = 1 .. NC)    # NC=number of stocks
seq(w[i] seq(v[i] >= w[i], i = 1 .. NC)
seq(v[i] >= -w[i], i = 1 .. NC),
add(v[i], i = 1 .. NC) <= 2*PS   # PS=number of short positions=number of long positions
add(w[i], i = 1 .. NC) = 0

The question now becomes how to impliment that in QP matrix notation for
the previous problem or come up with another way to make sure that the
number of -1 and 1 are constrained (cardinality constraint) so we can get realistic allocations.

Please Wait...