那股價報酬呢?
在上一個練習中,你已經證明了存放在 DataFrame AMZN 的 Amazon 股價符合隨機漫步。在這個練習中,你要對 Amazon 的報酬(價格的百分比變動)做相同的檢查,並說明報酬不符合隨機漫步。
本練習屬於課程
Python 中的時間序列分析
練習說明
- 從 statsmodels 匯入
adfuller模組。 - 使用
.pct_change()方法對價格取百分比變動,建立 AMZN 報酬的新 DataFrame。 - 在 DataFrame 上使用
.dropna()方法,移除報酬第一列的 NaN。 - 對
AMZN_ret的'Adj Close'欄執行擴增 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[___]))