SigmaField

Practice Portfolios

Solve the minimum-variance portfolio with a budget constraint

Medium+25 pointsAbout 40 minutesPortfolios

The brief

A portfolio manager has $50 million to place across ten funds, and wants the book with the least risk. Every dollar must be invested, so the budget is a constraint. Risk is the variance of the book's value over a year.

The desk wants the answer from a formula and from a numerical optimiser. The optimiser is what it will use once more constraints arrive, such as the fund's rule against short sales.

Your task

  1. Derive the positions on paper. Minimise x⊤Σx\mathbf{x}^\top\Sigma\mathbf{x} subject to 1⊤x=B\mathbf{1}^\top\mathbf{x} = B, with the Lagrangian L=x⊤Σx−λ(1⊤x−B)L = \mathbf{x}^\top\Sigma\mathbf{x} - \lambda(\mathbf{1}^\top\mathbf{x} - B). Here x\mathbf{x} holds the positions in $ millions, Σ\Sigma is the covariance matrix and BB the budget.
  2. Write min_variance(cov, budget): the pair (x, lam), with the positions as a NumPy array and the multiplier λ\lambda. Raise ValueError unless cov is square, symmetric and positive definite, and budget is positive.
  3. Write min_variance_numeric(cov, budget, long_only=False): the same positions, found with scipy.optimize.minimize. With long_only=True no position may be negative. Raise ValueError for the same bad inputs, and RuntimeError if the optimiser reports a failure.

The desk checks every answer to within $1,000 in each fund, which is 0.001 in these units.

The data

VOLS and CORR hold the ten funds' annual volatilities and correlations, and COV is the covariance matrix built from them. BUDGET is 50, in $ millions.

Hint: Where to start

Case study 4.5.5 found the minimum-variance weights for a budget of 1. Follow the same steps from Lagrange's condition (lesson 4.5.1), here 2Σx=λ12\Sigma\mathbf{x} = \lambda\mathbf{1}, and let the budget BB fix λ\lambda.

Hint: What the multiplier measures

Lesson 4.5.1 reads λ\lambda as a rate: the change in the least variance for each extra unit of budget. Check yours by solving for two budgets either side of 50.

Hint: The optimiser and short sales

Lesson 4.5.2 solves with SciPy's SLSQP method, whose ftol sets how precisely it stops; the default stops too early here. Case study 4.5.5 adds bounds for a long-only book, and its KKT conditions tell you whether the answer is right.