Metrics

Sharpe and Sortino Ratios

The Sharpe ratio measures average return per unit of total volatility. The Sortino ratio follows the same logic, but only uses downside volatility. Here, both are used to rank backtests from the actual portfolio equity path.

The engine computes these ratios from the portfolio equity curve. It starts from the initial capital, then records equity at each close of the backtest’s main timeframe. Returns are computed from one close to the next on that series. Sharpe uses the full volatility of those returns. Sortino only uses downside volatility.

The ratios are then annualized. You can access them through the sharpe_ratio and sortino_ratio variables in objectives. These variables make it easier to compare backtests run on different timeframes.

Sharpe Specification

The Sharpe ratio uses a standard definition with the risk-free rate fixed at 0, applied to the close-to-close return series of portfolio equity sampled on the backtest’s native timeframe.

  • Source series: initial capital, then portfolio equity at each close of the main timeframe
  • Elementary return: ri=EiEi-1-1
  • Risk-free rate: 0
  • Mean return: μ=riN
  • Standard deviation: σ=(ri-μ)2N-1
  • Annualization: A=Year_msΔ, using a 24/7 crypto year of 365 days
Sortino Specification

The Sortino ratio uses a standard definition with a downside target fixed at 0, applied to the same close-to-close return series of portfolio equity, again on the backtest’s native timeframe.

  • Source series: initial capital, then portfolio equity at each close of the main timeframe
  • Elementary return: ri=EiEi-1-1
  • Downside target: 0
  • Downside component: di=min(0,ri)
  • Downside deviation: σdown=di2N
  • Annualization: A=Year_msΔ, using a 24/7 crypto year of 365 days

For a 4W timeframe, the nominal duration used is 28 fixed days, not a calendar month.

When the calculation is undefined, the returned value is NaN, notably when there are fewer than two valid returns, when previous equity is less than or equal to 0, when an observation is not finite, or when the relevant volatility is zero.

Calmar Ratio

The Calmar ratio measures annualized return per unit of maximum drawdown. It shows whether portfolio performance was achieved without going through overly deep declines.

In this context, Calmar is used as a ranking metric for optimization. It compares compounded annual growth to the maximum drawdown observed over the effective backtest period.

Calmar Specification
  • Formula: Calmar=CAGRMDD
  • CAGR: CAGR=(Final capitalInitial capital)Year_msΔ-1, using a 24/7 crypto year of 365 days and the effective backtest duration

This design keeps Calmar aligned with the finalized backtest window used by the engine and avoids rebuilding a second drawdown series from stored equity samples.

When the calculation is undefined, the returned value is NaN. This happens notably when initial capital is less than or equal to 0, final capital is less than or equal to 0, elapsed duration is less than or equal to 0, maximum drawdown percent is less than or equal to 0, or any intermediate value is not finite.