Logo vun Ml4t Backtest Overfitting

Ml4t Backtest Overfitting

Organisatioun
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.

Iwwersiicht

Editeurml4t
Repositoryskills
Skill-Nummml4t-backtest-overfitting
Stären
45
Forks
13
Matgeliwwert Fichieren
Nëmmen Instruktiounen
LizenzApache-2.0
Linken
  • Instruktiounen am Markdown-Format

    Eng SKILL.md-Datei, déi de Modell bei Bedarf luet, soudatt nëmmen Token ufalen, wann eng Ufro tatsächlech dozou passt.

  • Funktionéiert mat all LLM

    KI-Skills si reng Markdown, keen ubidderspezifesche Code. Dofir funktionéiert dëse Skill mat GPT, Claude, Gemini, Grok oder engem lokale Modell.

  • Alles an den Instruktiounen

    Alles, wat de Modell brauch, steet an den Instruktiounen — keng zousätzlech Dateien ze synchroniséieren.

  • Open Source

    Vum ml4t op GitHub verëffentlecht. Liest de Quelltext, ier Dir de Skill installéiert.

Installatioun

Installéiert de KI-Skill Ml4t Backtest Overfitting an TypingMind, fir e mat all LLM ze benotzen, oder füügt en an en anere KI-Agent an, deen SKILL.md liest.

1

An TypingMind installéieren

TypingMind installéiert e Skill direkt aus sengem GitHub-Dossier — dobäi gëtt SKILL.md gelies, d'Ressourcedateie gi gebëndelt an d'Resultat gëtt lokal gespäichert.

  1. Maacht d'App op a gitt op Plugins → Skills.
  2. Wielt „Vun GitHub installéieren“.
  3. Pecht d'URL vum Skill-Dossier hei drënner an a bestätegt.
    https://github.com/ml4t/skills/tree/main/concepts/backtest-overfitting
  4. Aktivéiert de Skill an all Chat, an deem Dir e benotze wëllt.
Plugins → Skills → Skill afügen → Vu GitHub-URL, pecht dann d'URL vum Dossier an a klickt op Weider.
2

An engem anere KI-Agent installéieren

All KI-Agent, deen d'Format Agent Skills liest, kann dëse Skill benotzen — kopéiert den Dossier an de Skill-Verzeechnes vun deem KI-Agent.

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
Start Claude Code nom Kopéieren nei, fir datt den neie Skill erkannt gëtt.

An TypingMind benotzen

Aktivéiert Ml4t Backtest Overfitting an engem Chat vun TypingMind, an de Modell iwwerhëlt de Rescht. Den Numm an d'Beschreiwung stinn am System-Prompt. Soubal eng Ufro dozou passt, luet de Modell déi komplett Instruktioune selwer — Dir musst de Skill ni manuell opruffen, an et fale keng Token un, bis en tatsächlech benotzt gëtt.

De Modell luet Ml4t Backtest Overfitting automatesch, soubal eng Ufro dozou passt.

Funktionéiert mat all KI-Modell

KI-Skills si reng Markdown-Instruktiounen amplaz vun ubidderspezifeschem Code. Dofir ass Ml4t Backtest Overfitting net un de Modell gebonnen, fir deen de Skill geschriwwe gouf. Installéiert en eemol an TypingMind a benotzt e mat GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama oder engem lokale Modell, deen Dir selwer bedreift — alles mat Ären eegenen API-Keys.

  • Gëtt nëmme gelueden, wann et néideg ass

    De System-Prompt enthält nëmmen den Numm an d'Beschreiwung. D'Instruktioune gi bei der éischter passender Ufro gelueden, soudatt en onbenotzte Skill näischt kascht.

  • De Modell am lafende Chat wiesselen

    Well de Skill aus Instruktiounen amplaz vu Code besteet, funktionéiert en och no engem Modellwiessel — den nächste Modell liest déi selwecht SKILL.md-Datei.

