The Grand Scheme of Madness
Wavelets  ·  a visual guide

A microscope for time

A price series is many things happening at once: a slow trend, a cycle, a sudden jump, a burst of nervous trading. Fourier analysis tells you which rhythms are present and loses track of when. A wavelet transform keeps both, by looking through a window that widens for slow features and narrows for fast ones.

Top: 1,024 days of a simulated series containing a trend, a 48-day cycle that fades out, a jump on day 420 and a burst of fast oscillation around day 800. Bottom: its wavelet transform. Across is time, down is time scale from fast to slow, and darkness is how strongly the series moves at that scale at that moment. Move the pointer over the map to see the wavelet that produced each point, and change the wavelet to see how the map depends on the probe.
  1. 01What Fourier cannot see
  2. 02The windowed fix
  3. 03One small wave
  4. 04The scalogram
  5. 05The uncertainty trade
  6. 06Averages and differences
  7. 07Filter banks
  8. 08Choosing a wavelet
  9. 09Denoising
  10. 10Compression
  11. 11Jumps and bursts
  12. 12Variance by scale
  13. 13In practice
  14. 14The family
  15. 15Using it live
  16.  Sources
01

What Fourier cannot see

The Fourier transform rewrites a series as a sum of sines and cosines, each running the whole length of the record:

\[\hat{x}(\omega)=\sum_{t}x_t\,e^{-i\omega t}\]

The size of \(\hat{x}(\omega)\) says how much of frequency \(\omega\) the series contains. It says nothing about when. A sine has no beginning and no end, so an event that lasts thirty days gets spread across every day of the record. The timing is still in there, encoded in the phases, but in a form no one can read off a chart.

A steady 64-day cycle with a short burst of 6-day oscillation. Slide the burst anywhere along the record. The spectrum underneath does not move at all.
02

The windowed fix, and where it stops

The obvious repair is to take the Fourier transform of a short stretch at a time, sliding a window \(g\) along the series:

\[X(\tau,\omega)=\sum_t x_t\,g(t-\tau)\,e^{-i\omega t}\]

This works, up to a point you have to choose in advance. A short window pins down when something happened and blurs its frequency. A long window does the reverse. Whatever length you pick is applied to everything, and a series with both a slow cycle and a sharp jump wants two different answers.

The windowed Fourier transform of the series from figure 1. It is drawn on the same axes as figure 1 so the two can be compared. With a 16-day window the jump is a crisp vertical line and the cycle is missing. With a 256-day window the cycle is a clean horizontal band and the jump is spread over most of a year.
03

One small wave, stretched and slid

A wavelet \(\psi\) is a short oscillation that starts at zero, wiggles, and returns to zero, with as much area above the axis as below. From this one shape a whole family is made by stretching it to scale \(s\) and sliding it to position \(b\). The wavelet coefficient is how well the series near \(b\) matches the stretched shape:

\[W(s,b)=\sum_t x_t\;\frac{1}{s}\,\psi\!\Big(\frac{t-b}{s}\Big)\]

That is the whole idea. Stretching does what the window length could not: a narrow wavelet looks at a few days and responds to fast movement, a wide one looks at months and responds to slow movement, and the width changes automatically with the scale being examined. Because the wavelet has zero area, a constant level gives no response. Only change registers.

Top: the series with the wavelet drawn at the pointer, and the stretch of data it covers shaded. Bottom: the coefficient at this scale for every position. Move the pointer along the series. Press and drag up to stretch the wavelet or down to squeeze it, or use the slider. At a few days the coefficient spikes at the jump and the burst. At 48 days it rides the cycle and dies when the cycle does.
04

Every scale at once

Compute that coefficient row for a whole range of scales, stack the rows, and shade by size. The result is the scalogram: a map of the series with time across and scale down. Each kind of feature leaves its own signature.

  • A steady cycle is a horizontal band at its period, lasting as long as the cycle does.
  • A jump is a vertical cone. It is present at every scale, narrow at fast scales and widening at slow ones.
  • A burst is a compact blob, localised in both time and scale.
  • Noise is a faint speckle concentrated at the fastest scales.
The scalogram of the series in figure 1, shown with the Daubechies 4 wavelet, with seven others to choose from. The Morlet wavelet has several oscillations, so it resolves period well and shows the cycle as a clean band. The Paul wavelet has fewer and trades some of that for sharper timing. The Mexican hat and the Gaussian derivative are real-valued with one or two lobes: they time the jump tightly, and they break the cycle into a row of separate blobs, one for each swing, because a real wavelet responds to phase as well as amplitude. The Daubechies wavelets, which are designed for the discrete transform of section 7, can be stretched and slid in the same way. They behave like the other real wavelets, with shorter, lopsided footprints. Outside the dashed curves the wavelet overlaps the ends of the record and the values there are unreliable.
05

