拴着的狗?(第 2 部分)
为验证取暖油与天然气价格是否协整,先分别对二者进行 Dickey-Fuller 检验,表明它们是随机游走。然后对二者的差进行检验,该检验应当强烈拒绝随机游走假设。取暖油与天然气价格已预加载在 DataFrame HO 和 NG 中。
本练习是课程的一部分
Python 中的时间序列分析
练习说明
- 分别对
HO和NG做 adfuller 检验,并保存结果(结果为列表)。- adfuller 的参数必须是 Series,因此需要包含列
'Close'。 - 仅打印 p 值(列表中索引为 [1] 的元素)。
- adfuller 的参数必须是 Series,因此需要包含列
- 对价差执行相同操作,再次将
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])