Skip to content

Rolling Beta

Family: Stat-arb

What it computes

Emits RollingBetaTick ticks carrying beta, alpha, r_squared, 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

Sharpe (1964) rolling-OLS market-model beta vs subscriber-supplied benchmark — Fama-MacBeth (1973) rolling-window convention.

See the methodology overview for the citation index.

Inputs

Daily-close cache (2 symbols).

Key outputs

Beta, alpha, r_squared, sessions_used. The full field set is in the tick table below.

Output schema (RollingBetaTick)

The field / type / description table below is regenerated from the RollingBetaTick 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).
benchmark_symbolArc<str>Benchmark 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.
betaf64OLS slope β = cov(r_target, r_benchmark) / var(r_benchmark) — the dimensional hedge-ratio scalar a cross-leg pair-trade short-sizes against. NaN on a degenerate window.
alphaf64OLS intercept α = mean(r_target) − β · mean(r_benchmark). The per-session excess return the target earns after accounting for the benchmark factor — the Sharpe (1964) alpha.
r_squaredf64Coefficient of determination R² = 1 − var(residuals) / var(r_target). The fraction of the target's return variance the benchmark factor explains.
sessions_usedi32Count of paired log-return observations the regression 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 (RollingBetaParams)

Regenerated from the RollingBetaParams Rust source — see the note above.

FieldTypeDescription
contractsSecurityFilterContracts the subscription tracks — the per-contract [SecurityFilter] resolves the target leg. Stocks only.
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 target and the benchmark_symbol for the per-pair regression window to populate.
benchmark_symbolArc<str>Benchmark symbol the regression fits against — any peer issue, sector ETF, factor portfolio, or custom hedge basket the subscriber wires into the cache. Distinct from beta_to_spy which pins the benchmark to SPY.
lookback_sessionsusizeTrailing-window length in trading sessions. Defaults to [DEFAULT_LOOKBACK_SESSIONS] (60).
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_beta(["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()
  .rollingBeta(["QQQ"])
  .onEvent((tick) => {
    console.log(tick);
  });

Rust

rust
// Cargo.toml:
//   kairos = "0.1"

use kairos::{Client, RollingBetaRow};

# fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::connect(("me@example.com", "secret"))?;

let sub = client
    .live()
    .rolling_beta(["QQQ"])
    .on_event(|row: &RollingBetaRow| println!("beta={} alpha={}", row.beta, row.alpha))?;
// ... later ...
sub.unsubscribe();
# Ok(())
# }

Proprietary. All rights reserved.