← Back to Learn
II IntermediateWeek 3 • Lesson 7Duration: 65 min

TSA Time Series Analysis

Financial data has memory — and exploiting that memory is how you make money

Learning Objectives

  • Understand autocorrelation and what it means for trading
  • Learn ARIMA models — when they work and when they don't
  • Use the Hurst exponent for regime classification
  • Test for stationarity and understand why it matters

Explain Like I'm 5

Time series analysis looks for patterns in data that happen over time. If it rained today, is it more likely to rain tomorrow? Same question with prices — if the market went up today, does that tell us anything about tomorrow? Time series tools help answer that.

Think of It This Way

Financial time series are like weather patterns. There are seasons (regimes), trends (climate change), and random noise (daily weather). You can't predict exact weather tomorrow, but you can know winter is coming. Time series analysis separates the predictable patterns from the noise.

1Autocorrelation — Does the Past Predict the Future?

Autocorrelation measures how correlated a time series is with its own past values. It's one of the first things you should check on any financial data. Positive autocorrelation → trending behavior (momentum) Negative autocorrelation → mean-reverting behavior Zero autocorrelation → random walk (no predictability) Most financial returns show near-zero autocorrelation at lag 1 — because if they didn't, the free money would be too easy and arbitrage traders would crush it immediately. But here's where it gets interesting: • Volatility is highly autocorrelated (volatility clustering — the GARCH effect). A wild day usually precedes another wild day. • Absolute returns show significant autocorrelation out to 20+ lags. • Regime-dependent autocorrelation exists — in trending markets, lag-1 autocorrelation goes positive; in choppy markets, it goes negative. Production systems use autocorrelation at multiple lags as features for ML models. Lags 1 and 5 are particularly useful for detecting momentum vs. mean-reversion regimes.

Typical Autocorrelation of Financial Returns by Lag

2Stationarity — The Foundation Nobody Talks About

Before you do anything with time series, check for stationarity. A stationary series has constant mean, constant variance, and autocorrelation that doesn't change over time. Raw prices are not stationary. They trend, they have changing volatility — they're a mess. You have to transform them first: • Returns (pct_change) — usually stationary • Log returns — even better for many applications • Differenced prices — removes trends How to test:ADF (Augmented Dickey-Fuller): H₀ is "series has a unit root (non-stationary)." Low p-value = stationary. You want p < 0.05. • KPSS: H₀ is "series is stationary." High p-value = stationary. Opposite of ADF. • Run both: If ADF says stationary AND KPSS says stationary, you're good. Why does this matter? Because every statistical model — ARIMA, regression, even many ML models — assumes some form of stationarity. Feed non-stationary data into a model and you get garbage predictions that look amazing in-sample. Classic trap.

3The Hurst Exponent — Regime Detection

The Hurst exponent is one of the most useful tools in quantitative finance. It measures whether a time series is: • H > 0.5 — trending (persistent). What went up tends to keep going up. • H = 0.5 — random walk. No predictability. • H < 0.5 — mean-reverting. What went up tends to come back down. Production trading systems use Hurst for adaptive exit management: • High Hurst (trending) → let winners run with wider stops • Low Hurst (mean-reverting) → take profits quickly with tighter stops This single feature can add meaningful percentage points to your win rate. Knowing the regime changes everything about how you manage trades. The key: Hurst isn't static. It shifts over time as markets change between regimes. You compute it on rolling windows and use the current value to adapt in real-time.

Rolling Hurst Exponent Over Time (Simulated)

4ARIMA — Classical But Limited

ARIMA (AutoRegressive Integrated Moving Average) is the classic time series model. It combines: • AR(p) — past values predict current value • I(d) — differencing to make data stationary • MA(q) — past errors predict current value Honestly, ARIMA is more useful for understanding the concepts than for actual trading predictions. Financial returns are too noisy and regime-switching for ARIMA to work well as a direct price predictor. Where ARIMA is useful: • Modeling volatility (GARCH is basically ARIMA for variance) • As a baseline to beat — if your fancy ML model can't beat ARIMA, your model is bad • For mean-reversion strategies on spreads (cointegrated pairs) Modern production systems tend to skip ARIMA in favor of tree-based or deep learning models. But understanding ARIMA gives you the foundation for everything that came after.

5Practical Regime Detection Workflow

Here's how you actually use all of this together in a real trading system: Step 1: Check stationarity. Run ADF on your returns. If p > 0.05, you need more differencing or a different transformation. Step 2: Compute autocorrelation profile. Plot the ACF for lags 1-20. Significant positive autocorrelation at early lags = trending. Negative = mean-reverting. Step 3: Compute rolling Hurst exponent. Use 100-252 bar windows. This gives you a continuous regime indicator. Step 4: Adapt your strategy. • Hurst > 0.5 → momentum entries, wider stops • Hurst < 0.5 → mean-reversion entries, tighter stops • Hurst ≈ 0.5 → be cautious, reduce size Step 5: Validate regime transitions. Regime changes don't happen instantly. If Hurst jumps from 0.4 to 0.6 in one bar, that's noise. Smooth your regime indicators to avoid whipsawing. This workflow is basically what production ML systems automate with features fed into tree-based models. The model learns these relationships from data instead of you hard-coding rules — but you need to understand the concepts to build good features.

Key Formulas

Autocorrelation at Lag k

Correlation of a series with itself shifted by k periods. |ρ_k| > 2/√T suggests significant autocorrelation at lag k.

Hurst Exponent (R/S Method)

H is estimated from the slope of log(R/S) vs log(n). H > 0.5 = trending, H < 0.5 = mean-reverting. Production systems compute this on rolling windows to detect regime changes in real-time.

Hands-On Code

Computing the Hurst Exponent

python
import numpy as np

def hurst_exponent(series, max_lag=100):
    """Compute Hurst exponent using R/S analysis."""
    lags = range(2, max_lag)
    rs_values = []
    
    for lag in lags:
        # Split into chunks of size 'lag'
        chunks = [series[i:i+lag] for i in range(0, len(series)-lag, lag)]
        rs_chunk = []
        for chunk in chunks:
            if len(chunk) < lag:
                continue
            mean_val = np.mean(chunk)
            cumdev = np.cumsum(chunk - mean_val)
            R = max(cumdev) - min(cumdev)
            S = np.std(chunk, ddof=1)
            if S > 0:
                rs_chunk.append(R / S)
        if rs_chunk:
            rs_values.append(np.mean(rs_chunk))
    
    # Fit log-log relationship
    log_lags = np.log(list(lags[:len(rs_values)]))
    log_rs = np.log(rs_values)
    H = np.polyfit(log_lags, log_rs, 1)[0]
    return H

# Example usage
prices = np.cumsum(np.random.randn(5000)) + 100
H = hurst_exponent(np.diff(prices))
print(f"Hurst Exponent: {H:.3f}")
if H > 0.55: print("→ TRENDING regime")
elif H < 0.45: print("→ MEAN-REVERTING regime")
else: print("→ RANDOM WALK (no clear regime)")

The Hurst exponent is one of the most important features in quant trading. Values above 0.55 indicate trending markets, below 0.45 mean-reverting. This drives how you manage exits.

Knowledge Check

Q1.A Hurst exponent of 0.7 indicates:

Q2.Why do most modern quant systems skip ARIMA for signal generation?

Assignment

Compute the Hurst exponent on rolling 252-bar windows for any financial instrument. Plot it over time. Can you identify periods where the regime switched from trending to mean-reverting? Do those shifts correspond to market events you can research?