Logo van Backtest Determinism And Reproducibility

Backtest Determinism And Reproducibility

Community
HimanshuJ16
backtest-determinism-and-reproducibility

Gebruik dit wanneer identieke backtestcode en -gegevens bij verschillende runs andere P&L- of Sharpe-waarden opleveren, waardoor optimalisatie onbetrouwbaar wordt: deterministische seeding, een strikte sorteervolgorde voor invoer, een gesimuleerde klok in plaats van uitlezingen van de systeemtijd en detectie van verschillen tussen runs.

Overzicht

UitgeverHimanshuJ16
RepositoryAlgo-Trading-Skills
Skillnaambacktest-determinism-and-reproducibility
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 Backtest Determinism And Reproducibility 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/backtest-determinism-and-reproducibility
  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/backtest-determinism-and-reproducibility .claude/skills/backtest-determinism-and-reproducibility
Start Claude Code na het kopiëren opnieuw op, zodat de nieuwe skill wordt herkend.

Gebruik deze skill in TypingMind

Schakel Backtest Determinism And Reproducibility 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 Backtest Determinism And Reproducibility automatisch zodra een verzoek erbij past.

Werkt met elk AI-model

AI-skills zijn gewone Markdown-instructies in plaats van aanbiederspecifieke code. Daardoor is Backtest Determinism And Reproducibility 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

Invoke this skill when building backtest simulation engines or CI regression suites. If backtest runs produce varying P&L curves or Sharpe ratios across identical code and data, parameter optimization becomes impossible to trust — you cannot tell an improvement from noise. Non-determinism comes from unseeded RNGs, set iteration order, unordered event streams, wall-clock reads, and floating-point accumulation order.

What This Can and Cannot Guarantee

It cannot guarantee bit-identical results in general, and no tool can. PyTorch's reproducibility guidance states plainly that "completely reproducible results are not guaranteed across PyTorch releases, individual commits, or different platforms," and that results may differ between CPU and GPU "even when using identical seeds." The same holds for BLAS thread counts, SIMD code paths, and library versions.

Determinism is a property of a pinned environment — same platform, same library versions, same thread configuration. This skill does two things within that envelope:

  1. Eliminates the controllable sources: seeding, event ordering, clock reads.
  2. Detects divergence when it happens, by comparing exact float bits.

Point 2 is the part that must not be compromised. Earlier versions of this skill rounded every float to 6 decimals before hashing, which meant the canonical non-determinism signature — sum([0.1]*10) (0.9999999999999999) versus 0.1*10 (1.0) — was reported as bit-identical. A detector that cannot see the thing it was built to detect is worse than no detector, because it produces confident false assurance.

When NOT to Use

  • As a tamper-evident audit record. The checksum is an unkeyed SHA256: anyone can edit a trade log and recompute it. For an authenticated record see backtest-audit-trail-for-regulatory-review.
  • To compare runs across different environments. Differing Python/NumPy/BLAS versions or thread counts will legitimately diverge; that is an environment-pinning problem, not something a checksum can fix.
  • To validate strategy correctness. A perfectly reproducible backtest can be reproducibly wrong — see lookahead-bias-elimination.

Prerequisites

  • A master integer seed (e.g. 42).
  • PYTHONHASHSEED set in the environment before the interpreter starts.
  • Pinned library versions and a fixed thread configuration for any run you intend to compare.

Workflow

  1. Set PYTHONHASHSEED before launching Python. This is the trap that catches people: hash randomization is fixed at interpreter startup, so os.environ["PYTHONHASHSEED"] = "0" inside running code does nothing while looking like it works. Launch as PYTHONHASHSEED=0 python backtest.py. check_hash_seed() reports whether the current process is safe; it cannot fix it.
  2. Seed the RNGs — and know what seeding misses. apply_master_seeds() seeds random, NumPy's legacy global RandomState, and torch when present. NumPy documents np.random.seed as a legacy function and recommends a dedicated Generator; code calling np.random.default_rng() draws fresh OS entropy and stays non-deterministic no matter how often you seed the global. Use make_numpy_generator() and thread it through explicitly.
  3. Sort the event stream by (timestamp, symbol, sequence_id). All three keys are required — a missing timestamp is rejected rather than defaulted to 0.0, which would silently move that event to the front. Duplicate sort keys are also rejected: Python's sort is stable, so tied events would keep their input order and the result would depend on how the file happened to be read.
  4. Replace wall-clock reads with SimulatedClock. Inject it rather than monkey-patching time.time() — patching a global affects every library in the process, including ones whose correctness depends on real time. The clock refuses to move backwards, which surfaces an unsorted stream immediately.
  5. Checksum with exact float bits and compare runs. audit_reproducibility() reports is_bit_identical and, on failure, first_divergence_index so you can go straight to the offending trade instead of staring at two mismatched hex strings.

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

