quant-metrics 0.7.0

Pure performance statistics library for trading — Sharpe, Sortino, drawdown, VaR, portfolio composition
Documentation

quant-metrics

Pure-math portfolio statistics for Rust. Decimal-backed, zero I/O, zero async, WASM-compatible.

Conventions match Bloomberg / MetaTrader / TradeStation where they exist (e.g. Sharpe uses linear risk-free approximation per Bloomberg, Sortino uses total-N denominator per Sortino & Price 1994, win rate excludes zero-PnL from wins).

Install

[dependencies]
quant-metrics = "0.4"

Statistics

Category Functions
Returns total_return, annualized_return, cagr
Risk-adjusted sharpe_ratio, sortino_ratio, calmar_ratio, information_ratio
Drawdown max_drawdown, drawdown_series, max_drawdown_duration, recovery_time
Risk value_at_risk (VaR), conditional_var (CVaR)
Trade stats win_rate, profit_factor, avg_win, avg_loss, expectancy
Composition compose, compose_mixed, allocation methods (equal-weight, inverse-vol, HRP)
Cointegration pearson_correlation, OLS hedge ratio, ADF test, Ornstein-Uhlenbeck half-life
Rolling RollingWindow for returns, vol, sharpe, max-drawdown

Example

use quant_metrics::{sharpe_ratio, max_drawdown};
use rust_decimal_macros::dec;

let returns = vec![dec!(0.01), dec!(-0.02), dec!(0.03), dec!(0.005)];
let sharpe = sharpe_ratio(&returns, dec!(0.02), 252);  // rf=2%, daily
let dd = max_drawdown(&returns);

Audit

See AUDIT-VERDICT.md at the workspace root for formula correctness, numerical stability, and convention notes (reviewed by Claude Opus agent personas — not a human-conducted audit).

License

MIT — see LICENSE-MIT.