Skip to content

Sortino Ratio

Family: Risk

What it computes

Emits SortinoRatioTick ticks carrying mean_return, downside_deviation, sortino_ratio, annualized_sortino, n_intraday_bars off stock trade tape (5m bars).

Available on the live, historical, and replay drives.

Methodology

Sortino / Price (1994) downside-deviation risk-adjusted return (R̄ − MAR) / sqrt(mean(min(r − MAR, 0)²)); per-bar plus sqrt(252 × bars_per_session)-annualised reading.

See the methodology overview for the citation index.

Inputs

Stock trade tape (5m bars).

Key outputs

Mean_return, downside_deviation, sortino_ratio, annualized_sortino, n_intraday_bars. The full field set is in the tick table below.

Output schema (SortinoRatioTick)

The field / type / description table below is regenerated from the SortinoRatioTick 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.
mean_returnf64Rolling-window mean per-bar log return .
downside_deviationf64Downside-deviation root-mean-square DD = sqrt(mean(min(r − MAR, 0)²)) over the rolling window. Strictly positive on every emitted row — the ratio is undefined when downside risk is zero (Sortino & van der Meer 1991), and undefined states suppress the emission.
sortino_ratiof64Per-bar Sortino ratio (R̄ − MAR) / DD. Always finite: rows publish only when the downside deviation is strictly positive.
annualized_sortinof64Annualised Sortino ratio under the sqrt(252 × bars_per_session) convention.
n_intraday_barsi32Count of intraday bars currently inside the rolling window.

Configuration (SortinoRatioParams)

Regenerated from the SortinoRatioParams 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 — one US-equity session at the default 5-minute cadence).
marf64Minimum-acceptable-return threshold (MAR). Per-bar log return units. Defaults to [DEFAULT_MAR] (0.0).
bars_per_sessioni32Bars-per-session count used in the annualisation factor. Defaults to [DEFAULT_BARS_PER_SESSION] (78).
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().sortino_ratio(["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()
  .sortinoRatio(["QQQ"])
  .onEvent((tick) => {
    console.log(tick);
  });

Rust

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

use kairos::{Client, SortinoRatioRow};

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

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

Proprietary. All rights reserved.