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
[]
= "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 ;
use dec;
let returns = vec!;
let sharpe = sharpe_ratio; // rf=2%, daily
let dd = max_drawdown;
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.