quantlab.execution.rules.replay#

quantlab.execution.rules.replay(weights, fill, valuation, delisted, settings=ExecutionSettings(sizing_basis='fill', fees=0.0, slippage=0.0), init_cash=1.0)[source]#

Replay weights decided on each bar and return the holdings after every bar.

Parameters:
weightsarray-like

Target weights on [T, S], row t decided at bar t; NaN keeps a holding.

fill, valuation, delistedarray-like

As for plan_orders, on [T, S].

settingsExecutionSettings

The sizing basis, fees and slippage.

init_cashfloat

The starting cash; the book starts with no shares.

Returns:
ExecutionReplay

Shares and cash after each bar’s orders, and the rejections and settlements.

Raises:
ValueError

As ExecutionBook.trade raises.

Examples

A 1% fee on a buy of the whole book: vectorbt cuts it so cost and fee are the cash.

>>> import numpy as np
>>> prices = np.array([[10.0], [10.0]])
>>> result = replay(
...     np.array([[1.0], [np.nan]]), prices, prices, np.zeros((2, 1), dtype=bool),
...     ExecutionSettings(fees=0.01),
... )
>>> round(float(result.shares[1, 0]), 10), float(result.cash[1])
(0.099009901, 0.0)