Help with constraints in a optimazation problem?

• To: mathgroup at smc.vnet.net
• Subject: [mg60331] Help with constraints in a optimazation problem?
• From: jpahka at welho.com
• Date: Tue, 13 Sep 2005 06:07:14 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```
Hello,

The problem: I have a portfolio of around 250 equities. And I have daily returns
for both the indivitual equities as well as the whole portfolio from around two
years. And I'd like to replicate the return of the portfolio as closely as
possible by using, say 20 equities.

As a start I thought of using NMinimize to minimize tracking error (ie. sum of
squares of the return difference) between this 20 equity portfolio and the
original portfolio.

So, I have the returns in a matrix so that the first column of the matrix is the
return of the whole portfolio followed by the returns of the individual
equities. Lets call this matrix as "ret". And I have a vector "weights" as the
equity weights of the new portfolio.

So, the function to minimize would be something like:

func[ret_List, weights_List]:=Plus@@(((weights.Rest[#] - First[#])^2)&/@ret);

subject to constraints:

weights_i >= 0         ie.   (# &#8805; 0)& /@ weights
Sum[weights] == 1      ie.   Plus@@weights == 1
Max 20 weights_i > 0

This last one I don't know how to implement sanely. Surely I could use something
like:

Plus@@(Boole[# > 0.0001] &/@ weights) &#8804; 20

but that's just too inefficient ( and ugly). Can anybody think of a better way
of imposing such a constraint to this optimization promlem?