Logo von Backtesting Ml Models Against Transaction Costs

Backtesting Ml Models Against Transaction Costs

Community
HimanshuJ16
backtesting-ml-models-against-transaction-costs

Verwenden Sie diesen Skill, wenn ein ML-Modell seine Prognose bei nahezu jedem Balken ändert und die Sharpe Ratio vom Handelsumsatz abhängt. Er berücksichtigt Kosten pro Umsatz und wendet einen Konfidenzschwellenwert an, bevor die Strategie bewertet wird. Die Kostenzuordnung auf Auftragsebene finden Sie unter transaction-cost-analysis-tca-integration.

Add to TypingMind

Übersicht

HerausgeberHimanshuJ16
RepositoryAlgo-Trading-Skills
Skill-Namebacktesting-ml-models-against-transaction-costs
Sterne
50
Forks
7
Mitgelieferte Dateien
5
LizenzApache-2.0
Links
  • Anweisungen in Markdown

    Eine SKILL.md-Datei, die das Modell bei Bedarf lädt. So werden nur dann Token verbraucht, wenn eine Anfrage tatsächlich dazu passt.

  • Funktioniert mit jedem LLM

    KI-Skills bestehen aus reinem Markdown, nicht aus anbieterspezifischem Code. Daher funktionieren sie mit GPT, Claude, Gemini, Grok oder einem lokalen Modell.

  • Mitgelieferte Dateien: 5

    Skripte, Vorlagen und Referenzmaterial, die das Modell bei der Arbeit lesen kann. Die Dateien sind schreibgeschützt und werden niemals ausgeführt.

  • Open Source

    Von HimanshuJ16 auf GitHub veröffentlicht. Prüfen Sie vor der Installation die Quelldateien.

Installation

Installieren Sie den KI-Skill Backtesting Ml Models Against Transaction Costs in TypingMind, um ihn mit jedem LLM zu nutzen, oder fügen Sie ihn einem anderen Agenten hinzu, der SKILL.md lesen kann.

1

In TypingMind installieren

TypingMind installiert einen Skill direkt aus seinem GitHub-Ordner. Dabei liest die App SKILL.md, bündelt die Ressourcendateien und speichert das Ergebnis lokal.

  1. Öffnen Sie die App und gehen Sie zu Plugins → Skills.
  2. Wählen Sie „Von GitHub installieren“.
  3. Fügen Sie die unten angegebene URL des Skill-Ordners ein und bestätigen Sie.
    https://github.com/HimanshuJ16/Algo-Trading-Skills/tree/main/skills/backtesting-ml-models-against-transaction-costs
  4. Aktivieren Sie den Skill in jedem Chat, in dem er verfügbar sein soll.
Plugins → Skills → Skill hinzufügen → Über GitHub-URL. Fügen Sie dann die Ordner-URL ein und klicken Sie auf „Weiter“.
2

In einem anderen Agenten installieren

Jeder Agent, der das Agent-Skills-Format unterstützt, kann diesen Skill nutzen. Kopieren Sie den Ordner in das Skill-Verzeichnis des jeweiligen Agenten.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/HimanshuJ16/Algo-Trading-Skills.git /tmp/Algo-Trading-Skills
mkdir -p .claude/skills
cp -r /tmp/Algo-Trading-Skills/skills/backtesting-ml-models-against-transaction-costs .claude/skills/backtesting-ml-models-against-transaction-costs
Starten Sie Claude Code nach dem Kopieren neu, damit der neue Skill erkannt wird.

In TypingMind verwenden

Aktivieren Sie Backtesting Ml Models Against Transaction Costs in einem beliebigen Chat in TypingMind. Den Rest übernimmt das Modell. Name und Beschreibung des Skills stehen im System-Prompt. Sobald eine Anfrage passt, lädt das Modell selbstständig die vollständigen Anweisungen — Sie müssen den Skill nie manuell aufrufen, und er verbraucht erst Token, wenn er tatsächlich genutzt wird.

Das Modell lädt Backtesting Ml Models Against Transaction Costs automatisch, sobald eine passende Anfrage gestellt wird.

Funktioniert mit jedem KI-Modell

KI-Skills bestehen aus reinen Markdown-Anweisungen statt aus anbieterspezifischem Code. Daher ist Backtesting Ml Models Against Transaction Costs nicht an das Modell gebunden, für das der Skill geschrieben wurde. Installieren Sie ihn einmal in TypingMind und nutzen Sie ihn mit GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama oder einem selbst betriebenen lokalen Modell — alles mit Ihren eigenen API-Schlüsseln.

  • Wird nur bei Bedarf geladen

    Der System-Prompt enthält nur den Namen und die Beschreibung. Die Anweisungen werden bei der ersten passenden Anfrage geladen. Ein ungenutzter Skill verursacht daher keine Kosten.

  • Modell im laufenden Chat wechseln

    Da der Skill aus Anweisungen statt aus Code besteht, funktioniert er auch nach einem Modellwechsel — das nächste Modell liest dieselbe SKILL.md-Datei.

Skill-Anweisungen

