FRENESDE

Saving results

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

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
Take the mission on Doji Academy

← Back to the index