Keep everything the result depended on: the exact data file, the strategy code at a commit, every setting including the random seed, and the engine and library versions. Store a hash of the result beside them. Months later, rerun from those and compare hashes: identical means reproduced, different means one of the inputs changed, and the stored copies say which.
What silently changes
- Data. Vendors revise history: late prints, corrected bars, new split and dividend adjustments every time a company pays one. Re-downloading "the same" data months later usually gives a slightly different file.
- Code. A small edit made for another experiment changes the strategy the old result came from.
- Settings. Costs, lookback, date range, seed. Defaults change between library versions.
- Libraries. pandas, NumPy and the backtester itself change rounding, resampling and fill rules between releases.
- Randomness. Any random slippage, spread or tick path that is not seeded gives a different result every run.
What to keep for each result
| Keep | How |
|---|---|
| Data | The file itself, or its SHA-256 and where it is archived |
| Code | Git commit hash, with a clean working tree |
| Settings | The full settings dictionary, seed included, as JSON |
| Versions | Engine, Python and library versions (pip freeze) |
| Result | The result file and its hash |
A result with all five can be rerun by anyone with the files. One without them can only be trusted.
How Reamer Research handles it
Reamer Research is deterministic: the same bars, settings and rng_seed give the same result, fill for fill, on every run. The result JSON records its own abi_version and schema_version. This script keeps a run's record beside it and checks a rerun against it:
import hashlib, json, subprocess
import reamer_research as rr
def sha(path):
return hashlib.sha256(open(path, 'rb').read()).hexdigest()
def run_hash(result):
return hashlib.sha256(json.dumps(result.json(), sort_keys=True).encode()).hexdigest()
class Breakout:
def __init__(self, n=20, qty=10):
self.n, self.qty, self.lookback = n, qty, n + 1
def on_bar(self, d):
if d.close[0] == 0:
return None
if d.position() == 0 and d.close[-1] > d.high[:-1].max():
return rr.buy_market(self.qty, stop_loss=d.low[:-1].min())
if d.position() > 0 and d.close[-1] < d.close[-5:].mean():
return rr.close_position()
DATA = 'data/SPY_5min.bin'
settings = dict(spread=0.01, slippage=0.005, price_volatility=0.1, rng_seed=42)
result = rr.backtest(Breakout(n=20), DATA, **settings)
record = {'data_sha256': sha(DATA), 'strategy': {'n': 20, 'qty': 10},
'settings': settings, 'engine': rr.__version__,
'commit': subprocess.run(['git', 'rev-parse', 'HEAD'], capture_output=True,
text=True).stdout.strip(),
'result_sha256': run_hash(result)}
json.dump(record, open('breakout.record.json', 'w'), indent=1)
# months later
old = json.load(open('breakout.record.json'))
assert sha(DATA) == old['data_sha256'], 'data file changed'
again = rr.backtest(Breakout(**old['strategy']), DATA, **old['settings'])
print('reproduced' if run_hash(again) == old['result_sha256'] else 'differs')
The settings include price_volatility, which makes the spread random, and the seed that fixes it: change the seed and the hash changes; keep it and the result is identical. The strategy is an object configured with its parameters, so the record holds them too. A plain function or a class with class attributes works the same way, with its parameters kept in code at the commit.
Limits to know
- Archiving the data is yours. The engine reads the files it is given; a
.binfile is a fixed snapshot, so keep the one each result ran on. - Keep the kit release with the record.
rr.__version__names it, and a later release can change fills where its changelog says so, so rerun an old record on the release it names. - Evaluation Mode runs 30 days or 50,000 bars of one ticker. Enough to set up the record and check a rerun.
A $20 month includes the full kit, so you can keep reproducible records of your own runs and cancel if it does not fit.