Unit Root Testing

Unit root testing plays a crucial role in time series analysis, especially in the evaluation of financial data for algo-trading strategies. The presence of a unit root in a time series can affect the reliability of statistical inferences, necessitating thorough testing to ascertain the properties of the data. This document delves into the conceptual understanding, methodologies, and applications of unit root testing in the context of algorithmic trading.

Conceptual Background

Time Series and Stationarity

A time series is a series of data points indexed in time order, often used to track variables over time. Stationarity is a key property of time series data that must be considered in statistical modelling. A time series is said to be stationary if its statistical properties such as mean, variance, and autocorrelation are constant over time. Stationary time series are easier to model and predict, making them a preferred choice in econometrics and finance.

Unit Root

A unit root is a feature of some stochastic processes that indicates a non-stationary time series. Essentially, if a time series has a unit root, it shows a systematic pattern that is not constant over time, meaning the series can exhibit persistent, random walks. This trait poses challenges in modelling as standard statistical techniques assume stationarity.

Definitions and Mathematical Representation

Consider a time series y_t. The presence of a unit root is often tested using the following autoregressive model:

y_t=c+\rho y_{t-1}+\varepsilon_t
AR(1) and random-walk paths StockSharp JS-Charts

Enter the starting value and innovations in time order. A coefficient of one gives a random walk with the chosen drift. The long-run mean is defined when the absolute coefficient is less than one.

Loading calculator…

Where:

If \rho = 1, the series has a unit root (is non-stationary). Alternatively, if |\rho| < 1, the series is stationary.

Several statistical tests are designed to identify the presence of unit roots in time series data. Prominent among these are:

1. Augmented Dickey-Fuller (ADF) Test

The ADF test is a widely used method for testing the null hypothesis that a unit root is present in a time series sample. It extends the Dickey-Fuller test to include higher-order autoregressive processes.

The test uses the model:

\Delta y_t=d_t+\gamma y_{t-1}+\sum_{i=1}^{p}\delta_i\Delta y_{t-i}+\varepsilon_t

Choose the deterministic term d_t. It can be zero, a constant or a constant plus a linear trend. A lag order of zero gives the Dickey–Fuller regression. The test has a unit root as its null hypothesis.

Augmented Dickey–Fuller test StockSharp JS-Charts

Enter equally spaced observations in time order. Choose the deterministic terms and lagged differences. Reject the unit-root null when the statistic is below the selected MacKinnon critical value.

Loading calculator…

\tau_{\mathrm{ADF}}=\frac{\widehat\gamma}{\operatorname{SE}(\widehat\gamma)},\qquad H_0:\gamma=0
BTC/USD Daily candles Kraken
StockSharp JS-Charts

Each window tests BTC/USD daily log prices with an intercept in the ADF regression. The unit-root null is rejected at 5% when the statistic falls below the critical line.

Loading candle history…

The null hypothesis H_0: \gamma = 0 implies a unit root, meaning non-stationarity.

2. Phillips-Perron (PP) Test

The Phillips–Perron test starts from a Dickey–Fuller regression of the change in the series on its previous level. The deterministic term d_t can be zero, an intercept or an intercept and a linear trend. The null is a unit root.

\Delta y_t=d_t+\gamma y_{t-1}+e_t,\qquad H_0:\gamma=0
Z_\tau=\sqrt{\frac{\widehat c_0}{\widehat\lambda^2}}\,\tau-\frac{\widehat\lambda^2-\widehat c_0}{2\sqrt{\widehat\lambda^2}}\frac{n\,\operatorname{SE}(\widehat\gamma)}{s},\qquad \tau=\frac{\widehat\gamma}{\operatorname{SE}(\widehat\gamma)}
\widehat c_j=\frac{1}{n}\sum_{t=j+1}^{n}\widehat e_t\widehat e_{t-j},\qquad \widehat\lambda^2=\widehat c_0+2\sum_{j=1}^{L}\left(1-\frac{j}{L+1}\right)\widehat c_j

The correction uses the regression residuals \widehat e_t. Here n is the number of observations in the regression, s is the residual standard error and L is the number of lags in the Bartlett estimate. A statistic below the MacKinnon critical value rejects the unit-root null. Phillips–Perron reference implementation

Phillips–Perron unit-root test StockSharp JS-Charts

Enter equally spaced observations in time order. The lag setting controls the Bartlett long-run variance. Reject the unit-root null when the corrected statistic falls below the critical value.

Loading calculator…

BTC/USD Daily candles Kraken
StockSharp JS-Charts

Each window tests BTC/USD daily log prices using an intercept and Bartlett weights. The unit-root null is rejected at 5% when the Phillips–Perron statistic falls below the critical line.

