Perform ADF-Test (stationarity test) on several forex pairs at once and rank the results from the most mean-reversion tendency to least
Let’s imagine you have a historical time series of daily closing prices for EUR/USD (EURUSD=X), and you want to test it for stationarity.
Run the Test: You would use a function like adfuller() in Python, feeding it your time series data. The function will run the underlying regression and give you the key outputs: the ADF statistic, the p-value, and critical values at various significance levels.
Now you must interpret these numbers to make a decision about the time series. There are two primary ways to interpret the results, and they should always lead to the same conclusion.
By using the ADF test, you’re moving from a subjective “this pair looks like it’s ranging” to an objective, data-driven “this pair’s statistical properties indicate it’s suitable for mean reversion.”
By running the ADF-test concurrently on several forex pairs and saving the results into a list, we can rank them and then decide which pairs have the most mean-reverting tendency and which have the least.
Set the pair List and the time range to test on
# Define the list of forex pairs to test
# The '=X' suffix is necessary for forex data on Yahoo Finance
forex_pairs = ['AUDUSD=X', 'EURGBP=X', 'NZDUSD=X', 'USDCHF=X',
'AUDJPY=X', 'CADJPY=X', 'EURUSD=X', 'GBPUSD=X',
'NZDJPY=X', 'USDCAD=X', 'CHFJPY=X', 'EURJPY=X',
'EURNZD=X', 'GBPJPY=X', 'USDJPY=X', 'GC=F']
# Define the time period for the data
start_date = '2015-01-01'
end_date = '2025-01-01'
Output Example:
--- Ranked Results (Most Mean-Reverting to Least) ---
Pair ADF Statistic p-value
-------------------------------------
USDCAD=X -3.5570 0.0066
USDCHF=X -3.3585 0.0125
GBPUSD=X -2.8360 0.0533
EURUSD=X -2.7649 0.0635
EURNZD=X -2.6920 0.0754
AUDUSD=X -2.5885 0.0954
NZDUSD=X -2.5133 0.1123
NZDJPY=X -2.2632 0.1841
EURGBP=X -2.1751 0.2154
AUDJPY=X -1.8893 0.3371
CADJPY=X -1.1301 0.7029
GBPJPY=X -1.0640 0.7292
EURJPY=X -0.6527 0.8586
USDJPY=X 0.0834 0.9649
CHFJPY=X 0.4417 0.9830
GC=F 0.5184 0.9854
Back to Index