Skip to content

Instantly share code, notes, and snippets.

@h3ik0th
Last active September 16, 2021 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h3ik0th/4df628e1c791b545afaeef742b794fa9 to your computer and use it in GitHub Desktop.
Save h3ik0th/4df628e1c791b545afaeef742b794fa9 to your computer and use it in GitHub Desktop.
# should we expect Granger causality, based on cointegration?
# test for cointegration using Engle-Granger
# null hypothesis: Tyrion and Cersei are NOT cointegrated
# we choose lags up to 10, the typical length of a season, during
# which the interested audience received news about Tyrion and Cersei;
score, pvalue, _ = coint(df["Tyrion"], df["Cersei"], maxlag=10)
pvalue
print(f'cointegration: score: {score:.2f}')
print(f'cointegration: p-value: {pvalue:.10f}')
print("cointegrated - there MUST be Granger causality" if pvalue < ALPHA else "NOT cointegrated (uncertain about Granger causality)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment