Ledger

Defined in fynance.research

class Ledger(root)[source]

Bases: object

A persistent, append-only store of experiments under root.

Parameters:
rootstr or pathlib.Path

Directory the experiments live under (created on demand). Each experiment is stored at <root>/<name>/experiment.json.

Examples

>>> import tempfile
>>> from fynance.research import Experiment, Ledger
>>> d = tempfile.mkdtemp()
>>> led = Ledger(d)
>>> _ = led.append(Experiment(name="a", metrics={"sharpe": 1.0}))
>>> _ = led.append(Experiment(name="b", metrics={"sharpe": 2.0}))
>>> led.n_trials
2
>>> [r["name"] for r in led.leaderboard()]
['b', 'a']
append(experiment)[source]

Persist experiment under the ledger root; return its json path.

deflated_sharpe(experiment, metric='sharpe')[source]

Deflated Sharpe of experiment against the ledger’s trial count.

Uses the ledger’s n_trials as the number of trials and the dispersion of the stored Sharpe metrics as the trial variance, so a selected strategy is judged against the multiple testing it came from.

leaderboard(*, sort_by='sharpe', descending=True)[source]

Rank the stored experiments (see fynance.research.leaderboard).

load()[source]

Load every stored experiment (sorted by name for determinism).

property n_trials

Number of experiments in the ledger (the multiple-testing count).