rheon.corr.absorption

rheon.corr.absorption(r: Any, k: int) → float[source]

Compute Kritzman, Li, Page and Rigobon’s absorption ratio of a correlation matrix.

Use it to measure how much the series move as one: the share of the total variance the top k eigenvectors explain. A high ratio means the market is moving as one thing. To compare a fast and a slow ratio, use absorption_shift().

Parameters

r

An n x n correlation matrix, or a Gram or a closed group’s row, read as rheon.gram.correlation() reads it, without the intercept (the module’s docstring says why).

k

How many of the largest eigenvalues to sum, from 1 to n.

Returns

A float, sum_{i<=k} lam_i / sum_i lam_i over the eigenvalues lam_i in decreasing order, or nan where they sum to 0.

Raises

ValueError

k outside 1..n, r an array that is not square, or a Gram column other than the intercept with no variance.

WrongTypeError

k is not a whole number, such as 2.0 or True. It is both a TypeError and a ValueError.

numpy.linalg.LinAlgError

r is an array holding nan entries, where numpy’s eigensolver does not converge.

Examples

r = np.array([[1.0, 0.8, 0.7], [0.8, 1.0, 0.75], [0.7, 0.75, 1.0]])
print(round(rp.corr.absorption(r, 1), 3))
0.834

See also