quantlab.tracking.base.TrackingRun#
- class quantlab.tracking.base.TrackingRun[source]#
Bases:
ABCOne record a tracker keeps: a training, a CV fold, a CV summary or a backtest.
Opened by
Tracker.start_runand finished when its block is left. The public methods normalise their arguments and hand them to one hook each, which an adapter implements.Examples
>>> with NullTracker().start_run(project="P", group=None, name="n", config={}) as run: ... run.log({"train_loss": 0.5}, step=0) ... run.summarize({"test": {"ic": 0.04}})
- log(metrics, step)[source]#
Record values against a step, drawn as curves.
- Parameters:
- metricsMapping[str, float]
Metric names to numbers; each is converted to
float.- stepint
The epoch or boosting round the values belong to.
Examples
>>> run = NullRun() >>> run.log({"train_loss": 0.5, "val_loss": 0.7}, step=3)
- log_file(path)[source]#
Attach a file to the run, such as a backtest’s HTML report.
- Parameters:
- pathstr or Path
The file to attach.
- Raises:
- FileNotFoundError
If
pathis not an existing file.
Examples
>>> import tempfile >>> report = Path(tempfile.mkdtemp()) / "notes.html" >>> _ = report.write_text("<p>report</p>") >>> NullRun().log_file(report)
- log_table(name, columns, rows, *, top_bars=None)[source]#
Record a table.
- Parameters:
- namestr
The table’s name in the run.
- columnsSequence[str]
Column names.
- rowsSequence[Sequence]
One sequence of cells per row, as many cells as
columns.- top_barsint, optional
Also draw a bar chart of the first
top_barsrows, labelled by the first column and sized by the second, where the tracker can draw one cheaply; a tracker that cannot ignores it.
- Raises:
- ValueError
If a row’s length differs from the number of columns, or
top_barsis given for fewer than two columns.
Examples
>>> run = NullRun() >>> run.log_table("importance/gain", ["factor", "importance"], [["mom", 0.6], ["rev", 0.4]])
- summarize(metrics)[source]#
Set the run’s final values, one per name.
Nested mappings are flattened to
outer/innerkeys and every non-finite or non-numeric leaf is dropped (flatten_metrics). Writing a name again replaces its value.- Parameters:
- metricsMapping
Metric names to numbers or to further mappings.
Examples
>>> run = NullRun() >>> run.summarize({"whole": {"sharpe": 1.2}, "test_ic": 0.04})