犬のリード?(パート2)
Heating Oil と Natural Gas の価格が共和分していることを確認するために、まず両者がランダムウォークであることを別々にDickey-Fuller検定で確かめます。次に、その差に検定を適用し、ランダムウォーク仮説が強く棄却されることを確認します。Heating Oil と Natural Gas の価格は、DataFrame HO と NG にあらかじめ読み込まれています。
この演習はコースの一部です
Pythonで学ぶ時系列解析
演習の手順
HOとNGそれぞれに対して adfuller 検定を実行し、結果(リスト)を保存します。- adfuller の引数は Series である必要があるため、必ず列
'Close'を指定してください。 - p値(リストの要素 [1])だけを出力してください。
- adfuller の引数は Series である必要があるため、必ず列
- スプレッドについても同様に行います。
HOは単位換算を行い、各DataFrameの列'Close'を使用してください。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Import the adfuller module from statsmodels
from statsmodels.tsa.stattools import adfuller
# Compute the ADF for HO and NG
result_HO = adfuller(____)
print("The p-value for the ADF test on HO is ", result_HO[1])
result_NG = ___(NG['Close'])
print("The p-value for the ADF test on NG is ", result_NG[1])
# Compute the ADF of the spread
result_spread = adfuller(7.25 * ___ - ___)
print("The p-value for the ADF test on the spread is ", result_spread[1])