Core#
Attribution Dashboard — Main orchestrator class.
Coordinates all dashboard components, layouts, callbacks, and visualizations. Follows the same pattern as kaxanuk.backtest_engine.dashboard.backtest_dashboard.
- class AttributionDashboard(attribution_results: AttributionResultDict, portfolio_name: str | None = None, benchmark_name: str | None = None, logo_path: str | None = None, days_of_smoothing: int = 45, date_column: str = 'date')[source]#
Bases:
objectInteractive Dash-based dashboard for attribution analysis.
Metrics are pre-calculated by the engine and passed in rather than computed inside the dashboard.
- Parameters:
attribution_results (AttributionResultDict) – Pre-calculated attribution results to display. Only
portfolio_returnsandsummary_statsare required; every factor-model-specific key (simulated_rets,portfolio_attribution_ts,pct_df_returns,total_pct_decomposition,cumulative_totals) is optional and, when absent, the corresponding chart/tab renders an “enable it in configuration” placeholder.portfolio_name (str or None, default None) – Display name of the portfolio, shown in the dashboard header.
benchmark_name (str or None, default None) – Display name of the benchmark.
logo_path (str or None, default None) – Path to a logo image file to embed in the dashboard header.
days_of_smoothing (int, default 45) – Number of days used for smoothing in relevant chart components.
date_column (str, default "date") – Name of the date column shared across the attribution result tables.
- Variables:
results (AttributionResultDict) – The raw attribution results passed to the constructor.
date_column (str) – Name of the date column shared across the attribution result tables.
portfolio_returns (pyarrow.Table) – Columns:
[date, portfolio_returns].simulated_rets (pyarrow.Table) – Columns:
[date, factor1, factor2, ...].portfolio_attribution_ts (pyarrow.Table) – Columns:
[date, factor1, factor2, ...].pct_df_returns (pyarrow.Table) – Columns:
[date, factor1, factor2, ...].total_pct_decomposition (dict) – Mapping of
{factor_name: contribution_fraction}.summary_stats (dict) – Mapping of
{metric_name: value}.brinson_fachler_indexes (pyarrow.Table or None) – Brinson-Fachler attribution index table, if computed.
cumulative_totals (pyarrow.Table or None) – The factor model’s cumulative portfolio / factor / idiosyncratic return, if computed (or derived from
simulated_rets); drives the headline attribution chart.portfolio_name (str or None) – Display name of the portfolio.
benchmark_name (str or None) – Display name of the benchmark.
logo_path (str or None) – Path to the logo image file, if any.
days_of_smoothing (int) – Number of days used for smoothing in relevant chart components.
app (dash.Dash) – The underlying Dash application instance.
- run_server(*, debug: bool = False, port: int = 8050, host: str = '127.0.0.1', **kwargs) None[source]#
Start the Dash development server.
- Parameters:
debug (bool, default False) – Whether to run the Dash app in debug mode. Debug mode serves the Werkzeug debugger: error pages show tracebacks with source code to anyone, and its console, which runs arbitrary code, is guarded only by a PIN. With a host that is not a loopback address a warning is logged.
port (int, default 8050) – Port on which to serve the dashboard.
host (str, default "127.0.0.1") – Interface the server binds to.
**kwargs – Passed through to
dash.Dash.run.
- class AttributionResultDict[source]#
Bases:
TypedDictPre-calculated attribution results consumed by
AttributionDashboard.- Variables:
portfolio_returns (pyarrow.Table) – Columns:
[date, portfolio_returns].simulated_rets (pyarrow.Table) – Columns:
[date, factor1, factor2, ...].portfolio_attribution_ts (pyarrow.Table) – Columns:
[date, factor1, factor2, ...].pct_df_returns (pyarrow.Table) – Columns:
[date, factor1, factor2, ...].total_pct_decomposition (dict) – Mapping of
{factor_name: contribution_fraction}.summary_stats (dict) – Mapping of
{metric_name: value}.brinson_fachler_indexes (pyarrow.Table or None) – Brinson-Fachler attribution index table, if computed.
cumulative_totals (pyarrow.Table or None) – Columns:
[date, portfolio_returns, factor_returns, idiosyncratic_returns]from the factor model, if computed, pluscarry_returns/dividends_returnswhen those return components were supplied (factor_returnsthen excludes them). When absent butsimulated_retsandportfolio_returnsare given, the dashboard derives it from them.linking (LinkingMethod or str) – Linking method
simulated_retswas built with; only read whencumulative_totalsis derived. Defaultcarino, the factor model’s default.portfolio_name (str) – Display name of the portfolio.
benchmark_name (str) – Display name of the benchmark.
- benchmark_name: str#
- brinson_fachler_indexes: Table | None#
- cumulative_totals: Table | None#
- linking: LinkingMethod | str#
- pct_df_returns: Table#
- portfolio_attribution_ts: Table#
- portfolio_name: str#
- portfolio_returns: Table#
- simulated_rets: Table#
- summary_stats: dict#
- total_pct_decomposition: dict#
- create_dashboard_from_attribution(attribution_results: AttributionResultDict, portfolio_name: str | None = None, benchmark_name: str | None = None, logo_path: str | None = None, days_of_smoothing: int = 45, date_column: str = 'date') AttributionDashboard[source]#
Create an
AttributionDashboardfrom pre-calculated results.- Parameters:
attribution_results (AttributionResultDict) – Pre-calculated attribution results to display.
portfolio_name (str or None, default None) – Display name of the portfolio, shown in the dashboard header.
benchmark_name (str or None, default None) – Display name of the benchmark.
logo_path (str or None, default None) – Path to a logo image file to embed in the dashboard header.
days_of_smoothing (int, default 45) – Number of days used for smoothing in relevant chart components.
date_column (str, default "date") – Name of the date column shared across the attribution result tables.
- Returns:
A dashboard instance configured with the given results and options, ready to be served with
AttributionDashboard.run_server().- Return type:
- create_dashboard_from_result(result: AttributionResult, portfolio_name: str | None = None, benchmark_name: str | None = None, logo_path: str | None = None, days_of_smoothing: int = 45, date_column: str = 'date') AttributionDashboard[source]#
Create an
AttributionDashboardfrom anAttributionResult.Maps the result’s tables to the dashboard keys, so callers holding a result never build an
AttributionResultDictby hand. When the factor model ran, its portfolio return feeds the header, metric cards and returns/drawdown tabs; otherwise the Brinson-Fachler per-period one does.- Parameters:
result (AttributionResult) – What
run_attribution(ormain) returned.portfolio_name (str or None, default None) – Display name of the portfolio, shown in the dashboard header.
benchmark_name (str or None, default None) – Display name of the benchmark.
logo_path (str or None, default None) – Path to a logo image file to embed in the dashboard header.
days_of_smoothing (int, default 45) – Number of days used for smoothing in relevant chart components.
date_column (str, default "date") – Name of the date column shared across the result tables.
- Returns:
A dashboard ready to be served with
AttributionDashboard.run_server().- Return type: