Class Pca
java.lang.Object
com.quantfinlib.risk.Pca
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
ConstructorsConstructorDescriptionPca(double[][] covariance) Decomposes a symmetric covariance matrix (n×n, row-major square). -
Method Summary
Modifier and TypeMethodDescriptiondoubleeigenvalue(int c) Variance carried by componentc(descending order).doubleexplainedVariance(int k) Fraction of total variance the firstkcomponents explain.doubleloading(int c, int f) Unit loading of factorfon componentc.intsize()
-
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 componentc(descending order). -
loading
public double loading(int c, int f) Unit loading of factorfon componentc. -
explainedVariance
public double explainedVariance(int k) Fraction of total variance the firstkcomponents explain. -
size
public int size()
-