# Baxter-King Filter

`D09-F05-A03` · Statistical Time Series → Decomposition and Cycles · archetype `record-transform` · difficulty 4/5 · verification **contract**

Full page: https://docs.thefintechbuilder.com/statistical-time-series/decomposition-and-cycles/baxter-king-filter/
Agent skill: `npx skills add IslamBaraka90/Fintech-Algorithms-Library` — https://docs.thefintechbuilder.com/guides/agent-skill/

## Install and import

```bash
npm install fintech-algorithms
```

```ts
import { bkFilter } from "fintech-algorithms/statistical-time-series/decomposition-and-cycles/baxter-king-filter";
```

## Signature

```ts
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 | Required | Notes |
| --- | --- | --- | --- |
| `values` | `number[]` | yes | Observation series. |
| `low` | `number` | yes | Shortest cycle length to retain, in periods. · min: 1, integer: true |
| `high` | `number` | yes | Longest cycle length to retain. · min: 1, integer: true |
| `K` | `number` | yes | 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

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

`values`:

```json
[
  100.0901805654,
  101.3367333472,
  102.4083163971,
  102.9128416721,
  103.198587938,
  102.4311805579
]
```

Showing 6 of 192 elements.

`low`:

```json
6
```

`high`:

```json
32
```

`K`:

```json
12
```

### Call

```ts
bkFilter(values, low, high, K)
```

### Returns

object with 8 fields: cycle, trend, weights, low_period, high_period, K, edge_loss_each_side, weight_sum

```json
{
  "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

`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.

## Verification and provenance

Tier: **contract**.

The module loads, the entry point is callable and its declared signature matches the compiled code. The example below is real captured output, but no independently published figure asserts the numbers.

Both tiers guarantee the signature. Full explanation: https://docs.thefintechbuilder.com/guides/verification/

Generated from the docs.json payload shipped inside fintech-algorithms@0.13.1.
The signature and parameter list are checked against the compiled implementation at build time,
so a description that contradicts the code fails the build rather than reaching this file.

## Links

- Article (how it works, step by step): https://thefintechbuilder.com/statistical-time-series/decomposition-and-cycles/baxter-king-filter/
- Implementation source: https://github.com/IslamBaraka90/Fintech-Algorithms-Library/blob/main/src/statistical-time-series/decomposition-and-cycles/baxter-king-filter/impl.ts
- Package on npm: https://www.npmjs.com/package/fintech-algorithms
- Domain index for agents: https://docs.thefintechbuilder.com/statistical-time-series/llms.txt
