quantlab.backend.resample.resample_panel#

quantlab.backend.resample.resample_panel(data, freq, how, labels, owner)[source]#

Return data aggregated onto freq bars, one method per variable.

data is not changed; the grouping runs in an XrBackend of its own.

Parameters:
dataxr.Dataset

The panel on (timestamp, symbol), on bars finer than freq.

freqstr

A ResampleFrequency token.

howdict[str, str] or str

One method for every variable, or a {variable: method} dict naming each of data’s variables (resolve_resample_how).

labelscallable

labels(timestamps, freq): the bar each timestamp belongs to, as the owner cuts bars (BaseDataset.resample_labels).

ownerstr

Class name quoted in log and error messages.

Returns:
xr.Dataset

The panel on freq bars.

Raises:
ValueError

If freq is not coarser than data’s bars, or how does not name exactly data’s variables.

Examples

Three days of hourly bars of one symbol, cut by the clock:

>>> from quantlab.utils.resample import clock_labels
>>> hours = pd.date_range("2024-01-01", periods=72, freq="h")
>>> hourly_bars = xr.Dataset(
...     {"close": (["timestamp", "symbol"], np.arange(72.0).reshape(72, 1))},
...     coords={"timestamp": hours, "symbol": ["A"]},
... )
>>> daily = resample_panel(hourly_bars, "1d", "last", clock_labels, "Demo")
>>> daily.sizes["timestamp"]
3