Common Pitfalls

  • Rounding before hashing. Any tolerance applied before comparison erases exactly the sub-ulp divergences that signal non-determinism. float_precision exists for callers who explicitly want tolerant comparison, and it logs a warning saying what it costs.
  • Setting PYTHONHASHSEED from inside Python. It has no effect. The assignment succeeds, the variable reads back correctly, and set iteration order stays random.
  • Assuming dicts and sets behave alike. Dicts have preserved insertion order since Python 3.7 and are deterministic. Sets are not — iterating a symbol universe as a set gives a different order per process. With PYTHONHASHSEED at 0, 1, and 2, {'AAPL','MSFT','GOOG','TSLA'} iterates in three different orders. Iterate a sorted list.
  • Seeding only the NumPy global. np.random.seed() does not affect any Generator created by default_rng().
  • NaN in a trade log. json.dumps renders every NaN as the same token, so two runs that both corrupted to NaN hash identically and are declared reproducible. Non-finite values are now rejected outright.
  • Unsigned notional mistaken for P&L. Summing quantity * price across a round trip gives gross turnover, not equity: BUY 100@150 then SELL 100@155 sums to 30,500 while the realized P&L is 500. Cash flow must carry the side's sign.
  • Monte Carlo without a fixed seed. Slippage or execution-timing perturbations reseeded per run make every comparison meaningless.
  • Treating a matching checksum as proof of correctness. It proves two runs agreed, nothing more.

Verification

  • Run python -m unittest discover -s skills/backtest-determinism-and-reproducibility/scripts — 40 tests, 100% pass rate.
  • The test that matters: feed sum([0.1]*10) and 0.1*10 as prices for otherwise identical runs and confirm is_bit_identical is False. Pre-2.0 this returned True.
  • Run a backtest twice with identical inputs and confirm matching checksums; change the master seed and confirm the checksum shifts.
  • Confirm a missing timestamp or a duplicate (timestamp, symbol, sequence_id) raises DeterminismError rather than sorting silently.
  • Confirm SimulatedClock.advance_to() rejects a backwards jump.

Related Skills

  • walk-forward-validation-setup
  • monte-carlo-strategy-robustness-testing
  • vectorized-vs-event-driven-backtest-tradeoffs
  • backtest-audit-trail-for-regulatory-review — for an authenticated audit record, which this skill's unkeyed checksum is not
  • reproducible-ml-training-pipelines — the same problem for model training
  • dependency-pinning-and-reproducible-builds — pinning the environment determinism depends on

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 Backtest Determinism And Reproducibility?

Gebruik dit wanneer identieke backtestcode en -gegevens bij verschillende runs andere P&L- of Sharpe-waarden opleveren, waardoor optimalisatie onbetrouwbaar wordt: deterministische seeding, een strikte sorteervolgorde voor invoer, een gesimuleerde klok in plaats van uitlezingen van de systeemtijd en detectie van verschillen tussen runs.

Waarom Backtest Determinism And Reproducibility gebruiken in TypingMind?

Omdat je deze skill één keer installeert en met elk model kunt gebruiken. Backtest Determinism And Reproducibility 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 Backtest Determinism And Reproducibility in TypingMind?

Open Plug-ins → Skills → Installeren vanaf GitHub in TypingMind en plak https://github.com/HimanshuJ16/Algo-Trading-Skills/tree/main/skills/backtest-determinism-and-reproducibility. 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 Backtest Determinism And Reproducibility 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 Backtest Determinism And Reproducibility gebruiken?

Zoveel als je wilt. Je kunt Backtest Determinism And Reproducibility 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 Backtest Determinism And Reproducibility 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 👇