quantlab.backtest.approximate.ApproximateAccount#

class quantlab.backtest.approximate.ApproximateAccount(record, value_without_costs, weights, metrics, universe_value=None, benchmark_value=None)[source]#

Bases: object

The account an approximate backtest simulated: ApproximateBacktest.run’s result.

Attributes:
recordAccountRecord

The account record, as a backtest run’s (BaseBacktester.account): the value after each bar (1.0 at the first bar, init_cash 1.0) and its returns, one fill per symbol traded at each fill bar (its notional at the fill price, its share of the costs as fees) and the rebalance record. The approximate backtest settles, rejects and caps nothing, so settlements and rejected_orders are empty; it keeps no round trips, per-bar holdings or target deviation (trades, holdings and max_target_deviation are None).

value_without_costsxr.DataArray

The value of the same weights traded without costs.

weightsxr.Dataset

weight on (timestamp, symbol) over the window, NaN on every bar but the decided ones, and the rebalance record scheduled and decided on timestamp: what DecisionInputs.weights returns, so a backtest run takes it as it is (BaseBacktester.run_weights).

metricsdict

run_metrics of record: whole (opened by the return statistics of the window and Total Fees Paid) and execution, with a benchmark benchmark and relative; attribution (attribution_metrics of record, the universe ranked by the rule’s score label); iterations (the mean and max iterations of the solver per decision bar, 0 for a rule that does not iterate) and converged (whether every bar met the solver’s stopping rule). The approximate backtest has no training window, so no slice.

universe_valuexr.DataArray or None

The equal-weighted universe of the attribution, on timestamp, 1.0 at the first bar (a delisted symbol is not settled, as the approximate simulation settles none).

benchmark_valuexr.DataArray or None

The benchmark bought at the second bar’s fill price with all of 1.0 at the same cost and held, on timestamp; None without a benchmark_dataset.

Examples

>>> account = backtest.run(predictions, rule)
>>> float(account.value[0]), account.decided_weights.dims
(1.0, ('timestamp', 'symbol'))
>>> account.metrics["converged"], account.metrics["iterations"]
(True, {'mean': 0.0, 'max': 0})
>>> sorted(account.metrics["attribution"]["decomposition"])
['costs', 'selection', 'total']
property decided_weights#

The target weights at the decided bars, on (timestamp, symbol).

property returns#

Per-bar returns of value, 0.0 at the first bar.

property value#

The account’s value after each bar, on timestamp, 1.0 at the first bar.