# Finding a basket of stocks that tracks an index

Given an index, let's say S&P500, I am trying to find a list of maximum n underlyings, which altogether track the index quite well. I am thinking of running a portfolio optimization algorithm, where I long the Index (weight = 1) and short the n underlyings, with the aim of minimizing portfolio variance. The output would be the weights of the underlyings.

However, given there are 500 underlyings, there would be too many different combinations of underlyings, whose len(underlyings) <= n, and as a result the program would run very slowly. Is there a faster way / another way of selecting a basket of stocks that track the index well?

The requirement that the number of stocks is less than a certain number is called a cardinality constraint. A mixed integer quadratic programming solver is the most natural approach to this type of problem. However, for 500 stocks, this can also be quite slow, for the same reason you mention above. Alternately, Matlab also has a Webinar where they use a genetic algorithm to solve an optimization problem with cardinality constraints.

If these approaches are still too slow and you don't mind relaxing the strict cardinality constraint to something more loose, then you can try norm constraints (you might also see papers referring to sparse portfolios or portfolio regularization). Basically the idea is to introduce an additional penalty term into the optimization, like what is done with ridge regression or LASSO. So in this sense, if you increase the penalty term, then that will make the portfolio more sparse (more 0s). You might have to play around with the term to get the number of stocks you want (and the relationship between number of stocks and the choice of the term may not necessarily be constant over time).

• should intercept (constant term) be included in regression equation when we do LASSO for above purpose ?
– Qbik
Aug 18, 2018 at 9:46
• You're not doing LASSO. My point is that a norm constraint is like what you do in a LASSO.
– John
Aug 24, 2018 at 2:46

As a heuristic you can prioritize stocks with higher correlation to the index. If your starting weight vector is, for instance, normalized values of correlations, you can have a better start at optimization. You can also go with original weights in the index as a starting point (which would be roughly the market caps), and naturally I suspect the two starting points will be highly similar.

Then to reach your desired number of stocks you can eliminate alternatives by checking partial correlations. Higher partial correlation may indicate similar behavior therefore potential candidates to remove. Recently a friend recommended me Graphical Lasso Report, perhaps it may help to improve your model.

I might also add, it would be a nice problem if you look at it as a bi-objective problem (i.e. for different values of n, what is the performance of index representation).