Appearance
Max Drawdown Stream
Family: Risk
What it computes
Emits MaxDrawdownStreamTick ticks carrying max_drawdown, max_drawdown_pct, peak_price, trough_price, current_drawdown, n_intraday_bars off stock trade tape (5m bars).
Available on the live, historical, and replay drives.
Methodology
Magdon-Ismail / Atiya (2004) rolling peak-to-trough maximum drawdown MDD = max((peak − trough) / peak); the Calmar-ratio denominator (Young 1991).
See the methodology overview for the citation index.
Inputs
Stock trade tape (5m bars).
Key outputs
Max_drawdown, max_drawdown_pct, peak_price, trough_price, current_drawdown, n_intraday_bars. The full field set is in the tick table below.
Output schema (MaxDrawdownStreamTick)
The field / type / description table below is regenerated from the MaxDrawdownStreamTick 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) at emission time. |
ms_of_day | i32 | Milliseconds since midnight ET at emission time. |
max_drawdown | f64 | Rolling-window maximum drawdown MDD = max((peak − trough) / peak) expressed as a positive fraction in [0, 1]. NaN with an empty FIFO. |
max_drawdown_pct | f64 | Rolling-window maximum drawdown expressed in percentage points. NaN with an empty FIFO. |
peak_price | f64 | Rolling-window peak price — the running maximum at the point of the worst trough. NaN with an empty FIFO. |
trough_price | f64 | Rolling-window trough price that anchored the worst drawdown reading. NaN with an empty FIFO. |
current_drawdown | f64 | Standing per-bar drawdown at the most-recent close — (peak_last − close_last) / peak_last. Always ≥ 0. NaN with an empty FIFO. |
n_intraday_bars | i32 | Count of intraday bars currently inside the rolling window. |
Configuration (MaxDrawdownStreamParams)
Regenerated from the MaxDrawdownStreamParams 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. |
bar_interval_ms | i32 | Per-bar cadence in milliseconds. Defaults to [DEFAULT_BAR_INTERVAL_MS] (300_000 ms / 5 min). |
window_bars | i32 | Rolling-window length in bars. Defaults to [DEFAULT_WINDOW_BARS] (78 — one US-equity session at the default 5-minute cadence). |
min_emit_interval_ms | i32 | Minimum 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().max_drawdown_stream(["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()
.maxDrawdownStream(["QQQ"])
.onEvent((tick) => {
console.log(tick);
});Rust
rust
// Cargo.toml:
// kairos = "0.1"
use kairos::{Client, MaxDrawdownStreamRow};
# fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = Client::connect(("me@example.com", "secret"))?;
let sub = client
.live()
.max_drawdown_stream(["QQQ"])
.on_event(|row: &MaxDrawdownStreamRow| println!("mdd={} peak={}", row.max_drawdown, row.peak_price))?;
// ... later, to stop delivery ...
sub.unsubscribe();
# Ok(())
# }