Add a provenance manifest to every backtest
Motivation
Today a saved backtest captures what happened (orders, snapshots, metrics) but not enough about how it was produced to reliably reproduce it on another machine, or to detect when two saved backtests are actually the "same experiment".
This bites in three concrete places:
- Strategy code drifts → old backtests can't be re-run faithfully.
- Dependency drift → metrics differ subtly after a
pandas/polarsupgrade with no record of which version produced the original. - Sweeps with thousands of trials → no way to dedupe "same params + same data + same code" across machines.
Proposal
Add a provenance block, written into the backtest bundle / saved
directory at run completion. Suggested fields:
framework_version—investing_algorithm_framework.__version__python_version,platform,hostnamegit:commit_shaof the strategy repodirty(bool) — uncommitted changes presentbranch
code:- relative paths + content hashes of the strategy module(s) actually imported during the run
- optional inline source snapshot for small strategies (opt-in)
dependencies— slimpip freezelist (only top-level requirements, not the full transitive closure)seeds— every RNG seed the framework set (random,numpy,polars, strategy-supplied)data_provenance— exchange/source name, fetch timestamp, content hash of the OHLCV used (links to the dedup store from the bundle format issue)manifest_hash— stable hash of(parameters + data hash + code hash). Two backtests with the samemanifest_hashare guaranteed reproducible duplicates.
API
backtest.provenance # dict-like
backtest.manifest_hash # str
Index file (index.parquet from the bundle-format issue) gains a
manifest_hash column so dedup queries are O(N) over the index without
opening any bundles.
Out of scope
- Capturing the full transitive dependency closure — too noisy.
- Embedding the Python interpreter or virtualenv contents.
Related
Depends on the new bundle format (see "Speed up saving/loading large batches of backtests").
Solid framing. The four fields you're proposing (framework_version, git.commit_sha + dirty bit, code content hashes, dependency lock) are the load-bearing ones for backtest provenance. Two suggestions from work in the adjacent ML evaluation space:
-
Hash the whole provenance block, not just its contents. Your current proposal stores fields individually inside the bundle. If a future reader can reconstruct the canonical bytes of the provenance block, they can recompute a single SHA-256 digest that uniquely identifies the entire (code + deps + data) tuple. Two backtests with the same digest = same experiment by definition; deduplication becomes a single hash comparison instead of N field comparisons. The trick is committing to a canonicalization rule (key order, whitespace, integer/float typing) up front. Without that rule, two equivalent provenance blocks serialize differently.
-
Separate the data dependency from the code dependency. Your
codeblock captures strategy source. The implicit assumption is that the data is also pinned (file paths, snapshot dates). If the framework can additionally compute a content hash over the actual bytes the backtest consumed (resolved object list from the data source, hashed at run start), the provenance block becomes self-verifying. Anyone can re-resolve, re-hash, and prove (or disprove) byte equivalence later. This matters more than people expect in sweeps where data slowly drifts under a moving "as_of" pointer.
For prior art on the canonicalization-and-hash pattern specifically for evaluation claims (which is what backtests structurally are: performance metric claims), the spec we maintain at https://spec.falsify.dev/v0.1 commits exactly the (metric, comparator, threshold, dataset.hash, seed) tuple before the run. It's narrower than your proposal, since you correctly want git commit, deps, code, hostname, but the canonicalization rules in §3 might save some bike-shedding when you pick yours.
(Disclosure: I'm the spec author. Mentioning it because the canonicalization-byte-order problem is the part most people underestimate, not because the framework needs PRML.)