Article-25250-ADF-Test/test_adf.py
alexeynikolaev2 alexeynikolaev2 d6d7f32a5c
2026-11-25 15:56:27 +03:00
20 lines
723 B
Python
import numpy as np
from statsmodels.tsa.stattools import adfuller
# Load time series data from a single-column CSV file
y = np.loadtxt("y.csv")
p = 4
stats = []
crits = []
# Run ADF tests with fixed lag p for all three specifications:
# "n" -> no constant/trend (tau1), "c" -> constant (tau2), "ct" -> constant + trend (tau3)
for reg in ["n", "c", "ct"]:
tau, _, _, _, crit = adfuller(y, maxlag=p, regression=reg, autolag=None, result_object=False)
stats.append(f"{tau:.8f}")
crits.append(f"{crit['5%']:.8f}")
# Print test statistics and 5% critical values formatted to 8 decimal places
print("Python stats (tau1, tau2, tau3):", ", ".join(stats))
print("Python crits (tau1, tau2, tau3):", ", ".join(crits))