quantlab.runs.factor_attribution_report.factor_attribution_section#

quantlab.runs.factor_attribution_report.factor_attribution_section(block, attribution, *, out_of_sample, bars_per_year=None, in_sample_range=None)[source]#

Return the Factor attribution section’s html: tiles, then return and risk side by side.

Parameters:
blockdict

The run’s factor_attribution metrics block (whole and, for a model run, in_sample and out_of_sample).

attributionxarray.Dataset

The run’s per-bar factor attribution (factor_attribution.zarr).

out_of_samplebool

Whether the run has an in-sample part, so the tiles and the charts summarize the out_of_sample segment rather than whole, as the page’s headline numbers do.

bars_per_yearfloat, optional

Bars in a year, to annualize the per-bar forecasts drawn over time; 252 when not given.

in_sample_rangetuple of str, optional

(first, last) bar labels of the in-sample part, shaded on the charts over time (which span the whole window).

Returns:
str

The section’s html: plotly fragments reusing the page’s plotly.js, the rest escaped; a note alone when the block has no segment or the store no bar.

Examples

>>> html = factor_attribution_section(block, attribution, out_of_sample=True)
>>> '"name":"return_by_part"' in html, '"name":"risk_by_part"' in html
(True, True)