Skip to content
All library documents

Quadratic Optimization for Building a Return-Tracking Portfolio

Article Quant Q&A · Author: Mike

Summary

The document describes constructing a portfolio from candidate asset returns to track a target return stream. It frames the task as index tracking through quadratic programming, using the covariance matrix of candidate returns and their covariances with the target to choose portfolio weights. The example aligns the candidate and target series by date and applies lower and upper bounds to each weight.

The approach is intended to find weights that reduce tracking differences under the chosen optimization setup. The example allows weights between negative one and one, so it can include short positions, and it imposes a total weight constraint. It does not establish that the resulting portfolio achieves perfect correlation, nor does it discuss transaction costs, missing observations, out-of-sample stability, or how the optimization objective corresponds to correlation specifically. Those choices affect whether the hedge is useful in practice.

Key ideas

  • The return-tracking task is formulated as a quadratic programming optimization problem.
  • Candidate asset covariances and their covariances with the target stream inform the portfolio weights.
  • The example uses date-aligned return series and imposes bounds on individual weights.
  • Allowing negative weights permits short positions in the tracking portfolio.
  • The method does not guarantee perfect correlation or address trading costs and out-of-sample performance.

Tags

Full text
# Create a hedging portfolio


# 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.

## Answer by Mike (score 1)

https://quant.stackexchange.com/a/36764

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

ser, res = quadprog(
    np.cov(_x.transpose()), 
    [-1.0 * np.cov(_x.loc[:,c].T, _y)[0][1] for c in _x.columns],
    np.ones(n),
    1.0,
    np.vstack([lb for n in range(n)]), 
    np.vstack([ub for n in range(n)])  )
for s,z in zip(ser, _x.columns):
    print('{}: {:0.4f}'.format(z, float(s[0])))
```

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.