ARモデルとランダムウォークを比較する
平均回帰がわずかにある系列と、まったく平均回帰しない系列(ランダムウォークのようなもの)を見分けるのは難しいことがあります。前の演習で扱ったわずかに平均回帰する金利系列のACFを、同じ観測数でシミュレーションしたランダムウォークと比較します。
これら2つの系列の自己相関を並べてプロットすると、非常によく似て見えることに気づくはずです。
この演習はコースの一部です
Pythonで学ぶ時系列解析
演習の手順
statsmodelsモジュールからplot_acf関数をインポートします- 2つのサブプロット用に2つの軸を作成します
- 上段のプロットに、金利系列
interest_rate_dataの12期ラグの自己相関関数を描画します - 下段のプロットに、系列
simulated_dataの12期ラグの自己相関関数を描画します
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Import the plot_acf module from statsmodels
from statsmodels.graphics.tsaplots import plot_acf
# Plot the interest rate series and the simulated random walk series side-by-side
fig, axes = plt.subplots(2,1)
# Plot the autocorrelation of the interest rate series in the top plot
fig = plot_acf(___, alpha=1, lags=12, ax=axes[0])
# Plot the autocorrelation of the simulated random walk series in the bottom plot
fig = plot_acf(___, alpha=1, lags=12, ax=axes[1])
# Label axes
axes[0].set_title("Interest Rate Data")
axes[1].set_title("Simulated Random Walk Data")
plt.show()