quantlab.runs.backtest_attribution.attribution_metrics#
- quantlab.runs.backtest_attribution.attribution_metrics(account, *, fill, valuation, scores, groups=10, gross_value=None, benchmark=None, delisted=None)[source]#
Return an account’s
attributionblock and its curves.The universe of a rebalance bar (a decided bar of
account.rebalances) is every symbol with a finite score and a fill price on the next bar.rebalanced_group_valuesgives the equal-weighted universe curve and the curves ofgroupsscore groups;excess_decompositionsplits the annualised log growth over the benchmark (over the universe without one). A year isaccount.year_freqoveraccount.bar_interval, and the window counts one bar per return, asbacktest_stats.return_statsannualises.- Parameters:
- accountAccountRecord
What the account did; its bars are the panels’ bars.
- fill, valuationxr.DataArray
Fill and valuation prices on
(timestamp, symbol);fill’s symbols are the universe’s, the other panels are aligned to them and to the account’s bars.- scoresxr.DataArray
The score the rule ranks by on
(timestamp, symbol), named by its label; a symbol without one is never in the universe.- groupsint, default ATTRIBUTION_GROUPS
Score groups.
- gross_valuexr.DataArray, optional
The same weights simulated without costs, on the account’s bars; without it
costsis left out.- benchmarkBenchmarkRecord, optional
The benchmark on the account’s bars; its
value, or its returns compounded when it has none.- delistedxr.DataArray, optional
Booleans on
(timestamp, symbol)marking each delisted symbol’s last priced bar: the universe settles it as the engine does.
- Returns:
- blockdict
score_label,groups,decomposition,annualized_log_return(strategy,gross,universe,benchmark;Nonefor a curve not given),group_annualized_log_return(lowest scores first) andrelative_to_universe(backtest_stats.relative_statsof the account over the universe: what the scores and the rule add).- curvesxr.Dataset
universe_valueandgroup_value(ongroup, 1 the lowest) at the account’s first value, andgross_valuewhen given.
Examples
>>> block, curves = attribution_metrics( ... account, fill=prices["open"], valuation=prices["close"], scores=predictions["fwd_ret_1"] ... ) >>> sorted(block["decomposition"]) ['costs', 'selection', 'total']