LoslegenKostenlos loslegen

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.

Diese Übung ist Teil des Kurses

Time Series Analysis in Python

Kurs anzeigen

Anleitung zur Übung

  • 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

Interaktive Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# 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])
Code bearbeiten und ausführen