Appearance
Rolling Correlation
Family: Stat-arb
What it computes
Emits RollingCorrelationTick ticks carrying correlation, mean_return, variance, sessions_used 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
Pearson (1895) product-moment correlation ρ ∈ [-1, +1] over trailing daily log-return window — Gatev / Goetzmann / Rouwenhorst (2006) pair-trading candidate screen.
See the methodology overview for the citation index.
Inputs
Daily-close cache (2 symbols).
Key outputs
Correlation, mean_return, variance, sessions_used. The full field set is in the tick table below.
Output schema (RollingCorrelationTick)
The field / type / description table below is regenerated from the RollingCorrelationTick 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> | Target leg of the pair (interned). |
comparator_symbol | Arc<str> | Comparator leg of the pair (interned). Echoed on every emission so consumers can audit the spec wiring directly. |
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. |
correlation | f64 | Pearson correlation ρ ∈ [-1, +1]. NaN on a degenerate window (fewer than two paired returns or zero variance on either leg). |
mean_return | f64 | Sample mean log return for the target leg over the window. |
comparator_mean_return | f64 | Sample mean log return for the comparator leg over the window. |
variance | f64 | Sample variance of the target leg over the window. |
comparator_variance | f64 | Sample variance of the comparator leg over the window. |
sessions_used | i32 | Count of paired log-return observations the kernel actually consumed. Values below lookback_sessions signal a warm-up regime where the fit is computed off a shorter window than the institutional target. |
lookback_sessions | i32 | The configured trailing-window length, echoed for audit so consumers can compare sessions_used against the target directly. |
Configuration (RollingCorrelationParams)
Regenerated from the RollingCorrelationParams Rust source — see the note above.
| Field | Type | Description |
|---|---|---|
contracts | SecurityFilter | Contracts the subscription tracks — the per-contract [SecurityFilter] resolves the target leg (symbol). Stocks only — the analytic silently ignores option / index trades at the on_tick entry point. |
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 + 1 rows for BOTH the tracked symbol AND the comparator_symbol for the per-pair window to populate. |
comparator_symbol | Arc<str> | Fixed comparator symbol — the second leg of the pair the estimator correlates the target leg against. Subscribers thread the comparator through the spec; the per-contract [SecurityFilter] resolves the target leg. |
lookback_sessions | usize | Trailing-window length in trading sessions. Defaults to [DEFAULT_LOOKBACK_SESSIONS] (60). Production fits accept up to a full trading year (252 sessions) for the long-horizon weekly-return convention. |
min_emit_interval_ms | i32 | Minimum interval between emissions per pair, in milliseconds. Defaults to [DEFAULT_MIN_EMIT_INTERVAL_MS] (60_000 ms / 1 min). |
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().rolling_correlation(["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()
.rollingCorrelation(["QQQ"])
.onEvent((tick) => {
console.log(tick);
});Rust
rust
// Cargo.toml:
// kairos = "0.1"
use kairos::{Client, RollingCorrelationRow};
# fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::connect(("me@example.com", "secret"))?;
let sub = client
.live()
.rolling_correlation(["QQQ"])
.on_event(|row: &RollingCorrelationRow| println!("correlation={}", row.correlation))?;
// ... later ...
sub.unsubscribe();
# Ok(())
# }