quantlab.backtest.base.SimulationResult#

class quantlab.backtest.base.SimulationResult(value, returns, orders, settlements, bar_interval, trades=None, native=None, rejected_orders=<factory>, max_target_deviation=None, attribution=None, factor_attribution=None, holdings=None, rebalances=None)[source]#

Bases: object

Output of one engine simulation in engine-independent form.

value and returns are the portfolio value and per-bar returns on the timestamp dimension. orders is a dataset on an order dimension with the variables timestamp, symbol, size, price, fees and side. trades is a dataset on a trade dimension with symbol, entry_timestamp, exit_timestamp, pnl, return and status ("Open" or "Closed"), empty when nothing traded. settlements records delisted holdings turned into cash at their last valuation (symbol, axis_symbol, delisting_timestamp, settlement_timestamp, price). rejected_orders records orders that found no fill price, or no price to size them against (symbol, axis_symbol, signal_timestamp, fill_timestamp); the holding was kept. max_target_deviation is the largest absolute gap between a target weight and the weight held right after its fill bar, rejections, cash and fees included, with the weight valued at the prices the order was sized against (the fill prices, or the signal bar’s valuation prices for sizing_basis="valuation"); None when nothing rebalanced. native is the engine’s own result object and is read only by the engine that produced it. attribution is set by the backtester after a model run: universe_value and gross_value on timestamp and group_value on (group, timestamp), the curves behind the attribution metrics, in the run’s money (init_cash at the first bar); None for a run_weights() run. factor_attribution is set by the backtester when the config has a risk_model: quantlab.risk.attribution.factor_attribution’s per-bar dataset; None otherwise. holdings is each symbol’s holding after each bar, on (timestamp, symbol): the position’s value at the bar’s valuation price over the book’s value, cash included, as the fills left it (negative for a short, 0 where nothing is held); None from an engine that does not supply them. rebalances is the rebalance record of the weights simulated, set by the backtester: scheduled (the bars the rebalance schedule named) and decided (those the rule decided; a scheduled bar it held is not), booleans on timestamp. Turnover, the rebalance win rate and the attribution take the rebalances from it; None from a bare engine call.

Examples

>>> sim = result.simulation  # from ``BaseBacktester.run()``
>>> sim.value.dims, int(sim.value.values[0])
(('timestamp',), 1000000)
>>> list(sim.orders.data_vars)
['timestamp', 'symbol', 'size', 'price', 'fees', 'side']
>>> sim.bar_interval
np.timedelta64(86400000000000,'ns')