Appearance
Realized Spread
Family: Microstructure
What it computes
Emits RealizedSpreadTick ticks carrying realized_half_spread, realized_half_spread_bps, n_observations, delay_ms off trade + quote tape.
Available on the live, historical, and replay drives.
Methodology
Huang / Stoll (1996) realized half-spread RS_t = 2·D_t·(P_t − M_{t+τ}) / M_t post-trade decay aggregated over a rolling window; pairs with effective_spread to decompose temporary vs permanent execution cost.
See the methodology overview for the citation index.
Inputs
Trade + quote tape.
Key outputs
Realized_half_spread, realized_half_spread_bps, n_observations, delay_ms. The full field set is in the tick table below.
Output schema (RealizedSpreadTick)
The field / type / description table below is regenerated from the RealizedSpreadTick 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). |
date | i32 | Trading-session date (YYYYMMDD). |
ms_of_day | i32 | Milliseconds since midnight at emission time. |
realized_half_spread | f64 | Huang / Stoll (1996) realized half-spread in dollars — (1 / N) · Σ D_i · (P_i − M_{i+τ}) over the rolling window. NaN when N == 0. |
realized_half_spread_bps | f64 | Huang / Stoll (1996) realized half-spread in basis points — 10_000 · (1 / N) · Σ D_i · (P_i − M_{i+τ}) / M_i over the rolling window. NaN when N == 0. |
n_observations | i32 | Number of sealed prints contributing to the rolling estimate. |
delay_ms | i32 | Post-trade settlement delay in milliseconds — τ in the Huang / Stoll (1996) identity. Surfaced on every tick so the downstream consumer reads the horizon directly. |
Configuration (RealizedSpreadParams)
Regenerated from the RealizedSpreadParams Rust source — see the note above.
| Field | Type | Description |
|---|---|---|
contracts | SecurityFilter | Contracts the subscription tracks. Stock-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. |
window_ms | i32 | Rolling-window length in milliseconds for the realized- spread aggregate. Defaults to [DEFAULT_WINDOW_MS] (60_000 ms). |
delay_ms | i32 | Post-trade settlement delay in milliseconds — τ in the Huang / Stoll (1996) identity. Defaults to [DEFAULT_DELAY_MS] (300_000 ms — five minutes). |
min_emit_interval_ms | i32 | Minimum interval between consecutive emissions per symbol, in milliseconds. Defaults to [DEFAULT_MIN_EMIT_INTERVAL_MS] (1_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().realized_spread(["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()
.realizedSpread(["QQQ"])
.onEvent((tick) => {
console.log(tick);
});Rust
rust
// Cargo.toml:
// kairos = "0.1"
use kairos::{Client, RealizedSpreadRow};
# fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::connect(("me@example.com", "secret"))?;
let sub = client
.live()
.realized_spread(["QQQ"])
.on_event(|row: &RealizedSpreadRow| println!("half_spread={} half_spread_bps={}", row.realized_half_spread, row.realized_half_spread_bps))?;
// ... later ...
sub.unsubscribe();
# Ok(())
# }