那股票收益呢?
在上一个练习中,您已经证明了 Amazon 的股价(存放在 DataFrame AMZN 中)遵循随机游走。本练习中,您将对 Amazon 的收益率(价格的百分比变化)做同样的检验,并展示收益率并不遵循随机游走。
本练习是课程的一部分
Python 中的时间序列分析
练习说明
- 从 statsmodels 导入
adfuller模块。 - 使用
.pct_change()方法对价格取百分比变化,创建新的 AMZN 收益率 DataFrame。 - 在该 DataFrame 上使用
.dropna()方法,去除收益率首行中的 NaN。 - 对
AMZN_ret的'Adj Close'列运行增广 Dickey-Fuller(ADF)检验,并打印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[___]))