The pValue result of the Adfuller test are different under different Python versions

I am testing the stationary using adf test for pair trading, and found that the results of the Adfuller test in statsmodels.tsa.stattools are different under different Python versions。

In python 3.8:

    from statsmodels.tsa.stattools 
    import adfuller 
    data = [1, 2, 3, 4, 5, 6, 7, 8,9, 10, 11] 
    result = adfuller(data) 
    result[1] 
    
    print(f"ADF Statistic: {result[0]}") ADF Statistic: 1.0458250331675945 
    print(f"p-value: {result[1]}") p-value: 0.9947266780527716

In Python 3.12

    from statsmodels.tsa.stattools import adfuller 
    data = [1, 2, 3, 4, 5, 6, 7, 8,9, 10, 11] 
    result = adfuller(data)
    print(f"ADF Statistic: {result[0]}") ADF Statistic: -1.9028109877684682 
    print(f"p-value: {result[1]}") p-value: 0.330739891075021 

Why the same code lead to different p value?

Thanks

Searched using AI, and found it is because of the default parameter
result = adfuller(data, maxlag=1, autolag=None, regression='c')

If true, then, the follow up question is that, which parameters should been used for the stationary test?

Hi,

Thank you for reaching out.

Please find below the response:

  • If your data looks like a random walk with drift → use regression='ct'
  • If your data looks mean-reverting → use regression='c' (most spreads)
  • Use autolag='AIC' for robustness, unless you want to fix maxlag for consistency across environments

result = adfuller(data, autolag=‘AIC’, regression=‘c’)

The above is the standard choice in quant finance research / pairs trading, because spreads are usually stationary around a constant.

Thanks!

1 Like