Appearance
Engle Granger Residual
Family: Stat-arb
What it computes
Emits EngleGrangerResidualTick ticks carrying hedge_ratio, gamma_intercept, residual_current, residual_zscore off daily-close cache (2 symbols).
Available on the live and replay drives. The historical drive fails closed with KAIROS_ERR_HISTORICAL_UNWIRED until the relevant cache is hydrated externally.
Methodology
Engle-Granger (1987) Stage-1 long-run OLS residual stream ε_t = log(price_a) − γ̂ − δ̂ · log(price_b) with per-tick z-score — Vidyamurthy (2004) pair-trading entry signal.
See the methodology overview for the citation index.
Inputs
Daily-close cache (2 symbols).
Key outputs
Hedge_ratio, gamma_intercept, residual_current, residual_zscore. The full field set is in the tick table below.
Output schema (EngleGrangerResidualTick)
The field / type / description table below is regenerated from the EngleGrangerResidualTick 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_a | Arc<str> | LHS leg of the regression (interned). |
symbol_b | Arc<str> | RHS comparator leg of the regression (interned). |
date | i32 | Trading-session date (YYYYMMDD) at emission time. |
ms_of_day | i32 | Milliseconds since midnight ET at emission time. 0 for watermark-driven boot snapshots before any live tick. |
hedge_ratio | f64 | Long-run OLS slope δ̂ — the per-share hedge ratio (short δ̂ shares of B per long share of A so the spread is mean-reverting under cointegration). |
gamma_intercept | f64 | Long-run OLS intercept γ̂ — the equilibrium log-price differential. |
residual_current | f64 | Latest in-sample residual ε_T = log(price_a)_T − γ̂ − δ̂ · log(price_b)_T — the per-tick spread reading every pair-trading entry signal fires off. |
residual_mean | f64 | In-sample residual mean (1 / N) · Σ ε_t over the trailing window — the centring constant the z-score subtracts. |
residual_stddev | f64 | In-sample residual standard deviation σ_ε = sqrt((1 / N) · Σ (ε_t − mean(ε))²) — the scaling constant the z-score divides by. |
residual_zscore | f64 | Standardised residual z = (residual_current − mean(ε)) / σ_ε — the institutional entry signal: ` |
sessions_used | i32 | Count of paired log-price observations the regression consumed. |
lookback_sessions | i32 | The configured trailing-window length, echoed for audit. |
Configuration (EngleGrangerResidualParams)
Regenerated from the EngleGrangerResidualParams Rust source — see the note above.
| Field | Type | Description |
|---|---|---|
contracts | SecurityFilter | Contracts the subscription tracks — the per-contract [SecurityFilter] resolves symbol_a (the LHS regression leg). |
conditions | ConditionPolicy | Trade-condition admission policy applied to every print. |
venues | ExchangeFilter | Exchange / venue admission policy. |
daily_close | Arc<DailyCloseCache> | Boot-time hydrated daily-close cache. Must hold at least lookback_sessions rows for BOTH symbol_a AND symbol_b for the regression window to populate fully. |
symbol_b | Arc<str> | Fixed comparator leg — symbol_b on the regression log(price_a) = γ + δ · log(price_b) + ε. |
lookback_sessions | usize | Trailing-window length in trading sessions. Defaults to [DEFAULT_LOOKBACK_SESSIONS] (252). |
min_emit_interval_ms | i32 | Minimum interval between emissions per pair, 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().engle_granger_residual(["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()
.engleGrangerResidual(["QQQ"])
.onEvent((tick) => {
console.log(tick);
});Rust
rust
// Cargo.toml:
// kairos = "0.1"
use kairos::{Client, EngleGrangerResidualRow};
# fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::connect(("me@example.com", "secret"))?;
let sub = client
.live()
.engle_granger_residual(["QQQ"])
.on_event(|row: &EngleGrangerResidualRow| {
println!("residual_zscore={} hedge_ratio={}", row.residual_zscore, row.hedge_ratio)
})?;
// ... later ...
sub.unsubscribe();
# Ok(())
# }