quantlab.runs.backtest_stats.rebalance_fill_bars#
- quantlab.runs.backtest_stats.rebalance_fill_bars(rebalances, timestamps)[source]#
Return the fill bar of every decided rebalance: the bar after it on
timestamps.A weight decided at bar t fills at bar t + 1. A rebalance on the last bar, or off
timestamps, has no fill bar there and is left out.- Parameters:
- rebalancesarray_like of datetime64
The bars of the decided rebalances (the rebalance record’s
decidedbars).- timestampsarray_like of datetime64
The run’s bars, sorted.
- Returns:
- numpy.ndarray
The fill bars as
datetime64[ns], sorted and unique.
Examples
>>> bars = pd.bdate_range("2024-01-01", periods=4) >>> rebalance_fill_bars(bars[[0, 2, 3]].values, bars.values).astype(str).tolist() ['2024-01-02T00:00:00.000000000', '2024-01-04T00:00:00.000000000']