Skip to content

VaR Historical

Family: Risk

What it computes

Emits VarHistoricalTick ticks carrying var_95, var_99, n_intraday_bars off stock trade tape (5m bars).

Available on the live, historical, and replay drives.

Methodology

Exact Hyndman-Fan Type 7 lower-tail order statistic over the rolling per-bar return window; the unbounded session-anchored configuration (window_bars = 0) retains the Jain / Chlamtac (1985) P² streaming-quantile recursion.

See the methodology overview for the citation index.

Inputs

Stock trade tape (5m bars).

Key outputs

Var_95, var_99, n_intraday_bars. The full field set is in the tick table below.

Output schema (VarHistoricalTick)

The field / type / description table below is regenerated from the VarHistoricalTick 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>Underlying symbol (interned).
datei32Trading-session date (YYYYMMDD) at emission time.
ms_of_dayi32Milliseconds since midnight ET at emission time.
var_95f64Historical Value-at-Risk at the 95% confidence level — the negated empirical 5th-percentile of the windowed per-bar log returns (exact order statistic on a bounded window; P² streaming estimate on the unbounded window). NaN before five bars have sealed.
var_99f64Historical Value-at-Risk at the 99% confidence level — the negated empirical 1st-percentile of the windowed per-bar log returns (same estimator split as var_95). NaN before five bars have sealed.
n_intraday_barsi32Count of observations behind the published quantile — bars currently inside the rolling window (bounded mode) or total sealed bars this session (unbounded mode).

Configuration (VarHistoricalParams)

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

FieldTypeDescription
contractsSecurityFilterContracts the subscription tracks. 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.
bar_interval_msi32Per-bar cadence in milliseconds. Defaults to [DEFAULT_BAR_INTERVAL_MS] (300_000 ms / 5 min).
window_barsi32Rolling-window length in bars. Defaults to [DEFAULT_WINDOW_BARS] (78). Positive values bound the FIFO and select the exact order-statistic quantile; 0 selects the unbounded session-anchored window served by the P² streaming recursion; values 1..=4 clamp to 5.
min_emit_interval_msi32Minimum interval between consecutive emissions per symbol, in milliseconds. Defaults to [DEFAULT_MIN_EMIT_INTERVAL_MS] (60_000 ms). Set to 0 to publish on every sealed bar.

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().var_historical(["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()
  .varHistorical(["QQQ"])
  .onEvent((tick) => {
    console.log(tick);
  });

Rust

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

use kairos::{Client, VarHistoricalRow};

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

let sub = client
    .live()
    .var_historical(["QQQ"])
    .on_event(|row: &VarHistoricalRow| println!("var_95={} var_99={}", row.var_95, row.var_99))?;
// ... later ...
sub.unsubscribe();
# Ok(())
# }

Proprietary. All rights reserved.