quantlab.tracking.base.flatten_metrics#
- quantlab.tracking.base.flatten_metrics(metrics)[source]#
Flatten nested metrics to
outer/innerkeys, keeping finite numbers only.Booleans, NaN, infinities, strings, timestamps and every other non-numeric leaf are dropped, so every tracker accepts the result. Integers stay integers and floats (numpy ones included) become
float.- Parameters:
- metricsMapping
Metric names to values or to further mappings.
- Returns:
- dict[str, int | float]
The finite numeric leaves, keyed by their path joined with
/.
Examples
>>> flatten_metrics({"whole": {"sharpe": 1.2, "worst": float("nan")}, "ic": 0.1, "note": "x"}) {'whole/sharpe': 1.2, 'ic': 0.1}