rts_smootherΒΆ

Defined in fynance.features.filters

rts_smoother(m, C, a, R, G)[source]

Rauch-Tung-Striebel (RTS) smoother.

Backward pass over the output of kalman_filter. Produces smoothed estimates that use all observations, not just past ones.

Parameters:
mnp.ndarray of shape (T, n)

Filtered means from kalman_filter.

Cnp.ndarray of shape (T, n, n)

Filtered covariances from kalman_filter.

anp.ndarray of shape (T, n)

Prior means from kalman_filter.

Rnp.ndarray of shape (T, n, n)

Prior covariances from kalman_filter.

Gnp.ndarray of shape (n, n)

State transition matrix (same as passed to kalman_filter).

Returns:
msnp.ndarray of shape (T, n)

Smoothed state means.

Csnp.ndarray of shape (T, n, n)

Smoothed state covariances.

Examples

>>> import numpy as np
>>> rng = np.random.default_rng(0)
>>> y = rng.standard_normal((5, 1))
>>> G = F = W = V = np.eye(1)
>>> m, C, a, R, e, S = kalman_filter(y, G, F, W, V)
>>> ms, Cs = rts_smoother(m, C, a, R, G)
>>> ms.shape
(5, 1)
>>> bool((np.abs(ms) <= np.abs(y) * 2).all())
True