HodrickPrescottFilter.filter#

HodrickPrescottFilter.filter(data)[source]#

Filter a panel.

Each column is smoothed independently by the same banded solve; a one-dimensional series is treated as a one-column panel.

Parameters:

data (ArrayLike) – A (nobs, k) panel or one-dimensional series.

Return type:

DecompositionFilterResult

Returns:

The DecompositionFilterResult, every row kept, with the first and last ceil(cutoff) rows flagged provisional.

Raises:

Example

>>> rng = np.random.default_rng(0)
>>> panel = np.cumsum(rng.standard_normal((120, 2)), axis=0)
>>> res = HodrickPrescottFilter(penalty=100.0).filter(panel)
>>> res.n_series, int(res.provisional.sum()), round(res.cutoff, 1)
(2, 40, 19.8)
>>> HodrickPrescottFilter().filter(panel[:3, 0])
Traceback (most recent call last):
    ...
cultivars.exceptions.SpecificationError: ... needs at least 4 observations.