Skip to content

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.

FieldTypeDescription
symbolArc<str>Target leg of the pair (interned).
comparator_symbolArc<str>Comparator leg of the pair (interned). Echoed on every emission so consumers can audit the spec wiring directly.
datei32Trading-session date (YYYYMMDD) at emission time.
ms_of_dayi32Milliseconds since midnight ET at emission time. 0 for watermark-driven boot snapshots before any live tick.
correlationf64Pearson correlation ρ ∈ [-1, +1]. NaN on a degenerate window (fewer than two paired returns or zero variance on either leg).
mean_returnf64Sample mean log return for the target leg over the window.
comparator_mean_returnf64Sample mean log return for the comparator leg over the window.
variancef64Sample variance of the target leg over the window.
comparator_variancef64Sample variance of the comparator leg over the window.
sessions_usedi32Count 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_sessionsi32The 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.

FieldTypeDescription
contractsSecurityFilterContracts 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.
conditionsConditionPolicyTrade-condition admission policy applied to every print.
venuesExchangeFilterExchange / venue admission policy.
daily_closeArc<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_symbolArc<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_sessionsusizeTrailing-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_msi32Minimum 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(())
# }

Proprietary. All rights reserved.