Learn
Backtesting, strategies & metrics — from zero
Everything on this page is public, and every worked example is computed live by the same engine that powers the Backtest Lab.
What is backtesting?
Backtesting is a dress rehearsal for a trading strategy: you replay history and let your rules decide — with only the data available at each moment — what to buy, when to rebalance, and how to weight each position. The simulator walks forward through the price record, applies your ranking rule, allocates weights, and tracks the resulting portfolio value day by day.
The output is an equity curve plus the metrics to judge it: annualized return tells you the reward, volatility and drawdown tell you the pain, and risk-adjusted ratios like Sharpe and Sortino tell you whether the reward justified the pain. A backtest can never prove a strategy will work — but it can quickly prove that one won't.
The three strategy families
Momentum
Buys recent winners, betting that assets with the strongest price momentum keep outperforming. Thrives in trending markets; suffers when trends snap back.
Momentum(i) = P(today) − P(today − t) Mean reversion
Buys oversold assets trading below their moving average, betting they snap back toward the mean. Shines in range-bound markets; risks catching falling knives in strong trends.
Deviation(i) = P(today) − SMA(t) Smart beta
Ranks assets by risk-adjusted return — mean return per unit of volatility, a per-asset Sharpe ratio. Favors consistent performers over volatile high-flyers.
SmartBeta(i) = mean(Rᵢ) / std(Rᵢ) Want the full breakdown — parameters, pros/cons, and a live ranking demo of each? Explore the strategy catalog →
The metrics, explained with live numbers
Each card shows the formula in plain text and a worked example computed in your browser by the engine itself.
The demo series every example below uses
Thirteen month-end portfolio values (100, 102, 99.5, 103.1, 105.4, 101.9, 98.2, 102.6, 106.8, 104.1, 108.9, 106.2, 111.4). Every number in the metric cards is computed in your browser, right now, by the same engine functions (@/lib/engine/metrics) that score real backtests — nothing is hardcoded.
Rₜ = (Pₜ − Pₜ₋₁) / Pₜ₋₁ R_ann = (∏(1 + Rₜ))^(N/n) − 1Each period return Rₜ is the percentage change in value. To compare series of different lengths, compound all n returns and rescale to N periods per year (N = 12 for monthly data).
Worked example — First month: (102 − 100) / 100 = 2.00%. Compounding all 12 monthly returns → annualized return 11.40%.
Rule of thumb: Always compare annualized figures — a 10% total return means very different things over 6 months vs. 6 years.
σ_ann = σ(R) · √NThe standard deviation of period returns, scaled by the square root of periods per year. It measures how bumpy the ride is — not whether it goes up or down.
Worked example — Demo series: monthly σ scaled by √12 → annualized volatility 12.17%.
Rule of thumb: Broad equity indexes historically sit around 15–20% annualized. Double the volatility ≈ double the size of a typical swing.
Sharpe = R_excess,ann / σ_ann where R_excess = R − R_fExcess return (above the risk-free rate R_f) per unit of total volatility. The single most-quoted risk-adjusted performance number.
Worked example — Demo series with R_f = 3%: annualized excess return ÷ 12.17% volatility → Sharpe 0.67.
Rule of thumb: Above 1.0 is generally considered good, above 2.0 very good, above 3.0 excellent — and worth double-checking for overfitting.
Sortino = R_excess,ann / σ_down,ann σ_down = σ(R | R < 0) · √NLike Sharpe, but the denominator only counts DOWNSIDE deviation — volatility from negative periods. Upside surprises are not penalized.
Worked example — Demo series: 5 of 12 months were negative → Sortino 4.26 (vs. Sharpe 0.67).
Rule of thumb: Sortino > Sharpe on the same series means most of the volatility came from up moves — usually a good sign.
DDₜ = (Pₜ − peakₜ) / peakₜ MaxDD = min(DDₜ)The worst peak-to-trough decline over the whole period. The single best gut-check: could you have held through that loss without abandoning the strategy?
Worked example — Demo series peaks at 111.4 and its worst trough after a peak gives MaxDD -6.83%.
Rule of thumb: Recovering from a −50% drawdown requires a +100% gain. Deep drawdowns are why high-return backtests still fail live.
VaR₅ = −percentile(R, 5) CVaR₅ = −mean(R | R ≤ −VaR₅)Historic Value at Risk: the loss threshold your worst 5% of periods exceed. CVaR (expected shortfall) answers the follow-up — when you DO land in that worst 5%, how bad is it on average?
Worked example — Demo series: monthly VaR₅ = 3.46% — in 95% of months you lose less than that. CVaR₅ = 3.63%, the average loss inside the worst tail.
Rule of thumb: CVaR is always ≥ VaR. A big gap between them warns of rare-but-severe tail losses that VaR alone hides.
Overfitting — the backtester's trap
Tune a strategy's parameters long enough against one stretch of history and you will find a combination that looks spectacular — because it memorized that history's accidents, not because it found a durable edge. Warning signs: performance that collapses when you nudge a parameter, a Sharpe ratio that looks too good to be true, and results driven by a handful of lucky trades.
The antidote is walk-forward analysis: split history into rolling windows, pick parameters on the in-sample segment, then score them only on the unseen out-of-sample segment that follows — repeated across the whole record. Consistent out-of-sample results are the closest a backtest gets to honesty. The Backtest Lab runs walk-forward splits and parameter sweeps for exactly this reason. Watch for look-ahead bias (using information not yet available at decision time) and survivorship bias (testing only on assets that still exist today) too.
Frequently asked questions
What is TradePilot and how does it work?
TradePilot is an algorithmic trading workbench that unifies backtesting and strategy research. You define a strategy (asset selection + weight optimization), test it against historical data in the browser-based Backtest Lab, and iterate — every metric is computed by the same engine, whether in a quick demo or a full walk-forward run.
What does the Sharpe ratio tell me?
The Sharpe ratio measures risk-adjusted return: how much excess return you earn per unit of volatility. Above 1.0 is generally considered good, above 2.0 very good, and above 3.0 excellent. It lets you compare strategies with different risk profiles on one scale.
Can I lose more money than I invest?
With standard equity trading (no leverage or margin), your maximum loss is limited to your invested capital. Leveraged positions or short selling can amplify losses beyond the initial investment. TradePilot defaults to long-only, unleveraged strategies.
How often should a strategy rebalance?
Rebalancing frequency is configurable. Common choices are weekly, bi-weekly, or monthly. More frequent rebalancing captures signals faster but incurs higher transaction costs — sweep the interval in the Backtest Lab to see the trade-off on your own strategy.
Why do backtest results differ from live performance?
Several factors cause divergence: slippage (the gap between expected and actual execution price), transaction costs, market impact of your orders, look-ahead bias in data, and changing market regimes. Treat backtest results as optimistic estimates and account for these factors.
What is walk-forward analysis?
Instead of judging a strategy on one continuous window, walk-forward analysis splits history into rolling segments, repeatedly "training" parameters on one segment and evaluating on the next unseen one. A strategy that only shines on the full window — and falls apart out-of-sample — was probably overfit.
Ready to try it? Play with the calculators or open the Backtest Lab.