Performance metrics (fynance.metrics)

Risk-adjusted ratios, return and drawdown metrics to evaluate a strategy out-of-sample. A metric evaluates a series — distinct from fynance.features, which builds inputs.

Ratios & returns

sharpe(X[, rf, period, log, axis, dtype, ddof])

Compute the Sharpe ratio for each X' series.

sortino(X[, rf, period, log, axis, dtype, ddof])

Compute the Sortino ratio for each X' series.

calmar(X[, period, axis, dtype, ddof])

Compute the Calmar Ratio for each X' series.

annual_return(X[, period, axis, dtype, ddof])

Compute compounded annual returns of each X' series.

annual_volatility(X[, period, log, axis, ...])

Compute the annualized volatility of each X' series.

diversified_ratio(X[, W, std_method, axis])

Compute diversification ratio of a portfolio.

perf_index(X[, base, axis, dtype])

Compute performance of prices or index values along time axis.

perf_returns(R[, kind, base, axis, dtype])

Compute performance of returns along time axis.

perf_strat(X[, S, base, axis, dtype, reinvest])

Compute the performance of strategies for each X' series.

returns_strat(X[, S, kind, base, axis, dtype])

Compute the returns of strategies for each X' series.

Drawdown

drawdown(X[, raw, axis, dtype])

Measures the drawdown of each X' series.

mdd(X[, raw, axis, dtype])

Compute the maximum drawdown for each X' series.

Tail risk

Value-at-Risk, Conditional Value-at-Risk (Expected Shortfall) and Conditional Drawdown-at-Risk. Like the ratios above, var/cvar/cdar take a price/equity curve (returns are derived internally); tail_dependence is the exception — it takes a (T, N) returns panel directly, mirroring information_coefficient’s pair convention.

var(X[, alpha, method])

Value-at-Risk of a price/equity curve's per-period returns.

cvar(X[, alpha, method])

Conditional Value-at-Risk (Expected Shortfall) of a price/equity curve.

cdar(X[, alpha])

Conditional Drawdown-at-Risk of a price/equity curve.

tail_dependence(X[, q])

Pairwise lower-tail dependence of a (T, N) returns panel.

Rolling versions

roll_sharpe(X[, rf, period, w, log, axis, ...])

Compute rolling sharpe ratio of each X' series.

roll_calmar(X[, period, w, axis, dtype, ddof])

Compute the rolling Calmar ratio of each X' series.

roll_annual_return(X[, period, w, axis, ...])

Compute rolling compounded annual returns of each X' series.

roll_annual_volatility(X[, period, log, w, ...])

Compute the annualized volatility of each X' series.

roll_drawdown(X[, w, raw, axis, dtype])

Measures the rolling drawdown of each X' series.

roll_mdd(X[, w, raw, axis, dtype])

Compute the rolling maximum drawdown for each X' series.

roll_var(X[, alpha, w, method])

Rolling Value-at-Risk of a price/equity curve over a trailing window.

roll_cvar(X[, alpha, w, method])

Rolling Conditional Value-at-Risk of a price/equity curve.

Benchmark-relative

Score a strategy against a benchmark rather than in isolation: beta and Jensen’s alpha decompose the strategy’s return into a benchmark-driven part and a residual, while tracking error, the information ratio and the up/down capture ratios describe the active (strategy-minus-benchmark) return. Every function takes two aligned price/level curves (X, B) (see fynance.metrics.benchmark).

beta(X, B[, period])

OLS slope of the strategy's returns on the benchmark's returns.

alpha(X, B[, period, rf])

Annualized Jensen's alpha of the strategy against the benchmark.

tracking_error(X, B[, period])

Annualized standard deviation of the active (strategy - benchmark) return.

information_ratio(X, B[, period])

Annualized mean active return over the tracking error.

capture_ratio(X, B[, side, period])

Up- or down-market capture ratio of the strategy against the benchmark.

benchmark_summary(X, B[, period, rf])

Standard benchmark-relative performance summary.

roll_beta_benchmark(X, B[, w])

Trailing rolling beta of the strategy against the benchmark.

Factor analysis

Alphalens-style evaluation of a cross-sectional factor on a data-agnostic (T, N) panel. The alignment convention matches information_coefficientfactor[t] is paired with the return realized after the factor is known.

information_coefficient(pred, real, *[, ...])

Information Coefficient between a prediction and a realized outcome.

quantile_returns(factor, fwd[, n_quantiles])

Equal-count quantile-portfolio returns of a factor.

roll_information_coefficient(pred, real[, ...])

Trailing-window Information Coefficient.

ic_decay(factor, prices[, horizons, method])

Information Coefficient decay across forward horizons.

ic_summary(pred, real[, method])

Summary statistics of the per-bar cross-sectional Information Coefficient.

factor_rank_autocorr(factor[, lag])

Cross-sectional rank autocorrelation of a factor (turnover proxy).

QuantileResult(quantile_returns, spread, ...)

Per-bar quantile-portfolio returns of a factor.

Trading exposure & turnover

Position-level analytics — how a book trades (churn) and sits (leverage, long/short bias) — taking a weight/position series rather than an equity curve, so (like the factor helpers above) these are intentionally kept out of the METRICS registry.

turnover_series(W)

One-way turnover per bar, \(\sum_i |w_{t,i} - w_{t-1,i}|\).

annual_turnover(W[, period])

Annualized one-way turnover, mean(turnover_series(W)) * period.

gross_exposure(W)

Gross exposure per bar, \(\sum_i |w_{t,i}|\) (total book leverage).

net_exposure(W)

Net exposure per bar, \(\sum_i w_{t,i}\) (long/short bias).

exposure_summary(W[, period])

One-shot summary of a book's turnover and exposure.

Trade analytics

Round-trip trade extraction from a position book – distinct from the churn/turnover metrics above (sign_changes, trades_per_year): these describe individual trades (entry/exit, side, realized return) rather than how often the position flips. See also trades and trade_summary.

extract_trades(positions, returns)

Extract round-trip trades from a position series.

trade_summary(trades)

Summary statistics of a set of round-trip trades.

Aggregated report

summary(prices[, period, rf])

Standard performance summary of an equity/price curve.

summary is driven by the METRICS registry — a name → callable mapping (annual_return, annual_volatility, sharpe, sortino, calmar, max_drawdown, var, cvar, cdar) you can read or extend.

METRICS