Each backtest is an experiment: record its parameters, the period tested, the data source and version, the fees, the date and the metrics obtained. Without that, you cannot repeat the same test or compare two versions honestly.
After the run, gather the essentials in a dictionary, for example res = {'periode': strat.p.periode, 'sharpe': strat.analyzers.sharpe.get_analysis()}, then write it with json.dump(res, f, indent=2). A text format such as JSON or CSV is easy to read back and compare.
With cerebro.optstrategy(MaStrat, periode=range(10, 21), stop=[1, 2]), Backtrader tests every combination: here 11 × 2 = 22 runs. Save them all, not only the best.
The log also serves validation: the more runs you have done, the more the best result may be due to chance. Keeping track of the number of runs lets you estimate this selection bias.
Examples
BETA-X (fictional market) : This chart is just one run among others: another period, other parameters or other fees would give another curve. Save each run so you can repeat and compare it.
April 2013: the Reinhart and Rogoff spreadsheet error : While trying to reproduce a widely cited economics study by Carmen Reinhart and Kenneth Rogoff (2010), student Thomas Herndon found in April 2013 that a spreadsheet error left several countries out of the calculation, noticeably changing one of the key figures. Without stored data and calculations, the error would not have been found.
Key terms
Experiment log
Record of every run with its settings and results
Reproducibility
Ability to repeat a run and get the same result
optstrategy
Cerebro method that tests several parameter combinations
Selection bias
Flattering result obtained by keeping the best of many runs