Dies ist der Inhalt von SKILL.md, den das Modell lädt. Lesen Sie ihn vor der Installation — ein Skill besteht aus Anweisungen, denen Ihr Modell folgt.

When to Use

Machine learning models inherently generate highly active signals (e.g., changing predictions from slightly positive to slightly negative on every bar). Without strict Transaction Cost Analysis (TCA) and confidence thresholding, these models achieve massive theoretical Sharpe ratios that instantly collapse in live trading due to Turnover Drag. Invoke this skill to evaluate ML model predictions against realistic slippage and commission models, filtering out low-confidence trades that do not cover their own execution costs.

When NOT to Use

  • Order-level cost attribution. This skill models cost as a flat bps charge per unit of turnover. To decompose realised shortfall into delay, spread, and market impact, use transaction-cost-analysis-tca-integration.
  • Size-dependent impact. The flat-rate model has no ADV or participation term, so it will understate cost for orders that are large relative to available liquidity. Pair it with liquidity-adjusted-position-sizing and strategy-capacity-estimation-before-scaling-capital before scaling capital.
  • Continuous or leveraged target weights. Positions here are discrete {-1, 0, +1}. A continuous-weight portfolio needs turnover computed on the weight vector — see portfolio-construction-with-transaction-cost-awareness.

Prerequisites

  • An array of numerical ML predictions (e.g., predicted forward returns or continuous signal strength).
  • An array of actual underlying returns, already aligned so that element i is the return realised after predictions[i] was observable. The backtester cannot detect misalignment.
  • Estimated transaction costs in basis points (bps) per half-turn (e.g., 5 bps for slippage + fee), calibrated against your own execution data rather than a folklore constant.

Workflow

  1. Align predictions to forward returns: pair predictions[t] with the return earned by acting on it (t → t+1, or t+1 → t+2 if your execution lags the signal by a bar). Getting this wrong is the single most common way to produce a spectacular, meaningless backtest.
  2. Clean the inputs: drop or impute NaN/Inf predictions before the backtest. A NaN prediction silently classified as "flat" is a hidden regime change in the strategy, not a neutral default — MlTcaBacktester rejects non-finite input rather than absorbing it.
  3. Set the hurdle: the entry threshold must clear the round-trip cost. A position that is entered and later exited pays 2 units of turnover, so require signal_threshold >= 2 * bps_cost_half_turn / 10_000 in decimal-return units. Below this line, a correct prediction is still a losing trade.
  4. Generate positions: map predictions to {+1, -1, 0} against the threshold.
  5. Decide whether to apply a buy/hold spread: if the model churns around the threshold boundary, set exit_threshold < signal_threshold so an open position is held until conviction genuinely decays, rather than being closed and re-entered on noise.
  6. Calculate turnover: costs are charged on position changes only. Flat→long is 1 unit; long→short is 2 units; a position still open on the final bar owes its exit half-turn (liquidate_at_end, on by default).
  7. Apply cost drag and compute net returns: subtract turnover × bps_cost_half_turn / 10_000 from gross returns each period.
  8. Sweep the threshold out-of-sample: pick signal_threshold/exit_threshold on training folds and confirm them on held-out data. Choosing the threshold that maximises net return on the same sample you report is parameter mining, not cost control — see walk-forward-optimization-window-management.
  9. Stress the cost assumption: re-run at 2–3× your estimated bps. A strategy whose net edge disappears when costs double has no margin for a bad execution day.

Full procedure: see references/workflows.md. Standards reference: see references/standards.md. Printable pre-flight checklist: see assets/checklist.md.

Common Pitfalls

  • Ignoring State Persistence: Charging a transaction cost on every bar simply because the model predicted "Buy", even though the portfolio is already in a "Buy" state. Costs are only incurred on position changes (Turnover).
  • Zero Thresholding: Taking trades on microscopic predictions (e.g., model predicts +0.0001% return) which guarantees a net loss when the transaction cost is 0.05%. A threshold of exactly 0 is worse than useless — it makes the long and short conditions overlap, so a neutral prediction can be classified as a short.
  • Symmetric Costs: Forgetting that crossing the spread (market order) costs money on both entry and exit (half-turns).
  • The Free Exit: Ending the backtest with an open position and never charging the closing half-turn. On a low-trade-count strategy this can hide a meaningful slice of total cost.
  • Contemporaneous Returns: Multiplying predictions[t] by the return of the bar the prediction was made on. This is look-ahead bias, and the resulting equity curve survives any cost assumption you throw at it — see lookahead-bias-elimination.
  • NaN as Neutral: Letting missing predictions default to "flat". The backtest then reports a strategy nobody can trade, and a NaN in the return series silently poisons every compounded metric.
  • Threshold Mined In-Sample: Sweeping signal_threshold across the full history and reporting the best net result. The threshold is a free parameter, and cost-aware backtests overfit it as readily as any other.

Verification

  • Simulate an ML model that perfectly predicts 10% returns but flips direction every day. Apply a 6% (600 bps) per-half-turn cost. The gross return will be massive, but the net return must be decisively negative — covered by test_perfect_but_churning_model_is_net_negative.
  • Confirm a held position is charged once, not once per bar: two consecutive identical long signals must produce 1 unit of turnover, not 2.
  • Confirm a neutral (0.0) prediction maps to flat, never to short.
  • Run python -m unittest discover -s skills/backtesting-ml-models-against-transaction-costs/scripts and confirm a 100% pass rate.