Skill-Instruktiounen

Dëst ass den Inhalt vu SKILL.md, deen de Modell luet. Liest e virun der Installatioun — e Skill besteet aus Instruktiounen, déi Äre Modell befollegt.

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

Heefeg gestallte Froen

Wat mécht de KI-Skill 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.

Firwat Ml4t Backtest Overfitting op TypingMind benotzen?

Well Dir en eemol installéiert a mat all Modell benotze kënnt. Ml4t Backtest Overfitting besteet aus einfachem Markdown amplaz vun ubidderspezifeschem Code. Dee selwechte Skill funktionéiert also mat GPT-5, Claude, Gemini, Grok oder engem lokale Modell – an Dir kënnt de Modell matzen am Chat wiesselen, ouni datt de Skill ophält ze funktionéieren. TypingMind benotzt Är eegen API-Schlësselen, sou datt Dir d'Ubidder direkt bezuelt amplaz vun engem Abonnement pro Benotzerplaz. Är Skills a Chats bleiwen an Ärem eegene Späicher.

Wéi installéieren ech Ml4t Backtest Overfitting an TypingMind?

Maacht an TypingMind Plugins → Skills → Vu GitHub installéieren op a setzt https://github.com/ml4t/skills/tree/main/concepts/backtest-overfitting an. TypingMind liest d'Datei SKILL.md an installéiert de Skill, deen Dir pro Chat aktivéiere kënnt.

Wéi eng KI-Modeller kënnen Ml4t Backtest Overfitting benotzen?

All Modell, deen Dir an TypingMind verbënnt. KI-Skills sinn einfach Markdown-Instruktiounen an net ubidderspezifesche Code. Dofir kënne GPT, Claude, Gemini, Grok a lokal Modeller dëse Skill lueden, wann eng Ufro dozou passt.

Wéi vill KI-Modeller kann ech mat Ml4t Backtest Overfitting benotzen?

Esou vill Dir wëllt. Soulaang e Modell Skills ënnerstëtzt, kënnt Dir Ml4t Backtest Overfitting domat benotzen – GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama a méi – alles op TypingMind mat Ären eegenen API-Schlësselen.

Ass de KI-Skill Ml4t Backtest Overfitting gratis?

Jo. De Skill gëtt vum ml4t ënner der Lizenz Apache-2.0 op GitHub publizéiert. Dir bezuelt nëmmen Ären eegene KI-Ubidder fir d'Token, déi Dir benotzt.

Wat si KI-Skills?

E KI-Skill ass e weiderverwendbaart Pak vun Instruktiounen, dat engem KI-Modell bäibréngt, wéi en eng bestëmmt Aufgab erfëllt. E follegt dem oppenen Agent Skills-Format: eng Datei SKILL.md mat engem Numm an enger Beschreiwung, plus all Scripten, Virlagen oder Referenzdateien, déi de Modell eventuell brauch. De Modell liest d'Instruktiounen eréischt, wann Är Ufro zum Skill passt. En installéierte Skill kascht also näischt, bis e benotzt gëtt.

Wéi ënnerscheede sech KI-Skills vu Plugins oder MCP-Serveren?

E Plugin oder MCP-Server gëtt engem Modell nei Tools, déi en opruffe kann – Code, deen iergendwou leeft an e Resultat zeréckgëtt. E KI-Skill gëtt dem Modell dogéint Wëssen an eng Virgoensweis: wéi en eng Aufgab ugeet, wéi eng Schrëtt en nokënnt a wéi eng gutt Ausgab ausgesäit. Skills bestinn aus einfachem Markdown, brauche kee Server, keen API-Schlëssel a keng Lafzäitëmfeld a funktionéiere mat all Modell.

All weisen

Elo Ären eegene KI-Workspace ariichten

Abonnéiert Iech op eisen Newsletter, fir iwwer nei Funktiounen an zukünfteg Gewënnspiller informéiert ze ginn 👇