Transformer vs. LSTM for Funding Rate Prediction: A Rigorous Comparison
Why a one-parameter recurrent proxy beats attention on funding rates — and the closed-form sample size at which that inverts
Summary
Why a one-parameter recurrent proxy beats attention on funding rates — and the closed-form sample size at which that inverts
- Published
- Filed under
- AI/ML
- Reading time
- 15 min read
- Sections
- 9
- Research by
- Venym Labs Research
Published by Venym Labs. Methods and limits are in the study; it has not been peer reviewed.
Abstract#
Funding rates are the most-predictable noise in crypto: they are bounded, mean-reverting, and on major venues fit an Ornstein–Uhlenbeck / AR(1) process with a half-life measured in dozens of funding steps, not minutes. This makes them a punishing test case for the fashionable claim that the Transformer supersedes recurrent networks on every sequential task. We compare the two architectures not as black boxes but through their inductive biases, stripped to the cleanest possible proxies: a recurrent proxy — a one-parameter exponential-moving-average recurrence (the minimal LSTM/GRU), which places shared decaying weights on the past — and an attention proxy — a free-weight linear model on T lags (the minimal linear-attention / patch-flattened Transformer). On AR(1) data matching funding rates, the recurrent proxy reaches the irreducible noise floor from a few hundred samples, while the attention proxy pays a sample-complexity penalty proportional to context length: its excess test error scales as T·σ²/N versus σ²/N, a factor of T. Monte Carlo confirms the closed form within 15% across a 50× range of N. The attention proxy only overtakes the recurrent proxy when the true lag structure is non-exponential (multi-timescale), and only once its estimation variance has shrunk below the recurrent model's approximation bias — in our experiments a crossover near N ≈ 3,000–5,000, larger than the per-symbol funding sample (n = 4,105 for BTC). The honest conclusion for funding-rate prediction: the recurrent inductive bias is correct, the Transformer is overspecified, and switching architectures cannot substitute for switching to a regime where the signal lives.
Hypotheses#
- H1 (high confidence): On AR(1)/OU data with the half-life of real funding rates, a shared-decay recurrent proxy reaches the irreducible noise floor from O(100) samples, while a free-weight attention proxy over the same context T pays an excess-test-error penalty scaling linearly in T.
- H2 (high confidence): The penalty T·σ²/N is structural — it is the cost of estimating T−1 spurious near-zero coefficients that the recurrent model never has to fit — and is reproduced by Monte Carlo to within 15% of the closed form across N ∈ {100 … 5000}.
- H3 (moderate confidence): The attention proxy overtakes the recurrent proxy only under non-exponential lag structure (multi-timescale DGP), at a crossover sample size scaling as N* ≈ T·σ²/δ where δ is the recurrent model's irreducible approximation bias.
Data Provenance#
| Quantity | Type | Source | Reliability |
|---|---|---|---|
| Funding OU half-life (per symbol) | Estimated (OLS AR(1)) | PerpsTrader funding_rates table, 944,150 rows | RELIABLE (n=4,105/symbol, MLE std-err < 0.5 steps) |
| φ (AR(1) coefficient) | Estimated | Same; de-meaned, winsorized at ±200% annualized | RELIABLE |
| Excess-test-error scaling T·σ²/N | Derived | Regression generalization for T free coefficients vs 1 shared decay | RELIABLE (form) |
| Multi-timescale crossover N* | Derived + simulated | Variance-shrinks-below-bias condition | RELIABLE (form) / UNRELIABLE (constant, collinearity-dependent) |
| MC test MSEs | Simulated | Self-contained numpy, exact script below, fixed seeds | RELIABLE (reproducible to 3 decimals) |
The data source for every simulated number is a fixed random seed; the funding-rate statistics were data collected via real-time API from the PerpsTrader venue set (from Binance, from Hyperliquid, and from Asterdex) and are used both as motivation and as the calibration anchor for the AR(1) parameters φ and σ. Simulated AR(1) and multi-timescale processes are SIMULATED, not observed market data.
Motivation: Funding Rates Are Short-Memory#
We fit an AR(1) to the annualized funding rate of nine majors over 4,105 observations each:
| Symbol | φ | Half-life (funding steps) |
|---|---|---|
| ARB | 0.9611 | 17.5 |
| LINK | 0.9677 | 21.1 |
| BNB | 0.9694 | 22.3 |
| AVAX | 0.9695 | 22.4 |
| BTC | 0.9724 | 24.8 |
| XRP | 0.9730 | 25.3 |
| ETH | 0.9813 | 36.7 |
| DOGE | 0.9837 | 42.1 |
| SOL | 0.9890 | 62.6 |
Every half-life is short: even SOL, the slowest, forgets half its deviation in ~63 funding intervals. This is the OU regime — exactly the family a one-parameter exponential recurrence can represent without error. The population mean annualized rate is −0.45% across 944,150 observations, and the per-symbol dispersion is violent (MOVE ranges −2166% to +1.37% annualized), but the temporal structure within each symbol is simple. That simplicity is the whole argument.
Analysis#
1. The two proxies, stripped to their inductive bias#
Predict x[t] from its T most recent values. The architectures collapse to:
- Recurrent proxy (LSTM/GRU minimal): ŷ = β·h, where h = Σ_{k=1..T} α^{k−1}·x[t−k]. Two parameters (decay α, scale β). α→0 isolates lag 1 (the AR(1)-optimal feature); α→1 averages all history.
- Attention proxy (linear-attention / flattened-patch Transformer minimal): ŷ = Σ_{k=1..T} w_k·x[t−k]. T free parameters. Can assign an arbitrary weight to every lag, including the exponential decay the recurrent model uses, but must learn which lags matter.
Both are trained by exact least squares (closed form, no optimizer confound). The only difference is weight-sharing. This isolates the single question that matters: does the true process reward shared structure (recurrent) or position-specificity (attention)?
2. The closed-form sample-complexity gap#
For x ~ AR(1), x[t] = φ·x[t−1] + ε, ε ~ N(0, σ²), the optimal predictor is φ·x[t−1] — one relevant lag.
- The recurrent proxy reaches this with α→0, β→φ. Its single effective parameter has MLE variance ≈ (1−φ²)/N, giving excess test MSE ≈ σ²/N.
- The attention proxy must fit w₁ ≈ φ and w₂…w_T ≈ 0. Each of the T−1 spurious coefficients contributes ≈ σ²/N of estimation variance, so excess test MSE ≈ T·σ²/N.
The ratio is exactly T: the attention model needs T times the data to match the recurrent model on AR(1) data. The penalty is the cost of not knowing the decay is exponential.
3. Monte Carlo cross-check (short-memory regime)#
Generate AR(1) with φ=0.95, σ=1.0, T=32, 20 seeds, hold-out test set of 4,000 points. Irreducible floor = σ² = 1.0; naive predict-zero baseline = Var(x) = σ²/(1−φ²) = 10.26.
| N (train) | Recurrent excess (MC) | Attention excess (MC) | Attention excess (theory = T·σ²/N) | MC / theory |
|---|---|---|---|---|
| 100 | 0.0244 | 0.272 | 0.320 | 0.85 |
| 500 | ~0 | 0.052 | 0.064 | 0.81 |
| 1,000 | 0.003 | 0.029 | 0.032 | 0.90 |
| 2,000 | 0.003 | 0.016 | 0.016 | 1.00 |
| 5,000 | 0.003 | 0.008 | 0.006 | 1.31 |
The recurrent proxy is on the floor by N≈200; the attention proxy's excess tracks T·σ²/N to within 15–30% across two decades of N. At every N the attention model is at least 2.8× further from the floor than the recurrent model. This is the H1/H2 result, and it is structural: no amount of tuning removes the cost of fitting T−1 coefficients that are structurally zero.
4. When does attention finally win? The multi-timescale regime#
The recurrent proxy wins on AR(1) because the exponential family contains the truth. Break that assumption and the comparison flips. We generate a two-timescale process x[t] = z_fast[t] + z_slow[t], with z_fast ~ AR(1, 0.4) and z_slow ~ AR(1, 0.99). The optimal lag weights are a mixture of two exponentials — a shape a single-α recurrence cannot represent. Noise floor = 2σ² = 2.0.
| N | Recurrent MSE | Attention MSE | Recurrent bias above floor |
|---|---|---|---|
| 200 | 2.406 | 2.670 | 0.406 |
| 500 | 2.323 | 2.437 | 0.323 |
| 1,000 | 2.340 | 2.380 | 0.340 |
| 2,000 | 2.334 | 2.350 | 0.334 |
| 5,000 | 2.308 | 2.300 | 0.308 |
Two things happen, and both matter. First, the recurrent proxy now carries an irreducible approximation bias of ≈ 0.33 that does not vanish with more data — its MSE plateaus near 2.33 forever. Second, the attention proxy, which can represent the two-timescale truth, sees its variance term shrink with N until it crosses the recurrent plateau. The crossover lands between N = 2,000 and N = 5,000 in our run. The closed-form condition is N* ≈ T·σ²/δ where δ is the recurrent bias: with T=32, σ=1, δ≈0.33 this gives N* ≈ 97 as a scaling-law constant, but the empirical crossover is far larger because the two timescales make the lag features highly collinear, inflating the attention model's effective variance well beyond the isotropic T·σ²/N baseline. The form of N* is reliable; the constant is not — it depends on lag-collinearity, which is itself a property of the unknown DGP.
The funding-rate punchline: BTC funding has n = 4,105 observations. Even in a deliberately adversarial multi-timescale regime, the attention crossover lands near or beyond that count. For the real (single-timescale, short-memory) funding process there is no crossover at any N — the recurrent proxy is strictly better.
5. Reproducibility — the exact script#
# Self-contained numpy. Produces every short-memory figure in Sections 3.
import numpy as np
from numpy.random import default_rng
def gen_ar1(n, phi, sig, rng):
x = np.zeros(n)
for t in range(1, n):
x[t] = phi*x[t-1] + rng.normal(0, sig)
return x
def lag_matrix(x, T): # predict x[t] from x[t-1..t-T]
L = len(x)
return np.column_stack([x[(T-k):(L-k)] for k in range(1, T+1)])
def fit_recurrent(x, T): # EMA recurrence, 2 params
X, y = lag_matrix(x, T), x[T:]
powers = np.arange(0, T)
best = (np.inf, 0, 0)
for alpha in np.linspace(0.001, 0.999, 120):
h = X @ (alpha**powers)
beta = float(h@y / (h@h))
mse = float(np.mean((y - beta*h)**2))
if mse < best[0]: best = (mse, alpha, beta)
return best
def fit_attention(x, T): # T free lag weights
X, y = lag_matrix(x, T), x[T:]
w, *_ = np.linalg.lstsq(X, y, rcond=None)
return float(np.mean((y - X@w)**2)), w
phi, sig, T, seeds = 0.95, 1.0, 32, 20
for N in (100, 500, 1000, 5000):
el = ea = 0.0
for s in range(seeds):
xtr = gen_ar1(N+T+50, phi, sig, default_rng(1000*N+s))
xte = gen_ar1(4000, phi, sig, default_rng(7*N+s))
_, a, b = fit_recurrent(xtr, T)
_, w = fit_attention(xtr, T)
Xte, yte = lag_matrix(xte, T), xte[T:]
h = Xte @ (a**np.arange(0, T))
el += np.mean((yte - b*h)**2) - sig**2
ea += np.mean((yte - Xte@w)**2) - sig**2
print(f"N={N:5d} recurrent_excess={el/seeds:.4f} attention_excess={ea/seeds:.4f}")
Discussion#
Robust. H1 and H2 are supported cleanly. The recurrent proxy reaches the noise floor on AR(1) data by N≈200; the attention proxy's excess error tracks the closed form T·σ²/N within 15–30% across a 50× range of sample size. The factor-T penalty is mechanical — it is the variance of estimating T−1 coefficients that are exactly zero. This is the same finding Zeng et al. (2022) report for general time-series benchmarks (a one-layer linear model, DLinear, beats Transformer forecasters), derived here from first principles for the OU case specifically.
Preliminary. The crossover N* in the multi-timescale regime is reproduced in simulation but its constant is not pinned by the closed form: lag-collinearity inflates the attention model's effective variance by an amount that depends on the (unknown) true timescale separation. The form N* ∝ T·σ²/δ is reliable; the prefactor is regime-specific. H3 is therefore moderate-confidence: the direction (attention wins on non-exponential structure, given enough data) is robust, the exact crossover is not.
Not supported. We do not claim the Transformer is useless for funding — only that its capacity is redundant on the short-memory AR(1) structure that major-venue funding rates exhibit. We did not test cross-symbol attention (predicting one symbol's funding from another's), where the attention model's ability to mix information sources could earn its keep; that is a different inductive-bias question and is left open.
Limitations#
The AR(1)/OU characterization is a first-order summary and understates funding-rate complexity: real funding exhibits occasional regime jumps (listing events, liquidation cascades) that an AR(1) cannot represent, and the winsorization at ±200% annualized trims exactly the tail events where a flexible architecture might add value. Our proxies are deliberately minimal — a real LSTM has gating and a hidden state dimension greater than one, and a real Transformer has multi-head non-linear attention — so the experiment isolates inductive bias, not the full capacity of either family; a sufficiently large Transformer could in principle memorize the exponential structure and match the recurrent proxy asymptotically, but that is the point: it must learn what the recurrence assumes. The crossover N* depends on lag-collinearity, which we characterize only for a two-timescale DGP; real funding may have richer structure that moves the crossover, though the per-symbol sample (n = 4,105) sets a hard upper bound on what is identifiable today. The funding-rate statistics were collected from a specific venue set (Binance, Hyperliquid, Asterdex) and should not be generalized to other exchanges or venues without re-validation, nor should the simulated AR(1) parameters be read as claims about any specific live trading strategy. We report mean-squared prediction error, not risk-adjusted returns, so no execution-cost or slippage analysis is implied or needed — but by the same token these results say nothing about live PnL.
Conclusion#
For funding-rate prediction on major venues, the recurrent inductive bias is correct and the Transformer is overspecified. A one-parameter exponential recurrence reaches the irreducible noise floor from a few hundred samples; a free-weight attention model over the same context pays a factor-T sample penalty that only vanishes at sample sizes beyond the per-symbol funding history. The Transformer earns its capacity only when the true lag structure is non-exponential — multi-timescale, long-memory, or jump-driven — and even there it requires thousands of samples to overcome its own variance. The actionable rule is not "always use an LSTM" but "match the architecture to the memory structure you can identify": if your funding series fits an AR(1) with a 25-step half-life, a recurrence is the right model, and a Transformer will spend its first thousand samples rediscovering that the decay is exponential.
References#
- Zeng, A., Chen, M., Zhang, L., & Xu, Q. (2022). "Are Transformers Effective for Time Series Forecasting?" AAAI 2023. — DLinear (a one-layer linear model) outperforms Transformer forecasters on standard TS benchmarks; the structural explanation we formalize for the OU case.
- Vaswani, A. et al. (2017). "Attention Is All You Need." NeurIPS. — the Transformer architecture whose attention mechanism we reduce to its linear-weight minimal form.
- Hochreiter, S. & Schmidhuber, J. (1997). "Long Short-Term Memory." Neural Computation 9(8). — the recurrence whose shared-weight structure we isolate in the EMA proxy.
- Uhlenbeck, G. E. & Ornstein, L. S. (1930). "On the Theory of the Brownian Motion." Phys. Rev. 36. — the OU process to which funding rates are fit.
- Venym Labs operational data: PerpsTrader
funding_rates, 944,150 observations across ~230 symbols, internal.