Baxter-King Filter
Install and import#
npm install fintech-algorithmsimport { bkFilter } from "fintech-algorithms/statistical-time-series/decomposition-and-cycles/baxter-king-filter";Signature#
bkFilter(values, low, high, K)A band-pass filter isolating fluctuations between two periodicities. Being a symmetric moving average it consumes K observations at **each** end, so the filtered series is shorter than the input at both.
Parameters#
| Name | Type | Notes |
|---|---|---|
values | number[] | Observation series. |
low | number | Shortest cycle length to retain, in periods. min: 1 · integer: true |
high | number | Longest cycle length to retain. min: 1 · integer: true |
K | number | Filter half-length. Larger sharpens the band and costs more observations at each end. min: 1 · integer: true |
Returns#
{ cycle, weights, trimmed }
The band-passed series with the weights used and how many observations were trimmed from each end.
Errors#
- When low ≥ high, or the series is shorter than 2K + 1 — throws
Complexity: time O(n × K),
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.
63212Call#
bkFilter(values, low, high, K)Returns#
object with 8 fields: cycle, trend, weights, low_period, high_period, K, edge_loss_each_side, weight_sum
{
"cycle": [null, null, null, null, null, null],
"trend": [null, null, null, null, null, null],
"weights": [
-0.011925074099926311,
-0.042289342849822956,
-0.050142927835196305,
-0.02785666762175208,
0.0015008360109016001,
0.0016130582107286165
],
"low_period": 6,
"high_period": 32,
"K": 12,
"edge_loss_each_side": 12,
"weight_sum": 9.71445146547012e-17
}Other exports#
This module also exports
stlDecompose, hpFilter, cfFilter, 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#
Calculation flow#
Baxter-King Filter — Audit Flow
flowchart LR
A["Finite evenly sampled values"] --> B["Freeze transformation and profile"]
B --> C["Apply centered finite band-pass weights"]
C --> D["Component or power output"]
D --> E["Reconstruction / accounting check"]
E --> F["Endpoint and revision audit"]
F --> G["Profile sensitivity"]
G --> H["White-noise control"]
H --> I{"Decision use justified?"}
I -->|No| J["Keep as descriptive diagnostic"]
I -->|Yes| K["Rebuild causally and test out of sample"]
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