Class CovarianceShrinkage

java.lang.Object
com.quantfinlib.risk.CovarianceShrinkage

public final class CovarianceShrinkage extends Object
LEDOIT-WOLF covariance shrinkage (2004, "A well-conditioned estimator for large-dimensional covariance matrices") — the standard fix for the dirty secret of portfolio optimization: the sample covariance matrix is the MAXIMALLY overfit estimate. With N assets and T observations it has N(N+1)/2 free parameters; when T is not a large multiple of N its smallest eigenvalues are far too small and its largest far too large — and a mean-variance optimizer amplifies exactly those errors (it loads up on the directions the matrix WRONGLY calls near-riskless).

The estimator shrinks toward the scaled identity mu·I (mu = average sample variance):

  Sigma* = delta · mu·I + (1 − delta) · S

with the intensity delta chosen FROM THE DATA to minimize expected Frobenius loss: delta = b̄²/d², where d² = ||S − mu·I||²_F measures how far the sample matrix is from the target and b̄² estimates how much of that distance is pure sampling noise (the average Frobenius distance of single-observation outer products from S, over T², clamped to d²). Intuition: when the data say the sample matrix is mostly noise (T small, N large), delta → 1 and you trust the boring target; when T is huge, delta → 0 and the sample matrix speaks for itself. No tuning parameter to pick — that is the whole appeal.

The result is always positive-definite for delta > 0 (a convex combination with mu·I lifts every eigenvalue toward mu), which is what makes it safe to hand to optimization.PortfolioOptimizer where a raw sample matrix from short history can be singular. Identity target, stated: the constant-correlation target variant trades a bit of bias for structure; this is the well-conditioned workhorse. Research lane, deterministic.

  • Method Details

    • ledoitWolf

      public static CovarianceShrinkage.Result ledoitWolf(double[][] returns)
      Parameters:
      returns - T×N: returns[t][j] = period-t return of asset j; T ≥ 2, N ≥ 1, rectangular, finite
    • shrink

      public static double[][] shrink(double[][] returns)
      Convenience: the shrunk matrix only.