# Backtesting

## What is Backtesting?

**Backtesting simulates how your strategy would have performed using past market data.**

### How It Works

1. Choose a strategy and time period
2. System replays historical price data
3. Strategy generates buy/sell signals
4. Simulated trades execute
5. Performance calculated

### Why Backtest?

**Validate Logic** - Does the strategy actually work? Are the rules sound? **Set Expectations** - Realistic return expectations, typical drawdowns, win rate **Optimize Parameters** - Find best settings, compare variations, refine approach **Build Confidence** - See strategy in action, understand behavior, trust before going live

## Running a Backtest

<figure><img src="/files/OQQn3PEpaHTOC14KsRw5" alt=""><figcaption></figcaption></figure>

### 1. Access Strategy Lab

Navigate to: **Strategy Lab → Your Bot → Backtest**

### 2. Configure Parameters

**Time Period:** Recent data (3 months), Longer validation (6-12 months), Multiple conditions (1-2 years) **Starting Capital:** Use your planned trading capital (e.g., $10,000) **Trading Pair:** Must match your bot's target (e.g., BTC-USD) **Fees:** Include realistic trading fees (default: 0.05%)

### 3. Run the Test

Click **"Start Backtest"** - Processing time: 30-90 seconds

**What happens:** Loads historical data, runs strategy logic, simulates order fills, calculates P\&L and metrics

### 4. Review Results

## Understanding Results

### Key Metrics

**Total Return** - Overall profit/loss percentage. Good: 10-20% over 6 months, Excellent: 20%+, Warning: 50%+ might be over-optimized

**Win Rate** - Percentage of winning trades. Good: 50%+, Note: High win rate doesn't guarantee profitability

**Profit Factor** - Gross profits ÷ Gross losses. Good: Above 1.5, Excellent: Above 2.0, Warning: Below 1.3

**Max Drawdown** - Worst peak-to-valley decline. Acceptable: Under 20%, Good: Under 15%, Warning: Over 25%

**Total Trades** - Number of trades executed. Too few: <20, Good: 30-100, Too many: >200 (overtrading)

### Performance Chart

**Equity Curve** - Shows capital growth over time. Look for: Steady upward trend, recovers from drawdowns, no single trade creates all profit

**Red flags:** Flat for long periods, large drawdowns, all profit from 1-2 trades

## Interpreting Results

### Good Backtest Signs

Positive total return (10%+), profit factor above 1.5, max drawdown under 20%, consistent performance over time, multiple winning periods, reasonable trade frequency

### Warning Signs

**Over-Optimization:** Perfect 90%+ win rate, huge returns (100%+), almost no drawdown, won't work live **Curve Fitting:** All profit from one period, different results in different periods, too good to be true **Insufficient Data:** Only 5-10 trades, too short time period, need more testing

### What If Results Are Bad?

**Negative returns:** Try different parameters, test different strategy type, current market might not suit strategy

**Don't abandon immediately:**

* Some strategies work only in certain conditions
* Test on different time periods
* Understand why it lost

## Backtest Best Practices

### Time Period Selection

**Include Multiple Conditions:** Bull markets, bear markets, sideways markets, high and low volatility

### Walk-Forward Testing

**Better validation method:** Backtest on Period 1, optimize parameters, test on Period 2. If still profitable → good sign, if not → was over-fit

### Out-of-Sample Testing

**Reserve data for validation:** Backtest on 70% of your data for optimization, then test on the remaining 30% for validation. If validation fails, your strategy is over-optimized.

### Realistic Settings

**Include All Costs:** Factor in trading fees (0.05% typical), slippage (0.1-0.2%), and funding rates for perpetuals to get accurate results.

**Use Realistic Fills:** Market orders should assume some slippage, while limit orders should use conservative fill assumptions based on market conditions.

## Common Backtest Mistakes

**Testing Only Bull Markets:** Only backtesting during rising prices gives misleading results. Test across different market conditions including bear markets, sideways markets, and high volatility periods.

**Over-Optimizing Parameters:** Testing 100 parameter combinations and choosing the best one leads to overfitting. Test only 3-5 logical variations maximum to avoid curve-fitting.

**Ignoring Drawdowns:** Only looking at total return is dangerous. Maximum drawdown is as important as returns and shows the real risk of your strategy.

**Too-Short Time Periods:** Backtesting only 2-4 weeks isn't sufficient. Use a minimum of 3 months, preferably 6-12 months of data for reliable results.

**Assuming Perfect Execution:** Expecting exact entry/exit prices is unrealistic. Always include realistic costs and slippage in your backtests.

## After Backtesting

### If Results Are Good

**Next step: Paper Trading** - Don't go straight to live trading. Paper trade for 1-2 weeks minimum to verify live behavior matches your backtest, build confidence, then deploy small live positions.

[Paper Trading Guide →](/quantsedge-docs/strategy-lab/paper-trading.md)

### If Results Are Mixed

**Options:** Adjust parameters carefully, try different time periods, test a different strategy entirely, or combine with other strategies for diversification.

**Don't:** Keep tweaking until "perfect," skip paper trading, or risk real money yet.

### If Results Are Bad

**Don't force it:** Sometimes strategies simply don't work for certain markets. Try a completely different approach or accept that some ideas don't work in practice.

* Better to know now than after losing money

## Backtest Limitations

### What Backtesting Can't Tell You

**Future Market Conditions**

* Past performance ≠ future results
* Markets change
* New conditions emerge

**Psychological Factors**

* How you'll handle real losses
* Emotional discipline
* Stress of real money

**Exact Live Performance**

* Slippage varies
* Liquidity changes
* Technical issues can occur

**Black Swan Events**

* Extreme market crashes
* Exchange outages
* Unprecedented volatility

### Why You Still Need Paper Trading

Backtesting is essential but not sufficient:

* Paper trading tests real-time execution
* Reveals current market behavior
* Builds psychological readiness
* Final validation before live

**Never skip paper trading.**

## Quick Checklist

### Before Running Backtest

* [ ] Strategy logic is clear
* [ ] Parameters make sense
* [ ] Time period chosen (3-6 months minimum)
* [ ] Realistic fees included
* [ ] Starting capital set correctly

### After Backtest Results

* [ ] Total return is positive and reasonable
* [ ] Profit factor above 1.5
* [ ] Max drawdown acceptable (<20%)
* [ ] Sufficient number of trades (20+)
* [ ] Consistent across time periods
* [ ] No single trade creates all profit
* [ ] Ready for paper trading

## Next Steps

**Passed Backtesting?** Move to paper trading to validate in real-time. [Paper Trading Guide →](/quantsedge-docs/strategy-lab/paper-trading.md)

**Want to Optimize?** Learn advanced parameter tuning. [Strategy Optimization →](/quantsedge-docs/strategy-lab/strategy-optimization.md)

**Analyze Deeply** Understand performance metrics. [Performance Analysis →](/quantsedge-docs/strategy-lab/performance-analysis.md)

***

Backtesting is your first defense against bad strategies. Take it seriously, but remember it's only the first step in validation.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://quantsedge.gitbook.io/quantsedge-docs/strategy-lab/backtesting.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
