> ## Documentation Index
> Fetch the complete documentation index at: https://docs.askfutures.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Overfitting vs. optimization

> Why the best-scoring parameter set is often the least trustworthy one — and how to read a sweep as a map of robustness, picking from a wide plateau instead of a razor-thin peak.

Run a sweep and the results arrive ranked, winner on top. The natural move is to
take the top row — it scored best, after all. This page is about why that natural
move is often the wrong one, and how the same sweep, read differently, is your
best defense against the mistake.

<Note>
  **Optimization and overfitting are not the same thing.** Overfitting is what
  happens when you use a sweep as a *leaderboard* and blindly take the #1 row.
  Used as a *map* — showing you which whole regions of parameter space work and
  which don't — the very same sweep is what protects you.
</Note>

## What overfitting is

A backtest replays real history, and real history is part signal, part noise —
repeatable behavior mixed with one-off accidents. When you test many parameter
combinations, some will inevitably line up well with the noise: a stop that
happened to dodge one bad afternoon, an EMA length that happened to catch one
lucky run. Those combinations score beautifully on the window you tested and
have no reason to score well on the next one.

That's **overfitting**: tuning a strategy so tightly to the past that it has
memorized the accidents instead of learning the behavior. And the more
combinations a sweep tries, the more chances the noise gets to produce a
flattering winner. The top of the ranking is exactly where the luckiest
accidents accumulate.

<Warning>
  A sweep finds the parameters that fit the **past** best — which is not the
  same as the parameters that will work next. Treat the best result as a
  hypothesis, not a guarantee. Past performance does not guarantee future
  results.
</Warning>

## Peaks and plateaus

The defense comes from looking at the **shape** of the results, not just their
order. Plot performance against a swept parameter and two very different
pictures can produce the same #1 row:

```text theme={null}
 P&L                 The fragile peak          P&L               The robust plateau

  ▲          ★                                  ▲        ●   ●   ★   ●   ●
  │          │                                  │      ●                   ●
  │          │                                  │
  │  ●   ●   │   ●   ●                          │  ●                           ●
  │──●───●───┴───●───●──▶ stop size             │──●───────────────────────────●──▶ stop size
        one value works,                              a whole region works,
        its neighbors lose                            the exact value barely matters
```

<CardGroup cols={2}>
  <Card title="The fragile peak" icon="triangle-exclamation">
    One combination scores far above everything around it. Move the stop by a
    tick or the EMA by one bar and the edge evaporates. That sensitivity is the
    signature of noise: a real market behavior doesn't switch off because a
    parameter moved 5%. This is the overfitted pick — impressive on the ranking,
    unlikely to survive contact with new data.
  </Card>

  <Card title="The robust plateau" icon="mountain-sun">
    A broad, contiguous region of parameter values that all perform decently.
    The strategy works with a $300 stop *and* a $350 stop *and* a \$400 stop —
    which tells you it's keying on something about how the market actually
    moves, not on one lucky configuration. This is the pick that has a chance
    of holding up.
  </Card>
</CardGroup>

The counterintuitive part: **a good value inside the plateau beats the peak,
even when the peak's backtest number is higher.** The peak's extra score is
mostly rented from noise, and noise doesn't repeat. The plateau's score is
lower but owned.

## How optimization defends against overfitting

This is why a sweep is worth running even though it *creates* the opportunity
to overfit: a single backtest can't tell you whether its parameters sit on a
peak or a plateau. Only testing the neighborhood can. The sweep is a
**sensitivity map** of your strategy, and AskFutures gives you two views built
for reading it that way:

* **The Parametric heatmap** (for two swept parameters) shades every
  combination by your metric. Robustness is visible at a glance: look for a
  contiguous block of good cells, not one bright cell surrounded by losers. A
  strong row or column also tells you something — the strategy cares about one
  parameter and is indifferent to the other.
* **The Dot Chart** (and the one-parameter scatter) shows every combination as
  a point. A broad cluster of decent results is the plateau; a single dot
  floating above scattered losers is the peak.

<Steps>
  <Step title="Sweep a real neighborhood">
    Give each parameter a range wide enough to see the shape — not just three
    values hugging your current setting. You're mapping terrain, not confirming
    a guess.
  </Step>

  <Step title="Read the shape before the ranking">
    Open the Parametric heatmap or the scatter first. Is there a region that
    works, or just a point? If there's no plateau anywhere, the honest
    conclusion is that the edge isn't robust — no row of the ranking fixes that.
  </Step>

  <Step title="Pick from the middle of the plateau">
    Choose a value comfortably inside the good region — even if it isn't the
    top-ranked row. The center of a plateau has the most room to stay profitable
    when the market drifts; the edge of one is halfway to being a peak.
  </Step>

  <Step title="Re-test the pick on data it hasn't seen">
    Save the chosen combination as a new version and run it on a different
    window — a more recent stretch you didn't sweep over. A plateau pick that
    also survives out-of-sample is as much confidence as a backtest can give
    you. See [version and compare](/guides/version-and-compare).
  </Step>
</Steps>

<Tip>
  A useful habit when two combinations look close: prefer the one whose
  *neighbors* score better, not the one whose own score is higher. You're not
  choosing a number, you're choosing a neighborhood.
</Tip>

## Red flags that you're overfitting

<AccordionGroup>
  <Accordion title="The winner's neighbors lose" icon="triangle-exclamation">
    The top combination is great, but one step away in any direction is
    break-even or worse. The exact opposite of what a real edge looks like.
  </Accordion>

  <Accordion title="The winning values are oddly specific" icon="magnifying-glass">
    An EMA of 23, a stop of \$437. When the "best" value isn't part of any
    sensible region, it was almost certainly elected by noise.
  </Accordion>

  <Accordion title="You keep widening the sweep to find a winner" icon="arrows-left-right">
    If the idea only works after sweeping four parameters across huge ranges,
    the sweep isn't refining an edge — it's manufacturing one. More combinations
    tried means a luckier, less trustworthy winner. Fix the logic in chat
    instead; see [when to optimize](/concepts/optimization#when-to-optimize).
  </Accordion>

  <Accordion title="Performance collapses on a fresh window" icon="calendar-xmark">
    The swept window looks great, the recent months you held out don't. That
    gap *is* the overfitting, measured directly.
  </Accordion>
</AccordionGroup>

<Warning>
  Backtest and optimization results are **hypothetical and simulated** — no
  real trades were placed, and simulated results are designed with the benefit
  of hindsight. Past performance, actual or simulated, does not guarantee
  future results. Always test before you trade.
</Warning>

## Next steps

<CardGroup cols={2}>
  <Card title="Optimization" icon="sliders" href="/concepts/optimization">
    How sweeps work: ranges, metrics, and the two-tier engine.
  </Card>

  <Card title="Optimize a strategy" icon="gauge-high" href="/guides/optimize-a-strategy">
    Run a sweep by chatting or on the card, and read the heatmap.
  </Card>

  <Card title="Version & compare" icon="code-compare" href="/guides/version-and-compare">
    Save the plateau pick as a new version and test it out of sample.
  </Card>

  <Card title="Is the backtest real?" icon="shield-check" href="/concepts/is-the-backtest-real">
    Where the AI stops and the deterministic math begins.
  </Card>
</CardGroup>
