Skip to content
svgfevd

Forecast error variance decomposition

How much of each series' forecast uncertainty comes from shocks to each series, at each horizon?

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

How to read it

  1. Read each panel as one series' forecast uncertainty at each horizon.
  2. Read the band widths as the share due to each shock.
  3. A series explained mostly by its own shocks at long horizons takes little from the others.

Watch out

  • The split depends on the order of the series, so try another order before reading much into small shares.

Defaults

No settings: the chart draws one way.

Pinned in the code

  • Shares of Σ_{i<h} (Θ_i)² at each horizon h, using the same Cholesky ordering as the impulse responses; the shares at each horizon sum to 100%.
  • A series explained almost entirely by its own shocks at every horizon gets little predictive help from the others.

Use with care

The shares depend on the ordering of the series, like the impulse responses.

# Forecast error variance decomposition — Codesplash Chart Lab (recipe "fevd")
# controls: defaults
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.colors import to_rgba

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"]
# non-colour encodings per series (same table as the app: series are never told apart by colour alone)
SERIES_HATCHES = ["", "////", "..", "\\\\\\\\", "---", "xx", "|||", "++"]
HATCH_INK = to_rgba(plt.rcParams["axes.facecolor"], 0.5)  # stripes let the chart surface show through

df = pd.read_csv("fevd-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["forecast series"] = pd.Categorical(df["forecast series"].astype("string"), categories=["sales", "ad spend", "price"])
df["shock"] = pd.Categorical(df["shock"].astype("string"), categories=["sales", "ad spend", "price"])

_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")
H = "steps ahead"
V = "share"
R = "forecast series"
S = "shock"
responses = list(pd.unique(df[R]))
shocks = list(pd.unique(df[S]))
fig, axes = plt.subplots(1, len(responses), figsize=(8, 3.6), sharey=True, squeeze=False)
for ax, r in zip(axes[0], responses):
    wide = df[df[R] == r].pivot(index=H, columns=S, values=V).reindex(columns=shocks).sort_index()
    # each shock's layer also has its own texture, as in the app
    ax.stackplot(wide.index, wide.T.to_numpy(), labels=shocks, colors=PALETTE[: len(shocks)], hatch=[SERIES_HATCHES[k % 8] for k in range(len(shocks))], hatchcolor=HATCH_INK, linewidth=0, alpha=0.8)
    ax.set_title(str(r), fontsize=9)
    ax.set_ylim(0, 1)
axes[0][0].set_ylabel("share of forecast error variance")
axes[0][0].legend(fontsize=8, loc="lower right")
fig.supxlabel("steps ahead", fontsize=9)
plt.show()

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