quantlab.backend.resample.resample_on_read#
- quantlab.backend.resample.resample_on_read(open_source, start, end, freq, how, labels, owner)[source]#
Return the source bars read and their resample, cut to
start..``end``.The source bars are opened from
resample_padding(freq)before the first instant of the range to that padding after its last, so every resampled bar inside the range is whole; they are aggregated byresample_paneland the result is cut to the range.- Parameters:
- open_sourcecallable
open_source(first, last): the source bars fromfirsttolast, both inclusive, already cut to the requested symbols (so only those are aggregated) and holding every variablehownames.- start, endstr, datetime.date or pd.Timestamp
The range requested, both inclusive; a date-only
endincludes every bar of that day.- freq, how, labels, owner
As for
resample_panel.
- Returns:
- sourcexr.Dataset
What
open_sourcereturned: the bars read, which the caller records.- panelxr.Dataset
The resampled bars from
starttoend.
- Raises:
- ValueError
As
resample_panelraises. The range is not checked here: the caller checks it first (check_range), naming its own method.
Examples
>>> 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"]}, ... ) >>> source, daily = resample_on_read( ... lambda a, b: hourly_bars.sel(timestamp=slice(a, b)), ... "2024-01-02", "2024-01-02", "1d", "last", clock_labels, "Demo", ... ) >>> daily["timestamp"].values.astype("datetime64[D]").tolist() [datetime.date(2024, 1, 2)]