Class Pca

java.lang.Object
com.quantfinlib.risk.Pca

public final class Pca extends Object
Principal component analysis of a covariance matrix — the risk-factor compressor. A yield curve has a dozen tenors but three real risk factors (level, slope, curvature — the classic result this class reproduces on curve data); an equity book has hundreds of names but a handful of factors carrying most of the variance. PCA finds them: the eigenvectors of the covariance matrix, ordered by how much variance each explains.

Implementation is the cyclic Jacobi eigenvalue algorithm — exact for symmetric matrices, dependency-free, and comfortably fast at risk dimensions (tens of factors; it is O(n³) per sweep and converges in a handful of sweeps). Eigenvalues clip at zero: a covariance matrix is PSD in exact arithmetic, and a tiny negative eigenvalue is numerical noise, not an imaginary risk factor. Research lane, deterministic.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Pca(double[][] covariance)
    Decomposes a symmetric covariance matrix (n×n, row-major square).
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    eigenvalue(int c)
    Variance carried by component c (descending order).
    double
    Fraction of total variance the first k components explain.
    double
    loading(int c, int f)
    Unit loading of factor f on component c.
    int
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Pca

      public Pca(double[][] covariance)
      Decomposes a symmetric covariance matrix (n×n, row-major square). Asymmetry beyond floating-point noise is rejected — a typo'd covariance must not silently symmetrize into a different matrix.
  • Method Details

    • eigenvalue

      public double eigenvalue(int c)
      Variance carried by component c (descending order).
    • loading

      public double loading(int c, int f)
      Unit loading of factor f on component c.
    • explainedVariance

      public double explainedVariance(int k)
      Fraction of total variance the first k components explain.
    • size

      public int size()