Appearance
Half Life OU
Family: Stat-arb
What it computes
Emits HalfLifeOuTick ticks carrying phi_hat, intercept, long_run_mean, half_life_bars, half_life_ms off stock trade tape (5m bars).
Available on the live, historical, and replay drives.
Methodology
Ornstein-Uhlenbeck mean-reversion half-life t₁/₂ = -ln(2) / ln(φ̂) via Yule-Walker (1927) AR(1) on rolling per-bar log prices — Vidyamurthy (2004) pair-trading time-to-mean-reversion clock.
See the methodology overview for the citation index.
Inputs
Stock trade tape (5m bars).
Key outputs
Phi_hat, intercept, long_run_mean, half_life_bars, half_life_ms. The full field set is in the tick table below.
Output schema (HalfLifeOuTick)
The field / type / description table below is regenerated from the HalfLifeOuTick Rust source by docs-site/scripts/inject-doc-tables.ts on every npm run docs:build. Do not hand-edit between the sentinels.
| Field | Type | Description |
|---|---|---|
symbol | Arc<str> | Underlying symbol (interned). |
date | i32 | Trading-session date (YYYYMMDD) at emission time. |
ms_of_day | i32 | Milliseconds since midnight ET at emission time. |
phi_hat | f64 | AR(1) slope φ̂ = cov(s_t, s_{t-1}) / var(s_{t-1}) over the rolling-window log-price series. φ̂ ∈ (0, 1) flags the stationary mean-reverting regime; φ̂ ≥ 1 flags the non-stationary regime where the OU null is rejected. |
intercept | f64 | AR(1) intercept â = mean(s_t) − φ̂ · mean(s_{t-1}). |
long_run_mean | f64 | Long-run equilibrium μ̂ = â / (1 − φ̂) — the log-price level the OU process drifts toward over time. |
half_life_bars | f64 | OU half-life in bars t₁/₂ = -ln(2) / ln(φ̂). NaN when the AR(1) fit lands outside the stationary mean-reverting region (0, 1). |
half_life_ms | f64 | OU half-life in milliseconds — half_life_bars * effective_bar_interval_ms. NaN when half_life_bars is NaN. |
n_intraday_bars | i32 | Count of intraday bars currently inside the rolling window. |
Configuration (HalfLifeOuParams)
Regenerated from the HalfLifeOuParams Rust source — see the note above.
| Field | Type | Description |
|---|---|---|
contracts | SecurityFilter | Contracts the subscription tracks. Stocks only. |
conditions | ConditionPolicy | Trade-condition admission policy applied to every print. |
venues | ExchangeFilter | Exchange / venue admission policy. |
bar_interval_ms | i32 | Per-bar cadence in milliseconds. Defaults to [DEFAULT_BAR_INTERVAL_MS] (300_000 ms / 5 min). |
window_bars | i32 | Rolling-window length in bars. Defaults to [DEFAULT_WINDOW_BARS] (78 — one US-equity session). |
min_emit_interval_ms | i32 | Minimum interval between consecutive emissions per symbol, in milliseconds. Defaults to [DEFAULT_MIN_EMIT_INTERVAL_MS] (60_000 ms). |
Example
Python
python
import kairos_thetadata as kt
client = kt.Client.connect(kt.Credentials.from_env())
def on_event(row):
print(row)
sub = client.live().half_life_ou(["QQQ"]).on_event(on_event)
sub.wait(timeout_seconds=60.0)TypeScript
typescript
import { Client, Credentials } from "kairos-thetadata";
const client = await Client.connect(Credentials.fromEnv());
await client
.live()
.halfLifeOu(["QQQ"])
.onEvent((tick) => {
console.log(tick);
});Rust
rust
// Cargo.toml:
// kairos = "0.1"
use kairos::{Client, HalfLifeOuRow};
# fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::connect(("me@example.com", "secret"))?;
let sub = client
.live()
.half_life_ou(["QQQ"])
.on_event(|row: &HalfLifeOuRow| println!("half_life_bars={} long_run_mean={}", row.half_life_bars, row.long_run_mean))?;
// ... later ...
sub.unsubscribe();
# Ok(())
# }