Class OrnsteinUhlenbeck
java.lang.Object
com.quantfinlib.microstructure.OrnsteinUhlenbeck
Ornstein-Uhlenbeck estimation — the mean-reversion engine under every
pairs trade and basis position:
dx = κ(θ − x)dt + σ dW. Fit
from a sampled series by exact AR(1) mapping (x_{t+1} = a +
b·x_t + ε with b = e^{−κΔt}), giving the three numbers a
spread trader actually uses:
- half-life
ln2/κ— how long the spread takes to close half its gap: the holding-period estimate, and the first filter (a 200-day half-life is not a trade); - z-score
(x − θ)/σ_statwith the STATIONARY stdevσ/√(2κ)— entry/exit in units the strategy can threshold; - the refusal: a fitted
b ≥ 1means the series shows NO mean reversion in-sample — the fit throws rather than reporting an infinite half-life as a tradable number, because fitting OU to a random walk is how pairs desks die.
Small-sample honesty: the OLS AR(1) slope is DOWNWARD-biased in
finite samples (Kendall: E[b_hat - b] ~ -(1+3b)/n), so near the
minimum n=30 the fitted κ runs high and the half-life SHORT — a
20-day true half-life can fit as ~12. Treat short-sample half-lives as
optimistic lower bounds and prefer n in the hundreds before sizing a
holding period off them. Stated, not corrected: bias corrections trade
variance for bias and are themselves sample-size-sensitive.
Static, deterministic, research lane. Pair with
hedging.CointegrationTest (is the spread stationary at all?)
and hand the trade to execution.SpreadExecutionAlgo.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic OrnsteinUhlenbeck.Paramsfit(double[] series, double dt) Fits OU to a series sampled everydttime units (e.g.static doublelastZScore(double[] series, double dt) Convenience: the fitted z-score of the LAST observation.
-
Method Details
-
fit
Fits OU to a series sampled everydttime units (e.g. dt = 1.0/252 for daily samples in years). Throws when the series shows no mean reversion — see class doc.- Parameters:
series- ≥ 30 finite observationsdt- sampling interval, > 0
-
lastZScore
public static double lastZScore(double[] series, double dt) Convenience: the fitted z-score of the LAST observation.
-