You cannot have both, but you can choose where

No analysis can be sharp in time and in frequency together. If \(\Delta t\) is the spread of a basis function in time and \(\Delta\omega\) its spread in frequency, then

\[\Delta t\cdot\Delta\omega\;\ge\;\tfrac12\]

Picture each basis function as a tile on the time–frequency plane. The tiles all have the same area, and the only freedom is their shape. Every method in this guide is a way of tiling the plane.

Four ways to divide the same plane into tiles of equal area. Wavelets use tall, thin tiles at high frequencies, where events are brief and timing matters, and short, wide tiles at low frequencies, where events are slow and their exact period matters.
06

Averages and differences

The continuous transform computes far more numbers than the series contains. The discrete wavelet transform keeps just enough: as many coefficients as data points, with nothing lost. Its simplest form, the Haar transform, needs only arithmetic. Haar is also the first member of the Daubechies family, Daubechies 1, and every longer Daubechies wavelet follows the same recipe with more than two values in each average and difference.

Take the series two values at a time. Replace each pair by its average and its difference:

\[a=\frac{x_1+x_2}{2},\qquad d=\frac{x_1-x_2}{2}\qquad\Longleftrightarrow\qquad x_1=a+d,\quad x_2=a-d\]

The averages are a half-length, blurred copy of the series. The differences are the detail the blur removed. Now do the same to the averages, and again to the result. Each pass halves the series and peels off the detail at a scale twice as coarse as the last.

Eight numbers, transformed one level at a time. Averages are on the left and the differences removed at each level are on the right. Click any bar in the top row to change its value. Wherever neighbouring values are equal the difference is zero, which is why smooth stretches of a series cost almost nothing to store.
07

The same thing as a cascade of filters

Averaging neighbours is a low-pass filter. Differencing them is a high-pass filter. So one level of the transform is: split the series into a smooth half and a detail half with a pair of filters \(h\) and \(g\), then discard every second output, since each half carries only half the information.

\[a_{j+1}[n]=\sum_k h[k]\,a_j[2n+k]\qquad\qquad d_{j+1}[n]=\sum_k g[k]\,a_j[2n+k]\]

Longer filters than Haar’s give smoother wavelets, and the recipe is otherwise identical. Because each level works on half as much data as the one before, the total work is \(N+\tfrac N2+\tfrac N4+\dots<2N\) filter steps. The transform is faster than the fast Fourier transform.

Top: the filter bank. Each stage splits its input into a detail band, which is kept, and a smoother half-length series, which goes on to the next stage. Bottom: the detail coefficients of the series from figure 1, one row per level, each cell as wide as the stretch of time it describes. This is the scalogram of figure 5 sampled on the wavelet tiling of figure 6. It uses the wavelet chosen in section 8.
08

Choosing a wavelet

There are many wavelets because there are several things to want and no shape has them all. Short support localises events precisely and keeps edge effects small. Smoothness and vanishing moments make smooth stretches of data produce near-zero coefficients: a wavelet with \(p\) vanishing moments is blind to polynomial trends of degree below \(p\). Symmetry avoids shifting features in time. Longer filters buy smoothness at the price of support.

The named families are different answers to that trade. Daubechies wavelets have the most vanishing moments possible for their length, and are lopsided as a result. Symlets are Daubechies’ own rearrangement of the same filters to be as nearly symmetric as possible. Coiflets give the smoothing function vanishing moments as well, so that the smooth coefficients are close to samples of the series itself. Biorthogonal wavelets give up orthogonality, using one pair of filters to analyse and a different pair to rebuild, and in return are exactly symmetric. Two of them are the wavelets inside the JPEG 2000 image standard. For the continuous transform the choice is between complex wavelets, which measure the amplitude of an oscillation whatever its phase, and real ones, which locate individual peaks, troughs and edges.

Fifteen wavelets. The first eleven define discrete transforms. Click one to use it in every discrete figure that follows, and in figure 8 above, and see how the results change. The last four are for the continuous transform. Figures 1, 4 and 5 offer them alongside the Daubechies wavelets.
09

Denoising by forgetting small coefficients

A wavelet transform concentrates structure and spreads noise. A jump or a cycle lands in a few large coefficients. White noise lands evenly in all of them, at the same small size. So shrink every coefficient towards zero by a threshold \(\lambda\), wiping out the ones that are plausibly pure noise, and transform back:

\[\tilde d=\operatorname{sign}(d)\,\max\big(|d|-\lambda,\,0\big),\qquad\lambda=\sigma\sqrt{2\ln N}\]

The threshold shown is the universal one of Donoho and Johnstone, with the noise level \(\sigma\) estimated from the finest-scale coefficients. Unlike a moving average, this does not blur everything equally. Where the data is smooth it smooths hard, and where there is a jump the large coefficients survive and the edge is kept. The figure averages the estimate over sixteen shifts of the series, the standard remedy for the shift sensitivity described in section 13.

