quantlab.backend.resample#
Resample a panel, and resample on read: one copy for datasets and factors.
A resampled dataset or factor whose own <stem>_resample_<freq>.zarr store
has not been saved answers a request by resampling on read (ADR 0002): it
opens its source bars over the request widened by resample_padding(freq),
aggregates them onto freq bars and cuts the request’s window.
BaseDataset.panel and Factor.read both do it through
resample_on_read; each supplies only how it opens its source bars and how
it cuts bars (BaseDataset.resample_labels, which a factor takes from its
dataset). resample_panel is the aggregation alone, which a factor’s
compute and a dataset holding a panel use too. Two things stay the
caller’s: what a read records (the source bars, since the resampled panel is
computed, not stored) and the range check, whose message names its method.
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"]},
... )
>>> def open_source(start, end):
... return hourly_bars.sel(timestamp=slice(start, end))
>>> source, daily = resample_on_read(
... open_source, "2024-01-02", "2024-01-03", "1d", "last", clock_labels, "Demo"
... )
>>> daily.sizes["timestamp"], source.sizes["timestamp"] > daily.sizes["timestamp"]
(2, True)
Functions
Return the source bars read and their resample, cut to |
|
Return |