<!-- Generated from TradeReady.io docs. Visit https://tradeready.io/docs for the full experience. -->

---
title: Backtesting Overview
description: Test your trading strategies against real historical market data before risking anything live
---

## What Is Backtesting?

Imagine you have a time machine for trading. Backtesting lets you go back in time and test your strategy against real market data that already happened. Did Bitcoin crash in June? Did Ethereum spike in December? Your AI agent can practice trading through all of it — without risking a single dollar.

Instead of waiting months to see if a strategy works in real life, you get the answer in minutes.

---

## How It Works

Think of it like a flight simulator for trading.

You pick:

- **Which agent** — "Use my momentum bot agent"
- **A date range** — "I want to test from January 1 to December 31, 2025"
- **A starting balance** — "Give me $10,000 in fake money"
- **Which coins to trade** — "Just Bitcoin and Ethereum" (or all 600+ available)
- **A strategy name** — so you can compare different approaches later

Once you start, the system creates a **fake exchange** just for your test. This fake exchange has real historical prices from Binance, tracks your fake money balance, processes your buy and sell orders, charges realistic trading fees (0.1% per trade), and simulates slippage.

Then time starts moving. The virtual clock ticks forward one candle at a time. At each tick, your AI agent sees the current prices and decides: buy, sell, or do nothing. It is exactly like live trading, except the "market" is a recording of what actually happened.

### Why It's Fast

A full year of 1-minute price data is over 500,000 data points. The system loads all of this into memory at the start, so stepping through time is almost instant. A year of simulated trading completes in minutes, not months.

---

## What You Get at the End

When the simulation finishes, you get a full report card.

### The Big Numbers

- **ROI** — "I started with $10,000 and ended with $12,500, so my ROI is +25%"
- **Total Trades** — how many times the agent bought or sold
- **Final Equity** — your ending balance including any open positions

### Risk Metrics

| Metric | What It Means |
|--------|---------------|
| **Sharpe Ratio** | Risk-adjusted return. How smooth was the ride? Above 1.0 is good, above 2.0 is excellent. |
| **Sortino Ratio** | Like Sharpe but only penalizes downside volatility. |
| **Max Drawdown** | The worst losing streak. If your account fell from $12,000 to $9,000, that is a 25% drawdown. Lower is better. |
| **Win Rate** | What percentage of trades made money. 60% means 6 out of 10 trades were profitable. |
| **Profit Factor** | Total money won divided by total money lost. Above 1.0 means you are making more than you are losing. |
| **Avg Win / Avg Loss** | Average profit on winning vs losing trades. |

### Visual Charts

The results endpoint provides time-series data for:

- **Equity Curve** — your balance over time, ideally trending up and to the right
- **Drawdown Chart** — shows the dips and how deep they went
- **Trade Log** — every single buy and sell, with exact prices, fees, and profit/loss

---

## Comparing Strategies

The real power is comparison. Say you have three ideas:

| Strategy | ROI | Sharpe | Max Drawdown | Win Rate |
|----------|-----|--------|--------------|----------|
| Momentum | +18% | 1.4 | -8% | 55% |
| Mean Reversion | +12% | 0.8 | -15% | 62% |
| Breakout | +25% | 1.1 | -20% | 48% |

Breakout made the most money, but had the scariest drawdown. Momentum had the best risk-adjusted return. Mean Reversion won most often but made the least. Now you can make an informed choice.

---

## Common Strategy Types

### Trend Following (Momentum)

**The idea:** Things that are going up tend to keep going up.

The agent watches for coins that have been rising. When the short-term average price crosses above the long-term average, the agent buys. When the trend reverses, it sells. Like surfing — ride the wave and get off before it crashes.

### Mean Reversion

**The idea:** What goes down must come back up.

The agent looks for coins that dropped a lot recently. It buys them cheap, betting they'll bounce back to their normal price. Like shopping at a sale — buy things that are temporarily cheap and wait for prices to normalize.

### Breakout

**The idea:** When price breaks through a ceiling, it often keeps going.

The agent tracks the highest price over the last 24 hours. When price pushes above that ceiling, it buys — expecting the breakout to continue. Always paired with a stop-loss as a safety net.

### Momentum Rotation

**The idea:** Always hold the winners, drop the losers.

Every hour, the agent ranks all coins by performance. It sells anything not in the top 3 and buys whatever is currently leading. Like a fantasy sports team — constantly swap players to have the best lineup.

---

## What Makes It Realistic

The simulation accounts for real-world factors:

- **Real prices** — actual Binance market data, not random numbers
- **Trading fees** — 0.1% per trade, same as Binance
- **Slippage** — when you buy, you do not get the exact price you saw. The bigger your order, the worse the slippage. This is how real markets work.
- **No look-ahead bias** — the system enforces that your agent can only see prices up to the current simulated time. It cannot peek into the future.
- **Risk rules enforced** — if your agent has risk limits configured (max position size, daily loss limit), the backtest sandbox enforces them just as the live exchange would.

> **Info:**
> The critical invariant: `DataReplayer` only loads candles WHERE `bucket <= virtual_clock`. Look-ahead bias is architecturally impossible.

---

## Iteration Is the Key

The key to good backtesting is not getting it right on the first try — it is iterating:

1. **Start simple** — even a basic "buy when RSI drops below 30" is a valid starting point
2. **Run it** — see what ROI and drawdown you get
3. **Tweak one thing** — change one parameter, or add one condition
4. **Run again** with a new version label (`momentum_v1` → `momentum_v2`)
5. **Compare** — the platform shows all versions side by side
6. **Test different time periods** — a strategy that works in January but fails in June is unreliable

---

## The Simple Version

1. You pick a time period and starting balance
2. The system replays real market prices candle by candle
3. Your AI agent trades as if it were live
4. At the end, you get a full performance report
5. Run multiple strategies and compare to find the best one

---

## Next Steps

- [Technical Guide](/docs/backtesting/guide) — the full API lifecycle with code examples
- [Strategy Examples](/docs/backtesting/strategies) — complete working strategies with code
