# Backtesting

Backtesting is the evaluation of a defined trading strategy against historical data to estimate how it would have behaved, subject to data, execution-cost and overfitting limitations.

## What it means

A backtest applies rules specified in advance to past market data and records the trades those rules would have generated. It asks how a strategy *would have behaved in that historical sample*, not what it will earn in the future. Rules might specify when to enter, when to exit, position sizes and how to handle cash.

A credible backtest uses only information available at each simulated decision time. It also accounts for trading costs, including commissions where applicable, bid-ask spreads and potential market impact. Otherwise, the simulated results can be more favorable than trades that could reasonably have been executed.

## How it is calculated

There is no single backtesting formula: the strategy first generates a sequence of hypothetical portfolio values. A simple measure of its total net return is `R_net = (V_end - V_start) / V_start × 100%`.

- `R_net` is the net return over the test period, in percent.
- `V_start` is the starting portfolio value, in US$.
- `V_end` is the ending portfolio value, in US$, after modeled trading costs and any applicable cash flows have been accounted for consistently.

With deposits or withdrawals during the test, that simple formula is not sufficient on its own; the calculation must adjust for external cash flows. A backtest may also report drawdown or other risk measures alongside returns. Every reported metric depends on the trading rules, historical data and cost assumptions used.

## Worked example

Suppose a hypothetical strategy starts a historical test with US$10,000 and makes one simulated round-trip stock trade. Its rules enter with the full starting amount and close the position later. Assume no dividends, deposits, withdrawals or other trades.

1. The simulated position ends with shares worth US$10,600 before trading costs: a gross gain of US$600.
2. Assume combined entry and exit costs total US$100, including modeled spread, market impact and commissions.
3. The ending value after those costs is US$10,500.
4. Net return is `(US$10,500 - US$10,000) / US$10,000 × 100% = 5%`. Without the costs, the reported return would have been 6%.

These hypothetical round numbers illustrate the calculation, not a likely outcome. A real backtest would apply the rules across its specified historical period and document how every simulated order was priced.

## Why it matters before you trade

Backtesting can expose how a stated set of rules behaved through different conditions in the available history. It can also reveal whether results depend heavily on a few trades or on optimistic execution assumptions. It does not establish that a strategy will work in a new market period.

Common checks include whether the test avoided *look-ahead bias*—using information that was not yet known—and whether the historical stock universe includes stocks that later disappeared. Testing many rule variations and reporting only the strongest result creates overfitting risk. Separating strategy development data from later, untouched test data can make that risk easier to assess, though it cannot eliminate it.

## How PreTrAIde uses it

PreTrAIde's stated function is pre-trade analysis, not historical strategy backtesting. Before any order is placed, a user builds a stock basket with a side, quantity and execution conditions for each line. PreTrAIde then returns GO, NO-GO or MODIFY verdicts for the basket and each line, with a model-estimated success probability, risk assessment, suggested execution strategy and plain-language reasoning. Those verdicts are decision support, not recommendations.

After a verdict, users can open a paper-trading simulation of the basket to follow how it would have performed. Following a basket after a verdict is different from applying a fixed strategy to an earlier historical period. Neither a historical backtest nor a paper simulation guarantees future results.

## Common mistakes

- **Treating historical return as a forecast.** The result describes assumptions applied to a past sample.
- **Ignoring execution costs.** A quoted closing price is not necessarily a price an order could have received.
- **Using future information.** Data published after a simulated trade cannot justify that trade.
- **Testing only surviving stocks.** Omitting delisted stocks can distort the sample.
- **Confusing paper trading with backtesting.** Paper trading follows simulated decisions without real money; backtesting applies rules to an earlier historical period.

---
Source: https://pretraide.com/glossary/backtesting
