ACF と PACF
ドイツ国債(Bund)に対する月次のソブリン債利回りスプレッドの ACF と PACF(95% 有意帯付き)。

自己相関関数(ACF)は、時系列が k 期前の自分自身とどの程度強く相関しているかを測ります。偏自己相関(PACF)は、その間にある短いラグの影響を取り除いたうえで同じことを行います。灰色の帯(±1.96/√n)からはみ出す棒は、ホワイトノイズから生じる値より大きいものです。2つのパネルを合わせて見ると、モデルの見当が付きます。ここでは ACF が何か月にもわたってゆっくり減衰する(今月スプレッドが広ければしばらく広いまま)一方、PACF は 2 ラグ で切断されており、これは AR(2) 過程の特徴です。
設定は Warin & Stojkov (2023, Entropy) で、欧州のソブリン債利回り格差を扱っています。ここでのデータは説明のために シミュレーション したもので、論文のデータや結果ではありません。ユーロ圏のある国の 10 年債利回りのドイツ国債(Bund)に対するスプレッド(パーセントポイント)で、2003 年 1 月から 2022 年 12 月までの月次データ(n = 240)を AR(2) 過程として生成しています。相関は statsmodels.tsa.stattools.acf と pacf によるもので、サブタイトルには自己相関なしを帰無仮説とするリュン・ボックス検定を示しています。
コードおよび図中のテキストは英語です。
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from statsmodels.stats.diagnostic import acorr_ljungbox
from statsmodels.tsa.stattools import acf, pacf
# Simulated data, set in the context of Warin & Stojkov (2023) [warin2023entropy]
# Data: monthly 10-year spread over the Bund (percentage points), simulated AR(2)
rng = np.random.default_rng(2024)
n, nlags = 240, 30
e, s = rng.normal(0, 0.12, n + 100), np.zeros(n + 100)
for t in range(2, n + 100):
s[t] = 1.3 * s[t - 1] - 0.4 * s[t - 2] + e[t] # AR(2): persistent, mean-reverting
y = pd.Series(1.5 + s[100:], index=pd.date_range("2003-01-01", periods=n, freq="MS"))
band = 1.96 / np.sqrt(n)
lb = acorr_ljungbox(y, lags=[10]).iloc[0]
fig = plt.figure(figsize=(10, 6.5))
gs = fig.add_gridspec(2, 2, height_ratios=[1, 1.2])
ax_ts = fig.add_subplot(gs[0, :])
axes = [fig.add_subplot(gs[1, 0]), fig.add_subplot(gs[1, 1])]
# Top: the series itself
ax_ts.plot(y.index, y, color="#1D1D1F", lw=1.2)
ax_ts.axhline(y.mean(), color="#AEAEB2", lw=1, ls="--")
ax_ts.set(ylabel="Spread vs Bund (pp)", xlim=(y.index[0], y.index[-1]))
# Bottom: ACF and PACF as lollipops with the white-noise band
values = [acf(y, nlags=nlags)[1:], pacf(y, nlags=nlags, method="ywm")[1:]]
for ax, v, name in zip(axes, values, ["ACF", "PACF"]):
lags = np.arange(1, nlags + 1)
sig = np.abs(v) > band
colors = np.where(sig, "#007AFF", "#AEAEB2")
ax.axhspan(-band, band, color="#E5E5EA", alpha=0.7, lw=0)
ax.axhline(0, color="#8E8E93", lw=0.8)
ax.vlines(lags, 0, v, color=colors, lw=1.6)
ax.scatter(lags, v, s=28, color=colors, edgecolor="white", lw=0.8, zorder=3)
ax.set(xlabel="Lag (months)", ylabel=name, ylim=(-1, 1), xlim=(0, nlags + 1))
ax.set_xticks(range(0, nlags + 1, 5))
ax.set_yticks([-1, -0.5, 0, 0.5, 1], ["−1", "−0.5", "0", "0.5", "1"])
last = np.flatnonzero(np.abs(values[1]) > band)[-1] + 1 # last significant PACF lag
for lag in (1, last):
axes[1].annotate(f"{values[1][lag - 1]:+.2f}", (lag, values[1][lag - 1]),
xytext=(10, 0), textcoords="offset points", va="center",
fontsize=9, color="#007AFF", fontweight="semibold")
ax_ts.set_title(f"The bond spread is persistent: the PACF cuts off after lag {last}", pad=26)
p_txt = "p < .001" if lb.lb_pvalue < 0.001 else f"p = {lb.lb_pvalue:.3f}"
ax_ts.text(0, 1.04, f"Monthly, 2003–2022, n = {n} (simulated) · Ljung–Box Q(10) = {lb.lb_stat:.0f}, "
f"{p_txt} · grey band = ±1.96/√n", transform=ax_ts.transAxes, fontsize=9.5, color="#6E6E73")
plt.show()
図にはオプションの PyStatlas スタイル を使用しています。同じ見た目にするには plt.style.use("pystatlas.mplstyle") を追加してください。
データの出典
- Simulated data. Simulated data with a fixed random seed, created for this example.
No real respondents, documents or measurements: the numbers only illustrate how the chart and its statistics work. - Warin & Stojkov (2023), sovereign bond yield differentials in Europe. Warin, T., & Stojkov, A. (2023). Sovereign bond yield differentials across Europe: A structural entropy perspective. Entropy, 25(4), 630. https://doi.org/10.3390/e25040630
The example is set in the context of this paper; unless its description says otherwise, the numbers are simulated and are not the paper's data or results.
これらの例は統計手法を説明するためのものです。項目に別の記載がない限り数値はシミュレーションであり、図のタイトルはこのシミュレーションデータで図が示す内容を述べたものです。引用した論文の知見でも、実質的な問いに対する著者の立場でもありません。結果、背景、データについては、ここに挙げた論文を参照してください。
引用方法
PyStatlas は Thierry Warin が作成・運営しています。研究や業務に役立った場合は、ぜひ引用してください。
Warin, T. (2026). ACF and PACF. In PyStatlas: A Python Gallery of Statistical Graphics for the Social Sciences (Version 1.1.0) [Computer software]. https://warin.ca/pystatlas/time-series/acf-pacf/
@misc{warin2026statlas,
author = {Warin, Thierry},
title = {PyStatlas: A Python Gallery of Statistical Graphics for the Social Sciences},
year = {2026},
version = {1.1.0},
howpublished = {\url{https://warin.ca/pystatlas/}},
note = {Source code: https://github.com/warint/pystatlas}
}