MulaiMulai sekarang secara gratis

A Dog on a Leash? (Part 2)

To verify that Heating Oil and Natural Gas prices are cointegrated, First apply the Dickey-Fuller test separately to show they are random walks. Then apply the test to the difference, which should strongly reject the random walk hypothesis. The Heating Oil and Natural Gas prices are pre-loaded in DataFrames HO and NG.

Latihan ini adalah bagian dari kursus

Time Series Analysis in Python

Lihat Kursus

Petunjuk latihan

  • Perform the adfuller test on HO and on NG separately, and save the results (results are a list)
    • The argument for adfuller must be a series, so you need to include the column 'Close'
    • Print just the p-value (item [1] in the list)
  • Do the same thing for the spread, again converting the units of HO, and using the column 'Close' of each DataFrame

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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])
Edit dan Jalankan Kode