Risk & Portfolio Ratios¶
Risk-adjusted performance metrics for single securities and portfolios.
Note
All functions accept a list of periodic returns (e.g. monthly or daily). Pass None or an empty list and the function returns None.
Return Metrics¶
sharpe_ratio¶
Formula: (Avg Return − Rf) / Std Dev. Returns None when standard deviation is zero.
sortino_ratio¶
Like Sharpe but uses downside deviation only. Better for asymmetric return distributions.
calmar_ratio¶
Formula: Annualised Return / Max Drawdown. Higher = better risk/reward for drawdown-averse investors.
omega_ratio¶
Probability-weighted ratio of gains to losses above/below a threshold.
Risk Metrics¶
beta¶
Market sensitivity. beta = 1 moves with market; < 1 less volatile; > 1 more volatile.
alpha¶
Jensen's alpha — excess return above what CAPM predicts.
maximum_drawdown¶
Returns a positive decimal (e.g. 0.34 for a 34% peak-to-trough decline). Pass a list of prices, not returns.
historical_var¶
Value at Risk at given confidence level. Returns a positive loss value (e.g. 0.03 means 3% loss at the threshold).
conditional_var — CVaR / Expected Shortfall¶
Expected loss beyond VaR threshold. Always ≥ historical_var.
ulcer_index¶
Measures drawdown depth and duration. Lower = smoother equity curve.
TypeScript¶
import { sharpeRatio, maximumDrawdown, historicalVaR } from 'fin-ratios'
// Monthly returns
const returns = [0.02, -0.01, 0.03, -0.005, 0.015, ...]
sharpeRatio({ returns, riskFreeRate: 0.0 }) // Sharpe ratio
maximumDrawdown({ prices: [100, 110, 95, 105] }) // 0.136 (positive)
historicalVaR({ returns, confidence: 0.95 }) // positive loss value