Skip to content
svgfluctuation-process

Fluctuation process with boundaries

Does the cumulative (or moving) sum of residuals wander outside what a stable regression allows?

Demo data · seed 20261101 · 101 rows · default settings · 640 × 360SVG, lightSVG, darkDemo CSV

How to read it

  1. Read the line as cumulative (or moving) residuals from a regression fitted in time order.
  2. Leaving the boundaries signals a change in the coefficients.
  3. Note where it first crosses: the change happened before that.
  1. Callout 1: Crossing the boundary: unstable coefficients.
  2. Callout 2: The upper 5% boundary.
  3. Callout 3: A stable regression keeps the process near zero.

Watch out

  • The crossing date isn't the break date: use the F sequence or Bai–Perron to date it.

Defaults

Process
OLS-CUSUM
Which fluctuation process to draw: cumulative or moving sums of residuals.
Also: Recursive CUSUM · OLS-MOSUM · Recursive MOSUM
5% critical value (0 = closed form)
0
The analysis sends a simulated value for the MOSUMs; the CUSUMs have closed forms.
Range 0 to 10, step 0.01

Pinned in the code

  • Recursive CUSUM: boundary ±λ(1 + 2t) with λ = 0.948 at 5% (Brown, Durbin & Evans); OLS-CUSUM: ±1.358 (Brownian-bridge supremum).
  • MOSUM boundaries have no closed form: the analysis sends a simulated 5% point (normal errors, predictors held fixed); with none, no boundary is drawn.
  • t runs from 0 to 1 across the process; processes are scaled as strucchange's efp().
# Fluctuation process with boundaries — Codesplash Chart Lab (recipe "fluctuation-process")
# controls: kind=ols-cusum, crit=0
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

try:
    import codesplash as cs  # optional: the app's chart theme
except ImportError:
    cs = None
if cs:
    cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]

df = pd.read_csv("fluctuation-process-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV

_tokens = cs.palette(dark=False) if cs else {}
SEQ = _tokens.get("sequential", ["#eff6fd", "#1a469d"])  # sequential ramp (low → high)
DIV = _tokens.get("diverging", ["#c13e2e", "#f3f5f8", "#0859ac"])  # negative, midpoint, positive
REF = _tokens.get("reference", "#4e5661")
GREY = _tokens.get("dim", "#ced1d6")
def ordered(d, x, cols):
    """Rows with the needed values, sorted by the time column (stable); row order when there is none."""
    d = d.dropna(subset=[c for c in cols if c] + ([x] if x else []))
    return d.sort_values(x, kind="stable") if x else d

def time_of(d, x):
    return d[x] if x else pd.Series(np.arange(1, len(d) + 1), index=d.index)
X = "observations used"
Y = "OLS-CUSUM"
KIND, CRIT = "ols-cusum", 1.358099  # 5% boundary (recursive CUSUM: ±CRIT·(1 + 2t))
d = ordered(df, X, [Y])
x, v = time_of(d, X).to_numpy(dtype=float), d[Y].to_numpy(dtype=float)
t = (x - x[0]) / (x[-1] - x[0])  # 0 … 1 across the process
fig, ax = plt.subplots(figsize=(8, 4))
ax.axhline(0, color="grey", linewidth=0.8)
if CRIT is not None:
    b = CRIT * (1 + 2 * t) if KIND == "rec-cusum" else np.full_like(t, CRIT)
    ax.plot(x, b, color="#ce5342", linestyle="--", linewidth=1.2, label="5% boundary")
    ax.plot(x, -b, color="#ce5342", linestyle="--", linewidth=1.2)
ax.plot(x, v, color=PALETTE[0], linewidth=1.8, label=KIND)
ax.set_xlabel("observations used")
ax.set_ylabel("empirical fluctuation process")
ax.legend(frameon=False)
plt.show()

Needs pandas, numpy, matplotlib · reads fluctuation-process-demo.csv · app theme from the optional codesplash helper