Create a hedging portfolio

If, given a return stream of unknown composition, what is the best find a portfolio of assets that replicates that return stream from a universe of assets?

In other words, what is the best optimisation method to use to find the weights to assign a portfolio of assets where the returns from the portfolio has a correlation of 1 to another asset? Preferably something that is easy to replicate in Python.

To answer my own question: I've used a fairly simple index-tracking portfolio created from asset correlation, which is basically a quadratic programming optimisation problem, by following the procedure detailed in the paper here: https://www.nag.co.uk/content/index-tracking-portfolio-optimization-model

Since my preferred Python quadratic programming solver (CVXOPT) does not explicitly incorporate lower/upper bound solution for portfolio weights, I've used the following quadprog function taken from https://gist.github.com/garydoranjr/1878742 to solve for optimal portfolio weights.

Both _x and _y are organised in date-unified Pandas data frames, with DateTime as index.

_x = ... # Return stream of potential portfolio of assets
_y = ... # target/hedge return stream

n = len(_x.columns)
lb = -1.0
ub = 1.0