Appearance
Beta To SPY
Family: Stat-arb
What it computes
Emits BetaToSpyTick ticks carrying beta, alpha, r_squared 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) OLS regression vs SPY.
See the methodology overview for the citation index.
Inputs
Daily-close cache (2 symbols).
Key outputs
Beta, alpha, r_squared. The full field set is in the tick table below.
Output schema (BetaToSpyTick)
The field / type / description table below is regenerated from the BetaToSpyTick 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). |
benchmark_symbol | Arc<str> | Benchmark symbol the regression fit against (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. |
beta | f64 | OLS slope β = cov(r_symbol, r_benchmark) / var(r_benchmark). NaN on a degenerate-window guard (insufficient paired observations or zero benchmark variance). |
alpha | f64 | OLS intercept α = mean(r_symbol) − β · mean(r_benchmark). The per-session excess return the symbol earns after accounting for the benchmark factor — the canonical Sharpe (1964) alpha. |
r_squared | f64 | Coefficient of determination R² = 1 − var(residuals) / var(r_symbol). The fraction of the symbol's return variance the benchmark factor explains; high R² indicates the symbol's risk is dominated by the broad market factor. |
sessions_used | i32 | Count of paired log-return observations the regression actually consumed — the minimum of the symbol and benchmark trailing window lengths. 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 (BetaToSpyParams)
Regenerated from the BetaToSpyParams Rust source — see the note above.
| Field | Type | Description |
|---|---|---|
contracts | SecurityFilter | Contracts the subscription tracks. 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 benchmark_symbol for the per-symbol regression window to populate. |
benchmark_symbol | Arc<str> | Benchmark symbol the regression fits against. Defaults to [DEFAULT_BENCHMARK_SYMBOL] ("SPY"). Subscribers can swap to an alternative reference ("IVV", "VTI", sector ETFs) per-subscription. |
lookback_sessions | usize | Trailing-window length in trading sessions. Defaults to [DEFAULT_LOOKBACK_SESSIONS] (30). Production fits accept up to a full trading year (252 sessions) for the Bloomberg-style long-horizon weekly-return convention. |
min_emit_interval_ms | i32 | Minimum interval between emissions per symbol, in milliseconds. Defaults to [DEFAULT_MIN_EMIT_INTERVAL_MS] (60_000 ms / 1 min). Set to 0 to publish on every admitted print. |
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().beta_to_spy(["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()
.betaToSpy(["QQQ"])
.onEvent((tick) => {
console.log(tick);
});Rust
rust
// Cargo.toml:
// kairos = "0.1"
use kairos::{Client, BetaToSpyRow};
# fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::connect(("me@example.com", "secret"))?;
let sub = client
.live()
.beta_to_spy(["QQQ"])
.on_event(|row: &BetaToSpyRow| {
println!("beta={} alpha={}", row.beta, row.alpha)
})?;
// ... later ...
sub.unsubscribe();
# Ok(())
# }