quantlab.backend.resample.resample_panel#
- quantlab.backend.resample.resample_panel(data, freq, how, labels, owner)[source]#
Return
dataaggregated ontofreqbars, one method per variable.datais not changed; the grouping runs in anXrBackendof its own.- Parameters:
- dataxr.Dataset
The panel on
(timestamp, symbol), on bars finer thanfreq.- freqstr
A
ResampleFrequencytoken.- howdict[str, str] or str
One method for every variable, or a
{variable: method}dict naming each ofdata’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
freqbars.
- Raises:
- ValueError
If
freqis not coarser thandata’s bars, orhowdoes not name exactlydata’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