Get startedGet started for free

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.

This exercise is part of the course

Time Series Analysis in Python

View Course

Exercise instructions

  • 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

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# 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 and Run Code