Ā
1. Learning Objectives
By the end of this lesson, you will be able to:
-
Rigorously define and test for stationarity using ADF and KPSS tests, and apply appropriate transformations (differencing, Box-Cox).
-
Estimate and interpret the Autocorrelation Function (ACF) and Partial Autocorrelation Function (PACF) for model selection.
-
Formulate, estimate, and interpret ARIMA and SARIMA models and use them as benchmark features for AI models.
-
Test for cointegration using the Engle-Granger and Johansen procedures, and construct cointegrated spread features for pairs trading.
-
Formulate and estimate GARCH-family models (GARCH, EGARCH, GJR-GARCH) to extract conditional volatility features.
-
Apply Vector Autoregression (VAR) and Granger Causality tests to multivariate macro-financial datasets.
-
Understand the theoretical link between these econometric models and modern deep learning architectures (RNNs, Transformers).
2. Stationarity ā The Foundation of Predictive Modelling
A time series isĀ weakly stationaryĀ if its first two moments are time-invariant:
-
E[Y_t] = μ (constant mean). -
Var(Y_t) = ϲ (constant variance). -
Cov(Y_t, Y_{t-k}) = γ_kĀ (autocovariance depends only on lagĀk).
Why AI Needs Stationarity:Ā A neural network trained on a non-stationary series learns spurious correlations that change over time. The network’s weights become obsolete as market regimes shift.
2.1 The Augmented Dickey-Fuller (ADF) Test ā The Unit Root TestH_0: The series has a unit root (Non-Stationary).Ā H_1: The series is stationary.
The ADF regression:ĪY_t = α + β*t + γ*Y_{t-1} + Ī£_{i=1}^{p} Ī“_i ĪY_{t-i} + ε_t
If the test statistic for γ is less than the critical value (p < 0.05), we reject H_0 and conclude stationarity.
2.2 The KPSS Test ā The Reverse TestH_0: The series is stationary.Ā H_1: The series has a unit root.
Use both ADF and KPSS. If ADF rejects and KPSS does not ā Stationary. If ADF does not reject and KPSS rejects ā Non-Stationary. If both reject ā Deterministic trend.
2.3 Transformations to Enforce Stationarity
-
Differencing:Ā
āY_t = Y_t - Y_{t-1}. For prices, 1st difference gives returns. For log-prices, 1st difference gives log-returns. -
Log Transformation:Ā
ln(Y_t)Ā stabilises variance. -
Box-Cox Transform:Ā
Y_t^* = (Y_t^Ī» - 1)/λ forĀĪ» ā 0, andĀln(Y_t)Ā forĀĪ» = 0. The optimalĀλ is found via MLE.
3. Autocorrelation and Partial Autocorrelation ā The Memory of Markets
These functions tell us if past returns predict future returns (momentum/reversal).
3.1 Autocorrelation Function (ACF)Ļ_k = Cov(Y_t, Y_{t-k}) / Var(Y_t).
For an i.i.d. series,Ā Ļ_k ā 0Ā for allĀ k ā 0. The Ljung-Box Q-test tests the null that all autocorrelations up to lagĀ mĀ are zero:Q = T(T+2) Ī£_{k=1}^{m} (Ļ_k² / (T-k)) ~ ϲ_m.
IfĀ p < 0.05, significant serial correlation exists ā your AI must use lagged features.
3.2 Partial Autocorrelation Function (PACF)
PACF measures the correlation betweenĀ Y_tĀ andĀ Y_{t-k}}Ā after removing the effects of intermediate lags (Y_{t-1}, ..., Y_{t-k+1}). It is the coefficient ofĀ Y_{t-k}Ā in a linear regression ofĀ Y_tĀ on all previous lags.
AI Application:Ā The ACF and PACF of returns guide theĀ pĀ andĀ qĀ orders for ARIMA models. For an AI model, these functions tell you the minimum number of lagged returns to include as features. If PACF cuts off after lag 5, include exactly 5 lagged returns.
4. ARIMA Models ā The Classical Baseline
The AutoRegressive Integrated Moving Average (ARIMA) model is the gold standard for univariate financial forecasting. It serves as an excellent benchmark to compare against your deep learning model.
4.1 Mathematical Formulation
An ARIMA(p, d, q) model:(1 - Ī£_{i=1}^{p} Ļ_i L^i) * (1-L)^d * Y_t = (1 + Ī£_{j=1}^{q} Īø_j L^j) * ε_t
-
LĀ is the lag operator:ĀL^k Y_t = Y_{t-k}. -
pĀ = AR order (lags of the dependent variable). -
dĀ = degree of differencing. -
qĀ = MA order (lags of the error term). -
ε_t ~ White Noise (0, ϲ).
4.2 Interpretation of Parameters
-
AR(1) model:Ā
Y_t = Ļ_1 Y_{t-1} + ε_t. IfĀĻ_1 > 0, momentum; ifĀĻ_1 < 0, mean reversion. -
MA(1) model:Ā
Y_t = ε_t + θ_1 ε_{t-1}. Captures shocks that persist for exactly one period (e.g., bid-ask bounce).
4.3 SARIMA ā Seasonal ARIMASARIMA(p,d,q)(P,D,Q)_s, whereĀ sĀ is the seasonal period (e.g.,Ā s=5Ā for weekly seasonality in daily returns,Ā s=12Ā for monthly). It includes seasonal lags likeĀ Y_{t-s}}.
AI Integration:Ā You should fit an ARIMA model on your training set, record its 1-step-ahead predictionĀ Y_hat_{t+1}, and useĀ Y_hat_{t+1}Ā as aĀ featureĀ in your deep learning model. The neural network learns to weight and correct the ARIMA forecast.
5. Cointegration ā The Holy Grail of Statistical Arbitrage
Two non-stationary series are cointegrated if a linear combination of them is stationary. This implies a long-run equilibrium relationship.
5.1 Engle-Granger Two-Step Method (Single Cointegrating Vector)
-
RegressĀ
Y_tĀ onĀX_tĀ using OLS:ĀY_t = β_0 + β_1 X_t + z_t. The residualĀz_tĀ is the “spread.” -
TestĀ
z_tĀ for stationarity using the ADF test (without a trend). IfĀz_tĀ is stationary (p < 0.05), the pair is cointegrated. -
The spreadĀ
z_tĀ is a powerful mean-reverting feature for AI.
5.2 Johansen Test (Multiple Vectors)
ForĀ NĀ assets, there can be up toĀ N-1Ā cointegrating vectors. Johansen uses a VAR-based approach to test the rankĀ rĀ of the cointegration matrix. The trace statistic and maximum eigenvalue statistic determineĀ r.
AI Application:Ā Train a neural network to predict the future value of the spreadĀ z_{t+1}. If the model predicts the spread will widen, the strategy goes long the cheap asset and short the expensive one. This is a classic Pairs Trading AI.
6. Volatility Modelling ā The ARCH/GARCH Family
Since volatility is unobservable but is the primary input for risk management, we model it as a time-varying process.
6.1 ARCH(q) ā AutoRegressive Conditional Heteroskedasticity
Let ε_t = Ļ_t * v_t, whereĀ v_t ~ N(0,1).
The conditional variance equation:Ļ_t² = Ļ + Ī£_{i=1}^{q} α_i ε_{t-i}².
High past squared errors predict high future variance (volatility clustering).
6.2 GARCH(p, q) ā The Generalised FormĻ_t² = Ļ + Ī£_{i=1}^{q} α_i ε_{t-i}² + Ī£_{j=1}^{p} β_j Ļ_{t-j}².
The β terms capture the persistence of volatility shocks. The sum Σ α_i + Ī£ β_jĀ measures the “volatility half-life.” If the sum is close to 1, shocks are permanent (IGARCH).
6.3 EGARCH ā Asymmetric GARCH (Leverage Effect)
Markets react asymmetrically: bad news (negative returns) increases volatility more than good news.ln(Ļ_t²) = Ļ + Ī£ α_i * |ε_{t-i}/Ļ_{t-i}| + Ī£ γ_i * (ε_{t-i}/Ļ_{t-i}) + Ī£ β_j ln(Ļ_{t-j}²).
The γ term captures the asymmetry. If γ < 0, negative shocks increase volatility more (the leverage effect).
6.4 GJR-GARCH (Threshold GARCH)Ļ_t² = Ļ + α ε_{t-1}² + γ * I_{t-1} * ε_{t-1}² + β Ļ_{t-1}², whereĀ I_{t-1} = 1Ā if ε_{t-1} < 0, elseĀ 0.
AI Integration:Ā Use the one-step-ahead conditional varianceĀ Ļ_{t+1}² from a GARCH model as a feature. This provides the neural network with a model-based volatility forecast, which is better than a simple rolling standard deviation.
7. Vector Autoregression (VAR) ā Multivariate Dynamics
When we haveĀ KĀ endogenous time series (e.g., returns of 10 sectors), we use VAR.
7.1 Mathematical Formulation (VAR(p))Y_t = c + Φ_1 Y_{t-1} + Φ_2 Y_{t-2} + ... + Φ_p Y_{t-p} + ε_t
Where:
-
Y_tĀ is aĀ(K x 1)Ā vector. -
cĀ is aĀ(K x 1)Ā vector of intercepts. -
Φ_iĀ areĀ(K x K)Ā matrices of coefficients. -
ε_t ~ N(0, Σ) (contemporaneous correlation).
7.2 Granger Causality
VariableĀ XĀ “Granger-causes”Ā YĀ if lagged values ofĀ XĀ improve the prediction ofĀ YĀ beyond using lagged values ofĀ YĀ alone. Test via F-test on the coefficients ofĀ XĀ in the VAR equation forĀ Y.
AI Application:Ā Before feeding 50 macro series into a Transformer, run Granger causality tests.Ā Remove all variablesĀ that do not Granger-cause your target asset. This drastically reduces input dimensionality and prevents the Transformer from learning spurious correlations.
8. Cointegration vs. Correlation ā A Critical Distinction
CorrelationĀ is a contemporaneous measure of co-movement. It is transient and can change sign.
CointegrationĀ is a long-term equilibrium relationship. It is invariant to short-term noise.
AI Rule:Ā If you are building a pairs trading strategy,Ā neverĀ use Pearson correlation to select pairs. Use cointegration (Engle-Granger). Correlation can be high during a bull market but the spread can drift apart infinitely. Cointegration ensures the spread is mean-reverting.
9. From Econometrics to Deep Learning ā The Theoretical Bridge
Understanding these time-series models reveals the inductive biases of neural networks:
| Econometric Concept | Deep Learning Counterpart |
|---|---|
| AR (AutoRegressive) | 1D Convolutional Layers (Conv1d) over lagged features. |
| MA (Moving Average) | Attention mechanism focusing on recent error residuals. |
| VAR (Vector AR) | Multi-head Attention across asset dimensions. |
| GARCH (Volatility) | A separate LSTM/RNN head outputtingĀ Ļ_tĀ as a learned parameter (Mixture Density Networks). |
| Cointegration | The neural network learns a non-linear embeddingĀ z_t = f(Features)Ā that is implicitly stationary through the loss function (e.g., penalising non-mean-reverting outputs). |
| Stationarity requirement | Use of Layer Normalization / Batch Normalization to stabilise hidden states across time. |
| ARIMA benchmark | If your deep learning model cannot beat a simple ARIMA(1,0,1) on a univariate series, your architecture is too complex or your data is pure noise. |
10. Summary for the AI Practitioner
-
Stationarity is non-negotiable.Ā Always run ADF and KPSS. Difference non-stationary features. Apply Box-Cox to variance-stabilise.
-
ACF/PACFĀ tell you the minimum lag context required. Use them to set theĀ
seq_lengthĀ for your LSTM/Transformer. -
ARIMAĀ is your baseline. If your LSTM doesn’t beat a simple ARIMA on the same task, stop and debug your feature engineering.
-
CointegrationĀ is the mathematical foundation for relative value strategies (pairs trading). Use the spreadĀ
z_tĀ as a core feature. -
GARCHĀ extracts the conditional variance, which is a better volatility feature than rolling standard deviation.
-
Granger CausalityĀ is a filter. Use it to prune irrelevant features before training expensive deep learning models.
-
Always benchmark:Ā If an econometric model (ARIMA/GARCH) provides a given Sharpe, your AI model must significantly exceed it to justify the operational complexity.
InĀ Lesson 1.6, we will move from classical time-series toĀ Advanced Financial Data Sources. We will cover alternative data (satellite imagery, credit card transactions, social media sentiment), tick-by-tick order book data (Limit Order Books), and the mathematical challenges of handling irregularly spaced, ultra-high-frequency data using point processes and Hawkes processes.