Skip to content

Portfolio VaR

Family: Risk

What it computes

Emits PortfolioVarTick ticks carrying var_95 / 99, es_95 / 99, USD off daily-close cache.

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

RiskMetrics historical-simulation VaR + Acerbi-Tasche ES.

See the methodology overview for the citation index.

Inputs

Daily-close cache.

Key outputs

Var_95 / 99, es_95 / 99, USD. The full field set is in the tick table below.

Output schema (PortfolioVarTick)

The field / type / description table below is regenerated from the PortfolioVarTick 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).
datei32Session date the emission was driven by (YYYYMMDD).
ms_of_dayi32Milliseconds since midnight at emission time.
var_95_pctf64One-day 95% Value-at-Risk as a positive decimal loss. NaN when the cache holds fewer than lookback_sessions + 1 rows for the tracked symbol (degraded — surfaces the cold-start / missing-history data-quality issue rather than silently emitting zero).
var_99_pctf64One-day 99% Value-at-Risk as a positive decimal loss.
es_95_pctf64One-day 95% Expected Shortfall — the mean of the left tail below the 95% quantile, as a positive decimal loss.
es_99_pctf64One-day 99% Expected Shortfall.
var_95_usdf64var_95_pct × position_size_usd.
var_99_usdf64var_99_pct × position_size_usd.
es_95_usdf64es_95_pct × position_size_usd.
es_99_usdf64es_99_pct × position_size_usd.
position_size_usdf64The position_size_usd spec field, echoed on every emission so consumers can audit the dollar conversion factor without an out-of-band lookup.
sessions_usedu32Number of log returns that drove the emission — the actual window length, which falls short of lookback_sessions when the cache holds insufficient history (degraded emission).

Configuration (PortfolioVarParams)

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

FieldTypeDescription
contractsSecurityFilterContracts the subscription tracks. Stocks only — option portfolios need a different revaluation methodology.
conditionsConditionPolicyTrade-condition admission policy applied to admitted trades.
venuesExchangeFilterExchange / venue admission policy.
daily_closeArc<DailyCloseCache>Boot-time hydrated daily-close cache. Must hold at least lookback_sessions + 1 rows per tracked symbol for the lookback_sessions log-return window to populate.
lookback_sessionsusizeTrailing-window length in trading sessions. Defaults to [DEFAULT_LOOKBACK_SESSIONS] (252 = one trading year per the RiskMetrics convention).
position_size_usdf64Position size in dollars used to scale the percent VaR / ES into the dollar-denominated emissions. Defaults to [DEFAULT_POSITION_SIZE_USD] ($100_000).
min_emit_interval_msi32Minimum interval between emissions per symbol, in milliseconds. Defaults to [DEFAULT_MIN_EMIT_INTERVAL_MS] (60_000 ms = 1 minute).

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

Rust

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

use kairos::{Client, PortfolioVarRow};

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

let sub = client
    .live()
    .portfolio_var(["QQQ"])
    .on_event(|row: &PortfolioVarRow| {
        println!("position_size_usd={}", row.position_size_usd);
    })?;

// … later …
sub.unsubscribe();
# Ok(())
# }

Proprietary. All rights reserved.