Logo van Backtesting Ml Models Against Transaction Costs

Backtesting Ml Models Against Transaction Costs

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

Gebruik dit wanneer een ML-model zijn voorspelling bijna bij elke bar omgooit en de Sharpe-ratio afhankelijk is van die hoge omzet. De skill rekent kosten per omzet aan en past een confidence-drempel toe voordat de strategie wordt beoordeeld. Kosten toewijzen op orderniveau kan met transaction-cost-analysis-tca-integration.

Add to TypingMind

Overzicht

UitgeverHimanshuJ16
RepositoryAlgo-Trading-Skills
Skillnaambacktesting-ml-models-against-transaction-costs
Sterren
50
Forks
7
Meegeleverde bestanden
5
LicentieApache-2.0
Links
  • Instructies in Markdown

    Het model laadt het bestand SKILL.md alleen als dat nodig is. Dat kost dus alleen tokens als een verzoek daadwerkelijk bij de skill past.

  • Werkt met elk LLM

    AI-skills bestaan uit instructies in gewone Markdown, niet uit aanbiederspecifieke code. Daardoor werken ze met GPT, Claude, Gemini, Grok of een lokaal model.

  • Meegeleverde bestanden: 5

    Scripts, sjablonen en referentiemateriaal die het model tijdens het werken kan lezen. De bestanden kunnen alleen worden gelezen en worden nooit uitgevoerd.

  • Open source

    Gepubliceerd door HimanshuJ16 op GitHub. Bekijk de bronbestanden voordat je de skill installeert.

Installatie

Installeer de AI-skill Backtesting Ml Models Against Transaction Costs in TypingMind om deze met elk LLM te gebruiken, of voeg de skill toe aan een andere agent die SKILL.md kan lezen.

1

Installeren in TypingMind

TypingMind installeert een skill rechtstreeks vanuit de GitHub-map. De app leest SKILL.md, bundelt de bijbehorende bestanden en slaat het resultaat lokaal op.

  1. Open de app en ga naar Plug-ins → Skills.
  2. Kies "Installeren via GitHub".
  3. Plak de onderstaande URL van de skillmap en bevestig.
    https://github.com/HimanshuJ16/Algo-Trading-Skills/tree/main/skills/backtesting-ml-models-against-transaction-costs
  4. Schakel de skill in voor elke chat waarin je de skill wilt kunnen gebruiken.
Plug-ins → Skills → Skill toevoegen → Via GitHub-URL. Plak vervolgens de map-URL en druk op Doorgaan.
2

Installeren in een andere agent

Elke agent die het Agent Skills-formaat kan lezen, kan deze skill gebruiken — kopieer de map naar de skillmap van die agent.

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
Start Claude Code na het kopiëren opnieuw op, zodat de nieuwe skill wordt herkend.

Gebruik deze skill in TypingMind

Schakel Backtesting Ml Models Against Transaction Costs in voor een chat naar keuze in TypingMind en het model doet de rest. De naam en beschrijving staan in de systeemprompt. Zodra een verzoek bij de skill past, laadt het model zelf de volledige instructies. Je hoeft de skill nooit handmatig aan te roepen. Pas als het model de skill daadwerkelijk gebruikt, kost dat tokens.

Het model laadt Backtesting Ml Models Against Transaction Costs automatisch zodra een verzoek erbij past.

Werkt met elk AI-model

AI-skills zijn gewone Markdown-instructies in plaats van aanbiederspecifieke code. Daardoor is Backtesting Ml Models Against Transaction Costs niet gebonden aan het model waarvoor de skill is geschreven. Installeer de skill één keer in TypingMind en gebruik deze met GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama of een lokaal model dat je zelf draait — allemaal met je eigen API-sleutels.

  • Alleen geladen wanneer nodig

    De systeemprompt bevat alleen de naam en beschrijving. De instructies worden bij het eerste bijpassende verzoek opgehaald, dus een ongebruikte skill kost niets.

  • Wissel van model tijdens een chat

    Omdat de skill uit instructies bestaat en niet uit code, blijft deze werken als je van model wisselt — het volgende model leest hetzelfde SKILL.md-bestand.

Skillinstructies

