Ml4t Backtest Overfitting logo

Ml4t Backtest Overfitting

Organization
ml4t
ml4t-backtest-overfitting

Detect and prevent overfitting to historical data via multiple testing corrections and pre-registration. Use when evaluating strategy variants to ensure performance is not a data-mining artifact.

Overview

Publisherml4t
Repositoryskills
Skill nameml4t-backtest-overfitting
Stars
45
Forks
13
Bundled files
Instructions only
LicenseApache-2.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by ml4t on GitHub. Read the source before you install it.

Installation

Install the Ml4t Backtest Overfitting AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/ml4t/skills/tree/main/concepts/backtest-overfitting
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/ml4t/skills.git /tmp/skills
mkdir -p .claude/skills
cp -r /tmp/skills/concepts/backtest-overfitting .claude/skills/ml4t-backtest-overfitting
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Ml4t Backtest Overfitting in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Ml4t Backtest Overfitting on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Ml4t Backtest Overfitting is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Backtest Overfitting

Testing many strategies on the same data guarantees finding one that looks profitable by chance. With 100 independent trials at p < 0.05, you expect five false positives.

The Problem

Every parameter you tune, every feature you try, and every universe filter you adjust is an implicit trial. A researcher who reports a Sharpe ratio of 2.0 after exploring 200 configurations has not found alpha - they have found the luckiest draw from a noise distribution. Correcting for the number of trials, by haircut here and by Deflated Sharpe Ratio in ml4t-deflated-sharpe, is what separates the two. Without it, most published backtests are statistically meaningless.

The Pattern

WRONG

python
# Tune until something looks good
best_sharpe = 0
for lookback in [5, 10, 21, 63, 126, 252]:
    for top_k in [5, 10, 20, 50]:
        result = backtest(lookback=lookback, top_k=top_k)
        sharpe = result["sharpe"]
        if sharpe > best_sharpe:
            best_sharpe = sharpe
            best_params = (lookback, top_k)

print(f"Best Sharpe: {best_sharpe:.2f}")  # meaningless without correction

CORRECT

python
import numpy as np
from scipy.stats import norm

results = []
for lookback in [5, 10, 21, 63, 126, 252]:
    for top_k in [5, 10, 20, 50]:
        result = backtest(lookback=lookback, top_k=top_k)
        results.append(result["sharpe"])

# Sharpe haircut: subtract the selection bound (Bailey & Lopez de Prado).
n_trials = len(results)
best_sharpe = max(results)
sharpe_std = np.std(results)
expected_max = sharpe_std * (
    (1 - np.euler_gamma) * norm.ppf(1 - 1 / n_trials)
    + np.euler_gamma * norm.ppf(1 - 1 / (n_trials * np.e))
)
# This is NOT the Deflated Sharpe Ratio, which is a probability that also
# takes sample size, skew and kurtosis: see ml4t-deflated-sharpe.
haircut = best_sharpe - expected_max
print(f"Observed: {best_sharpe:.2f}, After haircut: {haircut:.2f}, Trials: {n_trials}")

Probability of Backtest Overfitting (PBO)

PBO uses combinatorial CV (CSCV; see cpcv skill) to generate multiple train/test paths, then checks how often the IS-best strategy underperforms OOS:

python
import numpy as np
from itertools import combinations

n_groups, n_test = 8, 4  # CSCV splits into complementary halves, not 2-of-8
groups = np.array_split(np.arange(len(data)), n_groups)
ranks = []  # relative OOS rank of the strategy chosen in sample
for test_g in combinations(range(n_groups), n_test):
    test = np.concatenate([groups[g] for g in test_g])
    train = np.concatenate([groups[g] for g in range(n_groups) if g not in test_g])
    is_sharpe = [backtest(p, data[train])["sharpe"] for p in param_grid]
    oos_sharpe = [backtest(p, data[test])["sharpe"] for p in param_grid]
    best_is = int(np.argmax(is_sharpe))  # the one you would have shipped
    rank = np.argsort(oos_sharpe)[::-1].tolist().index(best_is)
    ranks.append(rank / (len(param_grid) - 1))  # 0 = best OOS, 1 = worst

pbo = np.mean(np.array(ranks) > 0.5)  # how often the IS winner is below median

Red Flags

SignalConcern
Sharpe > 2.0 on daily dataAlmost certainly overfit or leakage
OOS matches IS within 5%Data leakage, not genuine alpha
Complex model barely beats simpleExtra parameters fit noise
Performance cliff after 2020Regime-specific overfitting

Guardrails

  • Document total configurations tested - each is a trial. Separate exploration from confirmation.
  • Pre-register hypothesis and success threshold in version control before any backtest.
  • Minimum 5 years daily data (~1,250 observations) for Sharpe estimation.
  • If the haircut Sharpe is negative, the strategy has no statistical evidence of alpha.

Production Implementation

ml4t-diagnostic provides validated implementations of both corrections:

python
from ml4t.diagnostic.evaluation.stats import compute_pbo, benjamini_hochberg_fdr
from ml4t.diagnostic.splitters import CombinatorialCV

cpcv = CombinatorialCV(n_groups=8, n_test_groups=4, embargo_size=5)  # halves, as above
pbo = compute_pbo(np.array(is_sharpes), np.array(oos_sharpes))
rejected = benjamini_hochberg_fdr(p_values, alpha=0.05)

Checklist

  • Strategy hypothesis committed to git BEFORE any backtest
  • Total trials documented (including informal exploration); multiple-testing correction applied
  • Sharpe haircut applied, and DSR from ml4t-deflated-sharpe reported with it
  • PBO calculated from combinatorial CV folds (PBO < 0.50 required)
  • True holdout set preserved and used exactly once

Frequently asked questions

What does the Ml4t Backtest Overfitting AI skill do?

Detect and prevent overfitting to historical data via multiple testing corrections and pre-registration. Use when evaluating strategy variants to ensure performance is not a data-mining artifact.

Why use Ml4t Backtest Overfitting on TypingMind?

Because you install it once and use it with any model. Ml4t Backtest Overfitting is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Ml4t Backtest Overfitting in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/ml4t/skills/tree/main/concepts/backtest-overfitting. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Ml4t Backtest Overfitting?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Ml4t Backtest Overfitting?

As many as you like. As long as a model supports skills, you can use Ml4t Backtest Overfitting with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Ml4t Backtest Overfitting AI skill free?

Yes. It is published on GitHub by ml4t under the Apache-2.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