fintech-algorithms

Wavelet Decomposition

Install and import

bash
npm install fintech-algorithms
ts
import { haarWavelet } from "fintech-algorithms/statistical-time-series/decomposition-and-cycles/wavelet-decomposition";

Signature

haarWavelet(values, levels)

Haar wavelet decomposition: splits the series into detail at successive scales plus a residual approximation. Unlike Fourier it localises in *time* as well as frequency, so it can say when a frequency was present.

Parameters

NameTypeNotes
valuesnumber[]Observation series. Haar works on powers of two; a shorter series is padded.
levelsnumberNumber of decomposition levels. Each halves the resolution of the approximation.
min: 1 · integer: true

Returns

{ details, approximation, levels }

Detail coefficients per level plus the final approximation.

Errors

  • When levels exceeds what the series length supports — 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

values
[
  100.0901805654,
  101.3367333472,
  102.4083163971,
  102.9128416721,
  103.198587938,
  102.4311805579
]

Showing 6 of 192 elements.

levels
4

Call

haarWavelet(values, levels)

Returns

object with 11 fields: approximation_coefficients, detail_coefficients, approximation_component, detail_components, reconstructed, levels, wavelet, boundary_mode, …

{
  "approximation_coefficients": [
    406.2370710410249,
    400.6458644165249,
    408.18250013307494,
    406.58956430514996,
    415.4042925955248,
    408.8285391202
  ],
  "detail_coefficients": [
    [
      -0.8814459251177285,
      -0.35675324323251195,
      0.5426389624013097,
      0.7206078638433713,
      0.22202008434506101,
      -0.6488746408711917
    ],
    [
      -1.9471220782999858,
      1.5938553549500085,
      -0.32437943830000726,
      -0.7441778894000111,
      2.4193453339000146,
      -0.5144175941000312
    ],
    [
      -0.46801782111276313,
      -3.419692948980583,
      4.169455460606318,
      0.2223496978931099,
      -5.578639117285321,
      3.8376397376595466
    ]
  ],
  "approximation_component": [
    101.55926776025618,
    101.55926776025618,
    101.55926776025618,
    101.55926776025618,
    101.55926776025618,
    101.55926776025618
  ],
  "detail_components": [
    [
      -0.6232763908999955,
      0.6232763908999955,
      -0.252262637500003,
      0.252262637500003,
      0.38370369004999805,
      -0.38370369004999805
    ],
    [
      -0.9735610391499928,
      -0.9735610391499928,
      0.9735610391499928,
      0.9735610391499928,
      0.7969276774750041,
      0.7969276774750041
    ],
    [
      -0.16546928751249362,
      -0.16546928751249362,
      -0.16546928751249362,
      -0.16546928751249362,
      0.16546928751249362,
      0.16546928751249362
    ]
  ],
  "reconstructed": [
    100.09018056539995,
    101.33673334719994,
    102.40831639709995,
    102.91284167209994,
    103.19858793799993,
    102.43118055789995
  ],
  "levels": 4,
  "wavelet": "haar",
  "boundary_mode": "periodization",
  "approximation_energy_fraction": 0.999765090759817,
  "detail_energy_fractions": [
    0.000018209004639336907,
    0.00005361952217361794,
    0.0001317428663664597,
    0.00003133784700365802
  ],
  "reconstruction_max_error": 9.947598300641403e-14
}

Other exports

This module also exports stlDecompose, hpFilter, bkFilter, cfFilter, fftPeriodogram, 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

Wavelet Decomposition — decomposition map
Wavelet Decomposition — endpoint risk
Wavelet Decomposition — family handoff
Wavelet Decomposition — parameter effect
Wavelet Decomposition — scenario comparison

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.

Read the article →

References

  • Evidence table
  • Source records
  • Evidence policy
  • Version notes