Related Skills

  • transaction-cost-analysis-tca-integration
  • execution-cost-model-recalibration-cadence
  • lookahead-bias-elimination
  • execution-realistic-simulation
  • walk-forward-optimization-window-management
  • portfolio-construction-with-transaction-cost-awareness

Mitgelieferte Dateien

Das Modell liest diese Dateien bei Bedarf, während der Skill geladen ist. Sie werden als lesbare Dateien bereitgestellt und niemals ausgeführt.

Häufig gestellte Fragen

Was macht der KI-Skill Backtesting Ml Models Against Transaction Costs?

Verwenden Sie diesen Skill, wenn ein ML-Modell seine Prognose bei nahezu jedem Balken ändert und die Sharpe Ratio vom Handelsumsatz abhängt. Er berücksichtigt Kosten pro Umsatz und wendet einen Konfidenzschwellenwert an, bevor die Strategie bewertet wird. Die Kostenzuordnung auf Auftragsebene finden Sie unter transaction-cost-analysis-tca-integration.

Warum Backtesting Ml Models Against Transaction Costs in TypingMind nutzen?

Weil Sie den Skill einmal installieren und mit jedem Modell verwenden können. Backtesting Ml Models Against Transaction Costs besteht aus reinem Markdown statt aus anbieterspezifischem Code. So funktioniert derselbe Skill mit GPT-5, Claude, Gemini, Grok oder einem lokalen Modell – und Sie können das Modell mitten im Chat wechseln, ohne dass der Skill seine Funktion verliert. TypingMind verwendet Ihre eigenen API-Schlüssel. Sie bezahlen die Anbieter daher direkt statt über ein Abonnement pro Nutzerplatz, und Ihre Skills und Chats bleiben in Ihrem eigenen Speicher.

Wie installiere ich Backtesting Ml Models Against Transaction Costs in TypingMind?

Öffnen Sie in TypingMind Plugins → Skills → Von GitHub installieren und fügen Sie https://github.com/HimanshuJ16/Algo-Trading-Skills/tree/main/skills/backtesting-ml-models-against-transaction-costs ein. TypingMind liest die Datei SKILL.md, bündelt die zugehörigen Dateien und installiert alles als Skill, den Sie für jeden Chat einzeln aktivieren können.

Welche KI-Modelle können Backtesting Ml Models Against Transaction Costs nutzen?

Jedes Modell, das Sie mit TypingMind verbinden. KI-Skills bestehen aus reinen Markdown-Anweisungen statt aus anbieterspezifischem Code. Daher können GPT, Claude, Gemini, Grok und lokale Modelle diesen Skill laden, wenn eine Anfrage dazu passt.

Wie viele KI-Modelle kann ich mit Backtesting Ml Models Against Transaction Costs verwenden?

So viele Sie möchten. In TypingMind können Sie Backtesting Ml Models Against Transaction Costs mit jedem Modell verwenden, das Skills unterstützt, etwa mit GPT, Claude, Gemini, Grok, DeepSeek, Mistral oder Llama. Dabei nutzen Sie Ihre eigenen API-Schlüssel.

Ist der KI-Skill Backtesting Ml Models Against Transaction Costs kostenlos?

Ja. Der Skill wird von HimanshuJ16 auf GitHub unter der Lizenz Apache-2.0 veröffentlicht. Sie bezahlen nur Ihren eigenen KI-Anbieter für die verwendeten Token.

Was sind KI-Skills?

Ein KI-Skill ist ein wiederverwendbares Anweisungspaket, das einem KI-Modell vermittelt, wie es eine bestimmte Aufgabe erledigt. Es folgt dem offenen Format Agent Skills: Die Datei SKILL.md enthält den Namen und die Beschreibung des Skills. Hinzu kommen bei Bedarf Skripte, Vorlagen oder Referenzdateien für das Modell. Das Modell liest die Anweisungen nur, wenn Ihre Anfrage zum Skill passt. Ein installierter Skill verursacht daher erst Kosten, wenn er verwendet wird.

Wie unterscheiden sich KI-Skills von Plugins oder MCP-Servern?

Ein Plugin oder MCP-Server stellt einem Modell neue aufrufbare Tools bereit – Code, der auf einem System ausgeführt wird und ein Ergebnis zurückgibt. Ein KI-Skill vermittelt dem Modell stattdessen Wissen und Vorgehensweisen: wie es eine Aufgabe angeht, welche Schritte es befolgt und wie eine gute Ausgabe aussieht. Skills bestehen aus reinem Markdown und kommen daher ohne Server, API-Schlüssel und Laufzeitumgebung aus. Sie funktionieren mit jedem Modell.

Alle anzeigen

Jetzt eigenen KI-Arbeitsbereich einrichten

Abonnieren Sie unseren Newsletter und erfahren Sie mehr über neue Funktionen und kommende Gewinnspiele 👇