Skip to content

EWCov

Exponentially weighted covariance.

This is the bivariate counterpart of stats.EWVar. It tracks the covariance between two variables while giving more weight to recent observations, which is what you want when the relationship between the variables drifts over time (e.g. the co-movement of two asset returns during a changing market regime).

Internally it uses the identity \(Cov(x, y) = E\[xy\] - E\[x\]E\[y\]\), with each expectation estimated by an exponentially weighted mean (stats.EWMean). Using the same fading_factor on the diagonal recovers stats.EWVar exactly.

Parameters

  • fading_factor

    Default0.5

    The closer fading_factor is to 1 the more the statistic will adapt to recent values.

Attributes

  • name

Examples

from river import stats

x = [1, 3, 5, 4]
y = [2, 4, 3, 6]

ewcov = stats.EWCov(fading_factor=0.5)
for xi, yi in zip(x, y):
    ewcov.update(xi, yi)
    print(ewcov.get())
0.0
1.0
0.5
0.625

Methods

get

Return the current value of the statistic.

update

Update the called instance.

Parameters

  • x
  • y

References