Source code for kaxanuk.attribution_analysis.output_handlers.output_handler_interface

"""
Abstract base class interface for writing the results of an attribution run.

This module defines the contract that every output handler implements, so the
attribution never depends on how or where its results are written (an Excel
report today; other formats can be added as handlers of their own).
"""

import abc
from pathlib import Path

from kaxanuk.attribution_analysis.entities.attribution_result import AttributionResult


[docs] class OutputHandlerInterface(metaclass=abc.ABCMeta): """ Abstract base class for output handlers. :func:`~kaxanuk.attribution_analysis.performance_attribution.main` passes the result of every run to its output handlers, in order, once the attribution is done and before it plots or serves the dashboard. A handler receives its destination and options when it is built, not from the run, so it writes a file-based result and an in-memory one (:func:`~kaxanuk.attribution_analysis.run_attribution_from_backtest`) alike. A handler only reads the result: it never changes a number. """
[docs] @abc.abstractmethod def output_result(self, *, result: AttributionResult) -> Path: """ Write `result` and return where it was written. Parameters ---------- result : AttributionResult The run's result; only read. Returns ------- Path The file (or directory) written. """