DocsBacktest Engineexecution

Performance Metrics

After a backtest completes, the engine computes a set of statistics from the closed trades. These metrics appear in the results panel and are used as optimization targets.

Core Metrics

MetricFormulaDescription
tradeCountCount of closed tradesTotal trades executed
winsTrades with profit > 0Number of winning trades
lossesTrades with profit <= 0Number of losing trades
winRatewins / tradeCountWin percentage (0-1)
totalProfitSum of all trade P&LNet profit after fees
totalFeesSum of all fees paidTotal commission cost
totalReturnFinal equity - initialAbsolute dollar return
totalReturnPercenttotalReturn / initial * 100Percentage return
avgTradeLengthAvg bars held per tradeAverage holding period

Risk Metrics

Max Drawdown

The largest peak-to-trough decline in equity during the backtest:

maxDrawdown = max(peak - trough) for all equity peaks
maxDrawdownPercent = maxDrawdown / peak * 100

A lower drawdown indicates better capital preservation. Strategies with 50%+ drawdowns are risky — a 50% loss requires a 100% gain to recover.

Sharpe Ratio

Risk-adjusted return, measuring return per unit of volatility:

sharpeRatio = mean(returns) / stdDev(returns) * sqrt(annualizationFactor)
SharpeInterpretation
< 0Losing money
0 - 1Below average
1 - 2Good
2 - 3Very good
> 3Excellent (verify, may be overfit)

Bidirectional Metrics

When using bidirectional trading mode, additional metrics break down performance by direction:

MetricDescription
longTradesNumber of long trades
shortTradesNumber of short trades
longWinRateWin rate for long trades only
shortWinRateWin rate for short trades only
longProfitTotal profit from long trades
shortProfitTotal profit from short trades

Optimization Targets

These metrics can be used as optimization objectives:

TargetDirectionBest For
sharpeRatioMaximizeRisk-adjusted performance
totalReturnMaximizeRaw profitability
profitFactorMaximizeGross profit / gross loss
maxDrawdownMinimizeCapital preservation
winRateMaximizeConsistency

Interpreting Results

High win rate, low profit: Many small wins and a few large losses. Add stop losses.

Low win rate, high profit: Few big winners carry the strategy. Common with trend-following — accept many small losses for occasional large moves.

High Sharpe, low trade count: May be overfit to a few lucky trades. Verify with more data or walk-forward analysis.

Negative totalReturn with positive winRate: Losing trades are larger than winners. Adjust risk-reward ratio.

Related

metricsperformancesharpedrawdownwin rateprofitstatistics