Using quadprog to minimize assigned scores to portfolio of both long and short weights

74 Views Asked by At

I am using quadratic programming (quadprog in Matlab) to minimize the variance of a portfolio where the weights can go both long and short, i.e. $-1/n < w_i < 3/n$ and $sum(w_1,...,w_n)=1$.

The different weights are assigned scores on beforehand so that if you go long in asset $(w_1, w_2, w_3, w_4)$ they have scores (1, 2, 3, 4) and if you go short in asset $(w_1, w_2, w_3, w_4)$ they have scores (4, 3, 2, 1), the inverse score. Now, what I want to do is both minimize the variance and the score I mentioned above. The variance part is minimized correctly by building a sigma and using quadprog but the score minimization is where I have problems.

To minimize the score I loop over different total scores and let those be a Beq constraint, hence the individual scores are in Aeq: $Aeq*w=Beq$.

Let's say I decide on beforehand to short asset $w_3$ and $w_4$ and go long in $w_1$ and $w_2$ (to get as low total score as possible). Then:

$$Aeq = (1,2,-2,-1)$$

The last two scores gets negative values since I set those weights to be in a limit of $-1/n < w < 0$ and if you multiply them the result is a positive score.

What is really the problem here is that when I loop over as low Beq as possible and take out those weights, quadprog computes the negative weights as $-1e-10$, i.e. zero. I want to create a portfolio that minimizes the variance as well as go both long and short but since all weights sum up to one, the total score increases the more you go short:

$$(0.75, 0.75, -0.25, -0.25) * (1, 2, -2, -1) > (0.5, 0.5, -1e-10, 1e-10) * (1, 2, -2, -1)$$

Now, one could say that I could just change the constraints so that $sum(abs(w_1, ..., w_n))=1$ which would normalize the score but that makes some other constraints I have to not work that well, for example that $w_1+w_3 = 0.7$ and $w_2+w_4 = 0.3$.

I have also tried forcing quadprog to short more by saying that, for the example above, $w_3+w_4<-0.1$ but that does not feel like an optimal solution.

I am very grateful for any thoughts regarding this problem!