Christiano-Fitzgerald Filter
Install and import
npm install fintech-algorithmsimport { cfFilter } from "fintech-algorithms/statistical-time-series/decomposition-and-cycles/christiano-fitzgerald-filter";Signature
cfFilter(values, low, high, drift)An asymmetric band-pass filter that uses the whole sample, so unlike Baxter-King it produces values at the ends. The trade is that the filter weights differ at each observation, which makes it non-stationary by construction.
Parameters
| Name | Type | Notes |
|---|---|---|
values | number[] | Observation series. |
low | number | Shortest cycle length to retain. min: 1 · integer: true |
high | number | Longest cycle length to retain. min: 1 · integer: true |
drift | boolean | Whether to remove a linear drift before filtering. optional |
Returns
{ cycle, trend }
The cycle component over the full sample length.
Errors
- When low ≥ high — throws
Complexity: time O(n²),
space O(n).
Worked example
executed Captured by running this function on the input its own test provides. Real output of real code — but not asserted against a published figure.
Input
[
100.0901805654,
101.3367333472,
102.4083163971,
102.9128416721,
103.198587938,
102.4311805579
]Showing 6 of 192 elements.
632trueCall
cfFilter(values, low, high, drift)Returns
object with 7 fields: cycle, trend, drift_line, low_period, high_period, drift_removed_before_filtering, reconstruction_max_error
{
"cycle": [
-0.9710232193903039,
-0.24888106131204424,
0.6369705111805075,
1.3312619134532966,
1.5158058129594352,
1.0859129088320714
],
"trend": [
101.06120378479031,
101.58561440851204,
101.77134588591949,
101.58157975864671,
101.68278212504057,
101.34526764906794
],
"drift_line": [
0,
0.03320258794921465,
0.0664051758984293,
0.09960776384764396,
0.1328103517968586,
0.16601293974607326
],
"low_period": 6,
"high_period": 32,
"drift_removed_before_filtering": true,
"reconstruction_max_error": 7.105427357601002e-15
}Other exports
This module also exports
stlDecompose, hpFilter, bkFilter, fftPeriodogram, haarWavelet, runTopic. Every module additionally exports run as an alias of its
primary function, and a meta object carrying its catalog id, domain, family,
shape and article URL.
Diagrams
How it works
This page states the contract — how to call it correctly. The article explains the concept: why it works, and where it breaks.
References
- Evidence table
- Source records
- Evidence policy
- Version notes