股票价格是随机游走吗?
大多数股票价格遵循随机游走(可能带有漂移)。您将查看已预加载到 DataFrame AMZN 中的亚马逊股票价格时间序列,并使用 statsmodels 库中的 "扩展 Dickey-Fuller 检验"(Augmented Dickey-Fuller Test)来检验其确实符合随机游走。
在 ADF 检验中,"原假设"(我们要么拒绝、要么不拒绝的假设)是该序列遵循随机游走。因此,较小的 p 值(例如小于 5%)意味着我们可以拒绝"该序列是随机游走"的原假设。
本练习是课程的一部分
Python 中的时间序列分析
练习说明
- 从 statsmodels 导入
adfuller模块。 - 对收盘价序列运行扩展 Dickey-Fuller 检验,该序列位于
AMZNDataFrame 的'Adj Close'列。 - 打印完整输出,其中包含检验统计量、p 值,以及 1%、5%、10% 显著性水平下的临界值。
- 仅打印该检验的 p 值(
results[0]是检验统计量,results[1]是 p 值)。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Import the adfuller module from statsmodels
from statsmodels.tsa.stattools import adfuller
# Run the ADF test on the price series and print out the results
results = adfuller(___)
print(results)
# Just print out the p-value
print('The p-value of the test on prices is: ' + str(results[___]))