Skip to content

lewispy/ARDL-Python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ARDL Cointegration and ECM Analysis

A Python function to perform ARDL cointegration analysis and estimate the Error Correction Model (ECM).

Overview

This Python function performs ARDL cointegration analysis and estimates the ECM model. It helps in:

  • Selecting optimal lags using the AIC criterion (if exog_orders is not provided).
  • Estimating the Unrestricted Error Correction Model (UECM).
  • Providing long-run (cointegrating) and short-run (ECM) model summaries.
  • Plotting ARDL residuals (Error Correction Term - ECT), default error diagnostics, and CUSUM plots with 95% confidence bands.

Features

  • Automatic or manual lag selection for ARDL models.
  • Estimation of UECM and ECM models.
  • Long-run and short-run model summaries.
  • Comprehensive error diagnostics and stability tests (CUSUM).

Requirements

To run this function, you need the following libraries:

  • pandas
  • numpy
  • matplotlib
  • statsmodels

Usage


# Import necessary libraries
import pandas as pd
from statsmodels.tsa.ardl import ardl_select_order, UECM
import statsmodels.api as sm
import matplotlib.pyplot as plt
import warnings

Call the ARDL function

ardl_model( dataset=dataframe, y="dependent_variable", X=["independent_variable1", "independent_variable2"], max_lag=4, exog_orders=None # or provide a list of lag orders for exogenous variables )

Function Parameters

  • dataset: The dataset as a Pandas DataFrame.
  • y: The dependent variable (string).
  • X: List of independent variable(s).
  • max_lag: Maximum lag order for selection.
  • exog_orders: List of manually determined lag orders for exogenous variable(s). If None, the function automatically selects lags.

Output

  • The UECM (unconstrained) model
  • Long-run (cointegrating) model summary
  • Short-run (ECM) model summary
  • Plot of the ARDL residuals (ECT)
  • Plot of default error diagnostics
  • The CUSUM plots with 95% confidence bands

Example


# Example usage
import pandas as pd

Load your dataset

df = pd.read_csv("your_dataset.csv")

Run the ARDL model

ardl_model( dataset=df, y="Y_variable", X=["X1", "X2", "X3"], max_lag=3, exog_orders=None )

Notes

  • If exog_orders is not provided, the function will automatically select the optimal lags using the AIC criterion.
  • Ensure that your dataset is free of missing values, as NA values can cause errors during lagging.
  • Use exog_orders to manually specify lag orders if the automatic selection fails.

License

This project is licensed under the MIT License.

Author

Developed by Patrick Onodje. Feel free to reach out for any questions or collaborations on patrickonodje@live.com.

About

A python function that computes ARDL results, the error correction term, and CUSUM plots for model stability check

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors