Skip to content
svgvolatility-band

Volatility band

When was the series calm or turbulent, and how wide should the next moves be expected to be?

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

How to read it

  1. Read the line as the series and the band as its expected range at each moment.
  2. A wide band marks a turbulent period; volatility tends to cluster.
  3. Read the extension at the end as how wide the next moves should be expected to be.

Watch out

  • The band models size, not direction: it says nothing about which way the series will move.

Defaults

Band (σ)
2
How many conditional standard deviations the band spans on each side of the mean.
Range 0.5 to 4, step 0.5

Pinned in the code

  • The band is mean ± k σ_t with σ_t the model's conditional standard deviation; the forecast part continues it with the variance forecasts.
  • With k = 2 about 95% of normally distributed moves fall inside; fat-tailed returns breach it more often.

Use with care

A wider band says larger moves are likely, in either direction; it says nothing about which way the series will go.

# Volatility band — Codesplash Chart Lab (recipe "volatility-band")
# controls: k=2
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("volatility-band-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["day"] = pd.to_datetime(df["day"])
df["kind"] = pd.Categorical(df["kind"].astype("string"), categories=["fit", "forecast"])

_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")
X = "day"
SIGMA = "volatility"
V = "return"
M = "mean"
KIND = "kind"
K = 2  # band = mean ± K·sigma
d = df.dropna(subset=[SIGMA])
d = d.sort_values(X, kind="stable") if X else d
t = d[X] if X else np.arange(1, len(d) + 1)
mid = d[M] if M else 0.0
ahead = (d[KIND].astype(str) == "forecast").to_numpy() if KIND else np.zeros(len(d), dtype=bool)
fig, ax = plt.subplots(figsize=(8, 4))
ax.fill_between(t, mid - K * d[SIGMA], mid + K * d[SIGMA], where=~ahead, color=PALETTE[0], alpha=0.22, linewidth=0, label=f"Fitted ±{K} σ")
if ahead.any():
    ax.fill_between(t, mid - K * d[SIGMA], mid + K * d[SIGMA], where=ahead, color=PALETTE[1], alpha=0.3, linewidth=0, label=f"Forecast ±{K} σ")
if V:
    ax.plot(t, d[V], color=GREY, linewidth=0.8, label=V)
ax.legend(fontsize=8)
plt.show()

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