始める無料で始める

犬のリード?(パート2)

Heating Oil と Natural Gas の価格が共和分していることを確認するために、まず両者がランダムウォークであることを別々にDickey-Fuller検定で確かめます。次に、その差に検定を適用し、ランダムウォーク仮説が強く棄却されることを確認します。Heating Oil と Natural Gas の価格は、DataFrame HONG にあらかじめ読み込まれています。

この演習はコースの一部です

Pythonで学ぶ時系列解析

コースを見る

演習の手順

  • HONG それぞれに対して adfuller 検定を実行し、結果(リスト)を保存します。
    • adfuller の引数は Series である必要があるため、必ず列 'Close' を指定してください。
    • p値(リストの要素 [1])だけを出力してください。
  • スプレッドについても同様に行います。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])
コードを編集して実行