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:
objectOutput of one engine simulation in engine-independent form.
valueandreturnsare the portfolio value and per-bar returns on thetimestampdimension.ordersis a dataset on anorderdimension with the variablestimestamp,symbol,size,price,feesandside.tradesis a dataset on atradedimension withsymbol,entry_timestamp,exit_timestamp,pnl,returnandstatus("Open"or"Closed"), empty when nothing traded.settlementsrecords delisted holdings turned into cash at their last valuation (symbol,axis_symbol,delisting_timestamp,settlement_timestamp,price).rejected_ordersrecords 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_deviationis 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 forsizing_basis="valuation");Nonewhen nothing rebalanced.nativeis the engine’s own result object and is read only by the engine that produced it.attributionis set by the backtester after a model run:universe_valueandgross_valueontimestampandgroup_valueon(group, timestamp), the curves behind theattributionmetrics, in the run’s money (init_cashat the first bar);Nonefor arun_weights()run.factor_attributionis set by the backtester when the config has arisk_model:quantlab.risk.attribution.factor_attribution’s per-bar dataset;Noneotherwise.holdingsis 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);Nonefrom an engine that does not supply them.rebalancesis the rebalance record of the weights simulated, set by the backtester:scheduled(the bars the rebalance schedule named) anddecided(those the rule decided; a scheduled bar it held is not), booleans ontimestamp. Turnover, the rebalance win rate and the attribution take the rebalances from it;Nonefrom 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')