Are Bitcoin and Ethereum Cointegrated?
Cointegration involves two steps: regressing one time series on the other to get the cointegration vector, and then perform an ADF test on the residuals of the regression. In the last example, there was no need to perform the first step since we implicitly assumed the cointegration vector was \(\small (1,-1)\). In other words, we took the difference between the two series (after doing a units conversion). Here, you will do both steps.
You will regress the value of one cryptocurrency, bitcoin (BTC), on another cryptocurrency, ethereum (ETH). If we call the regression coefficient \(\small b\), then the cointegration vector is simply \(\small (1,-b)\). Then perform the ADF test on BTC \(\small - b \) ETH. Bitcoin and Ethereum prices are pre-loaded in DataFrames BTC and ETH.
Diese Übung ist Teil des Kurses
Time Series Analysis in Python
Anleitung zur Übung
- Import the statsmodels module for regression and the
adfullerfunction - Add a constant to the
ETHDataFrame usingsm.add_constant() - Regress
BTConETHusingsm.OLS(y,x).fit(), where y is the dependent variable and x is the independent variable, and save the results inresult.- The intercept is in
result.params[0]and the slope inresult.params[1]
- The intercept is in
- Run ADF test on BTC \(\small - b \) ETH
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
# Import the statsmodels module for regression and the adfuller function
import statsmodels.api as sm
from statsmodels.tsa.stattools import adfuller
# Regress BTC on ETH
ETH = sm.___(ETH)
result = sm.OLS(___,___).fit()
# Compute ADF
b = result.params[1]
adf_stats = adfuller(___['Price'] - b*___['Price'])
print("The p-value for the ADF test is ", adf_stats[1])