Quant BuffetRelax, Not Over Thinking

Quant Buffet API

Metrics API

compute_metrics fields and benchmark-relative stats.

`backtest.metrics.compute_metrics` turns an equity curve into the statistics shown in the lab UI (CAGR, Sharpe, drawdown, etc.).

Usage

metrics = compute_metrics(
    result.equity,
    benchmark=spy_buy_and_hold,  # optional pd.Series, same index as equity
    risk_free=0.0,
    trades_count=len(result.trades),
)
# keys: start, end, years, cagr, volatility, sharpe, sortino,
#       max_drawdown, calmar, daily_win_rate, trades, alpha, beta, ...

Core output fields

KeyDescription
start, endFirst and last equity dates (strings).
yearsCalendar years spanned.
start_equity, end_equityDollar values at start/end.
total_returnEnd/start − 1 (not annualised).
cagrCompound annual growth rate.
volatilityAnnualised standard deviation of daily returns.
sharpeExcess return / volatility (annualised, risk_free subtracted).
sortinoReturn / downside deviation.
max_drawdownWorst peak-to-trough (negative fraction).
calmarCAGR / |max_drawdown|.
daily_win_rateFraction of positive return days.
tradesTrade count passed through from the engine.

Benchmark fields (when benchmark provided)

  • benchmark_total_return, benchmark_cagr
  • alpha — annualised Jensen's alpha vs benchmark daily returns
  • beta — covariance / variance vs benchmark