Experiment¶
Defined in fynance.research
- class Experiment(name, spec=<factory>, code=None, seed=0, metrics=<factory>, series=None, created_at=<factory>, fynance_version=<factory>)[source]
Bases:
objectSerializable record of a single strategy experiment.
- Parameters:
- namestr
Short slug identifying the experiment (also the output sub-directory).
- specdict, optional
Everything needed to reproduce the run: strategy description, params, walk-forward config, cost config and the data spec (e.g.
{"kind": "synthetic-gbm", "seed": 7, "n": 1000}).- codestr, optional
The generated strategy source, stored verbatim for audit/reproduction.
- seedint
Master seed driving every stochastic step.
- metricsdict of str to float, optional
Summary metrics (
sharpe/sortino/…); empty until a run fills it.- seriesdict of str to list of float, optional
JSON-friendly curves (e.g.
equity/returns) for the report.- created_atstr
ISO-8601 UTC creation time (set automatically).
- fynance_versionstr
Version of fynance that produced the experiment (set automatically).
Examples
>>> from fynance.research import Experiment >>> e = Experiment(name="demo", seed=7, metrics={"sharpe": 1.5}) >>> e2 = Experiment.from_dict(e.to_dict()) >>> e2.name, e2.seed, e2.metrics["sharpe"] ('demo', 7, 1.5)
- classmethod from_dict(data)[source]
Rebuild an
Experimentfrom ato_dictmapping.
- classmethod load(path)[source]
Load an
Experimentfrom anexperiment.jsonfile.
- save(output_dir, *, name=None)[source]
Write
<output_dir>/<name>/experiment.jsonand return its path.Always writes under the caller-provided
output_dir— never inside the package. Parent directories are created as needed.- Parameters:
- output_dirstr or pathlib.Path
Base directory the artifact is written under.
- namestr, optional
Sub-directory name; defaults to
name.
- Returns:
- pathlib.Path
Path to the written
experiment.json.
- to_dict()[source]
Return a JSON-serializable dict of the experiment.