Noisy dataTrue seriesWavelet estimateBest moving average
Top: the noisy series, the truth and two estimates. Bottom: the error of the wavelet estimate at every threshold, as a multiple of the universal value, against the best that any centred moving average achieves on the same data. Raise the noise and watch the balance shift. The readout also compares the two in the thirty days around the jump on day 420.
10

Compression: keep the few that matter

The same concentration makes wavelets a compression scheme. Keep the largest \(K\) coefficients, set the rest to zero, and reconstruct. The comparison below does the same with the largest \(K\) Fourier coefficients. Fourier is efficient for pure cycles and hopeless for a jump: a discontinuity needs every frequency, and cutting any of them leaves ripples along the whole record.

The noise-free series rebuilt from its largest coefficients in each basis, with the original in grey. Bottom: the error of both as more coefficients are kept. Watch the neighbourhood of the jump in the Fourier panel.
11

Reading jumps and bursts across scales

How a feature behaves from one scale to the next identifies what it is. A jump shows up at every scale at the same moment, and its coefficients grow as the scale coarsens. A burst of fast oscillation appears at one or two scales and is absent from the rest. Noise shrinks steadily as the scale coarsens. Detectors for breaks and outliers are built on exactly this: look for coefficients that line up across scales.

The series and its detail coefficients at six scales, from a transform that keeps one coefficient per day at every scale so the rows line up in time. The jump on day 420 marks every row. The burst near day 800 marks only the rows whose band contains its 7-day period. The figure uses the wavelet chosen in section 8. Longer wavelets give cleaner bands and blunter timing, and lopsided ones displace features slightly at the coarser scales.
12

How much happens at each horizon

An orthogonal wavelet transform preserves energy, so the variance of a series splits exactly into a contribution from each scale:

\[\operatorname{Var}(x)=\sum_{j}\nu_j^2,\qquad\nu_j^2=\text{variance of the level-}j\text{ detail coefficients}\]

This is a horizon-by-horizon risk budget. The same decomposition applied to two series gives a correlation at each scale, and that can differ sharply from the single number computed on raw returns. Two assets that share a slow common driver and have unrelated daily noise look nearly uncorrelated day to day and move together over months.

Two simulated return series of 4,096 days. Each is a shared, slowly varying driver plus its own independent daily noise. Left: the share of one series’ variance at each horizon. Right: the correlation between the two at each horizon, against the ordinary correlation of daily returns. Computed with the wavelet chosen in section 8.
13

What to watch in practice

The standard discrete transform has one property that surprises everyone the first time. It is not shift-invariant. Move the series by a single day and the coefficients change, sometimes a great deal, because the fixed grid of pairs now falls differently across each feature. The undecimated transform, also called the stationary or maximal-overlap transform, fixes this by skipping the downsampling and keeping every shift. It costs \(N\) coefficients per level in place of \(N\) in total, and it is the right default for analysing time series.

Energy at each level for a series containing one jump and one bump, as the whole series is shifted a day at a time. Outlines show the unshifted values. Left: the standard transform, whose answer depends on where the grid happens to fall. Right: the undecimated transform, whose answer does not. Both use the wavelet chosen in section 8. Shift sensitivity is a property of the downsampling and no choice of wavelet removes it.
14

Where wavelets sit among their relatives

Each neighbour is the wavelet transform with one design decision made differently. Each panel opens a short interactive guide to that method.

TransformCoefficientsCostUse it for
Continuousone per scale per time, heavily redundant\(O(N\log N)\) per scalelooking: scalograms, ridges, timing of oscillations
Discreteexactly \(N\), orthogonal\(O(N)\)compression, denoising, fast computation
Undecimated\(N\) per level\(O(N\log N)\)time-series analysis, variance and correlation by scale, break detection
15

Using it live

Every map in this guide was drawn with the whole record in hand. A trading signal has only the past. Four things change when a wavelet feature has to be computed on the day it is used.

Two-sided smooth, with hindsightTwo-sided smooth, as computed on the dayOne-sided 16-day averageThe series
The series from figure 1 with fresh noise. The smooth removes everything faster than about 32 days, using a Symlet 8 transform with the detail levels 1 to 4 set to zero. The heavy line uses the whole record. The second line is the same calculation run on the data up to the chosen day, with the series mirrored at the edge. The third is the level-4 smooth of the one-sided Haar transform. Move the day past the jump at day 420 to see the largest revisions.

Before a wavelet feature goes into a backtest, compute each day’s value from the data up to that day, store it, and never recompute history. Choose the wavelet, the levels and the thresholds on a training window only.

Sources and further reading