rheon.corr.epps_invert¶
- rheon.corr.epps_invert(gram_or_row: Any, *, L: int) Any[source]¶
Compute the correlation over
Lrows from lagged co-moments, undoing the Epps attenuation.Use it on a correlation measured over fine intervals, which is too low because two series do not move at the same instants (the Epps effect). Toth and Kertesz’s equation 12 undoes it by summing the lagged cross-covariances over a coarser interval of
Lrows.Parameters
gram_or_rowA Gram from
gram(), or a closed group’s row, withlagsandlag_comomentsholding every lag1 .. L-1. Build it withrp.spec.ew_cov(..., lags=list(range(1, L))).LThe coarser interval, in rows, at least 1.
L = 1gives the plain correlation.
Returns
The
k x kcorrelation matrix at scaleL, over the input’s columns other than an intercept, withnanwhere a column has no variance.Raises
ValueErrorLbelow 1, or a lag1 .. L-1missing from the input, which the error names.
Examples
This code reads
tradesfrom Example data:quotes = trades.filter(pl.col("price").is_null()).with_columns( ret=pl.col("mid").diff().over("symbol") ) pair = quotes.pivot(on="symbol", index="ts", values="ret").fill_null(0.0) spec = rp.spec.ew_cov("cov", features=["AAA", "BBB"], half_life=float("inf"), lags=[1, 2]) bank = rp.ModelBank([spec]) bank.fit_predict(pair) g = bank.gram("cov")[0] print(round(float(rp.corr.epps_invert(g, L=1)[0, 1]), 3), round(float(rp.corr.epps_invert(g, L=3)[0, 1]), 3))
-0.001 0.418
See also
rheon.gram.correlation(), the correlation at one row.
Notes
The weights are triangular, on the numerator and on both denominators:
rho_L[a, b] = sum_x (L - |x|) C_x[a, b] / sqrt(sum_x (L - |x|) C_x[a, a] * sum_x (L - |x|) C_x[b, b])over
x = -(L-1) .. L-1, withC_xthe co-moments at lagxandC_{-x}[a, b] = C_x[b, a]. So the numerator isL C_0[a, b] + sum_{l=1}^{L-1} (L - l) (C_l[a, b] + C_l[b, a]), and each variance term isL C_0[a, a] + 2 sum_l (L - l) C_l[a, a].