Dit is de inhoud van SKILL.md die het model laadt. Lees deze vóór de installatie — een skill bestaat uit instructies die je model zal volgen.

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

Meegeleverde bestanden

Zolang de skill geladen is, leest het model deze bestanden als dat nodig is. Het model kan ze alleen lezen; ze worden nooit uitgevoerd.

Veelgestelde vragen

Wat doet de AI-skill Backtesting Ml Models Against Transaction Costs?

Gebruik dit wanneer een ML-model zijn voorspelling bijna bij elke bar omgooit en de Sharpe-ratio afhankelijk is van die hoge omzet. De skill rekent kosten per omzet aan en past een confidence-drempel toe voordat de strategie wordt beoordeeld. Kosten toewijzen op orderniveau kan met transaction-cost-analysis-tca-integration.

Waarom Backtesting Ml Models Against Transaction Costs gebruiken in TypingMind?

Omdat je deze skill één keer installeert en met elk model kunt gebruiken. Backtesting Ml Models Against Transaction Costs bestaat uit gewone Markdown in plaats van aanbiederspecifieke code. Dezelfde skill werkt dus met GPT-5, Claude, Gemini, Grok of een lokaal model. Ook als je midden in een chat van model wisselt, blijft de skill werken. TypingMind werkt met je eigen API-sleutels, dus je betaalt aanbieders rechtstreeks in plaats van een abonnement per gebruikersplek af te sluiten. Je skills en chats blijven in je eigen opslag.

Hoe installeer ik Backtesting Ml Models Against Transaction Costs in TypingMind?

Open Plug-ins → Skills → Installeren vanaf GitHub in TypingMind en plak https://github.com/HimanshuJ16/Algo-Trading-Skills/tree/main/skills/backtesting-ml-models-against-transaction-costs. TypingMind leest het bestand SKILL.md, bundelt de bijbehorende bestanden en installeert het geheel als een skill die je per chat kunt inschakelen.

Welke AI-modellen kunnen Backtesting Ml Models Against Transaction Costs gebruiken?

Elk model dat je in TypingMind koppelt. AI-skills bestaan uit gewone Markdown-instructies in plaats van aanbiederspecifieke code. GPT, Claude, Gemini, Grok en lokale modellen kunnen deze skill dus allemaal laden wanneer een verzoek erbij past.

Hoeveel AI-modellen kan ik met Backtesting Ml Models Against Transaction Costs gebruiken?

Zoveel als je wilt. Je kunt Backtesting Ml Models Against Transaction Costs gebruiken met elk model dat skills ondersteunt, zoals GPT, Claude, Gemini, Grok, DeepSeek, Mistral of Llama. Allemaal in TypingMind met je eigen API-sleutels.

Is de AI-skill Backtesting Ml Models Against Transaction Costs gratis?

Ja. Deze skill is door HimanshuJ16 op GitHub gepubliceerd onder de licentie Apache-2.0. Je betaalt alleen je eigen AI-aanbieder voor de tokens die je gebruikt.

Wat zijn AI-skills?

Een AI-skill is een herbruikbare bundel instructies die een AI-model leert hoe het één specifieke taak moet uitvoeren. De skill volgt het open Agent Skills-formaat: het bestand SKILL.md bevat de naam en beschrijving van de skill. Daarnaast kan de skill scripts, sjablonen of referentiebestanden bevatten die het model nodig heeft. Het model leest de instructies alleen als je verzoek bij de skill past. Een geïnstalleerde skill kost dus niets zolang deze niet wordt gebruikt.

Waarin verschillen AI-skills van plug-ins of MCP-servers?

Een plug-in of MCP-server geeft een model nieuwe tools om aan te roepen: code die ergens wordt uitgevoerd en een resultaat teruggeeft. Een AI-skill geeft het model juist kennis en een werkwijze: hoe het een taak moet aanpakken, welke stappen het moet volgen en hoe goede uitvoer eruitziet. Skills bestaan uit gewone Markdown en hebben dus geen server, API-sleutel of runtime nodig. Ze werken met elk model.

Bekijk alles

Maak nu je eigen AI-werkruimte

Schrijf je in voor onze nieuwsbrief en blijf op de hoogte van nieuwe functies en toekomstige weggeefacties 👇