株式リターンではどうでしょう?
前の演習では、DataFrame AMZN に含まれるAmazonの株価がランダムウォークに従うことを確認しました。本演習では、Amazonのリターン(価格のパーセント変化)について同様に検証し、リターンはランダムウォークに従わないことを示します。
この演習はコースの一部です
Pythonで学ぶ時系列解析
演習の手順
- statsmodels から
adfullerモジュールをインポートします。 .pct_change()メソッドを使って価格のパーセント変化を取り、AMZNのリターンの新しいDataFrameを作成します。- DataFrameの
.dropna()メソッドで、リターンの最初の行にある NaN を取り除きます。 AMZN_retの'Adj Close'列に対してAugmented Dickey-Fuller検定を実行し、results[1]にある p値 を出力します。
実践的なインタラクティブ演習
このサンプルコードを完成させて、この演習に挑戦してみましょう。
# Import the adfuller module from statsmodels
from statsmodels.tsa.stattools import adfuller
# Create a DataFrame of AMZN returns
AMZN_ret = ___
# Eliminate the NaN in the first row of returns
AMZN_ret = ___
# Run the ADF test on the return series and print out the p-value
results = adfuller(___)
print('The p-value of the test on returns is: ' + str(results[___]))