Loading candle history…

3. KPSS Test

Remove an intercept or a linear trend from the series and form the cumulative sums S_t of the residuals \widehat e_t. The estimated long-run variance \widehat s^2 uses Bartlett weights. The selected stationarity null is rejected when the statistic is above the critical value.

\operatorname{KPSS}=\frac{\sum_{t=1}^{n}S_t^2}{n^2\widehat s^2},\qquad S_t=\sum_{j=1}^{t}\widehat e_j
KPSS stationarity test StockSharp JS-Charts

The test removes a constant or a linear trend and uses Bartlett weights for the long-run variance. Reject stationarity when the statistic is above the critical value.

Loading calculator…

BTC/USD Daily candles Kraken
StockSharp JS-Charts

Each window tests BTC/USD daily log prices for level stationarity. The stationarity null is rejected at 5% when the KPSS statistic rises above the critical line.

Loading candle history…

4. Zivot-Andrews Test

The Zivot–Andrews test searches for a single unknown structural break under the trend-stationary alternative. The auxiliary regressions include an intercept and a linear time trend.

\Delta y_t=\alpha+\beta t+\theta D_t(b)+\psi H_t(b)+\gamma y_{t-1}+\sum_{i=1}^{p}\delta_i\Delta y_{t-i}+e_t
D_t(b)=\mathbf{1}\{t>b\},\qquad H_t(b)=\max(0,t-b)
Z_{\mathrm{ZA}}=\min_{b\in\mathcal B}\frac{\widehat\gamma_b}{\operatorname{SE}(\widehat\gamma_b)}

The one-based position b is the last observation before the shift. The level model uses D_t, the slope model uses H_t, and the combined model uses both. The level and combined models scan positions from the lower trimming boundary plus one through the upper boundary. The slope-only model shifts both boundaries one observation earlier to match the reference convention. The chart holds the lag order p fixed, finds the minimum t-statistic and compares it to the simulated critical values for that model. Zivot–Andrews reference implementation

Zivot–Andrews test for one structural break StockSharp JS-Charts

Enter equally spaced observations in time order. The test holds the number of lagged differences fixed and trims 15% of the sample at each end. Compare the lowest statistic to the critical value for the selected break model.

Loading calculator…

Algorithmic Trading and Unit Root Testing

Importance in Algo-Trading

Algorithmic trading relies heavily on accurate data modelling and forecasts. Non-stationary time series can lead to misleading statistical inferences and poor trading decisions. Thus, determining if a time series has a unit root is pivotal for developing reliable pricing models.

Model Selection

  1. Mean-Reversion Strategies: These strategies assume that prices will revert to their mean over time. A unit root test can help identify whether the prices follow a random walk or exhibit mean-reverting properties.
  2. Forecasting and Risk Management: Accurate forecasts require stationarity in time series. Identifying unit roots enables transformations (e.g., differencing) to achieve stationarity, improving model performance.
  3. Cointegration Analysis: In pairs trading, cointegration analysis involves identifying pairs of assets whose prices move together in the long term. Unit root tests are used to confirm that the price series of each asset is individually non-stationary but a linear combination is stationary.

Software and Tools

Several software packages offer unit root testing functionalities, integrating these tests into broader econometric analysis tools:

R

Python

MATLAB

EViews

A sophisticated econometric software providing comprehensive support for time series analysis, including unit root tests.

Application Examples in Algo-Trading

  1. ETF Analysis: Using unit root tests to identify non-stationary ETFs and applying mean-reversion strategies.
  2. Forex Trading: Determine the stationarity of currency pairs to model exchange rate dynamics accurately.
  3. Stock Index Futures: Identifying unit roots in stock index futures for risk management and portfolio optimization.

Challenges and Considerations

Structural Breaks

Structural changes in economic series (e.g., policy changes, market crashes) can affect the results of unit root tests. Tests like Zivot-Andrews are designed to handle such breaks.

Model Selection

Choosing the correct lag length in tests (like ADF) is critical. Overfitting or underfitting can lead to inaccurate results.

Pre-Test Bias

Conducting multiple unit root tests increases the likelihood of Type I and Type II errors. Careful interpretation and corroboration with other methods are advisable.

Software Implementation

Implementations across software can yield different results due to variations in default settings and underlying algorithms. Consistency in approach and verification through multiple platforms is recommended.

Conclusion

Unit root testing is indispensable for robust time series analysis in algorithmic trading. Understanding and correctly applying unit root tests ensures that traders can make well-founded decisions based on reliable models. Proper identification and transformation of non-stationary data into stationary formats enable the development of effective trading strategies, ultimately leading to better risk management and higher returns.