resample

Defined in fynance.data

resample(ps, freq, agg='last')[source]

Downsample a series to a coarser frequency.

The series index must be a NumPy datetime64 array; polars’ group_by_dynamic resampling is defined only over a temporal axis. An integer or object-dtype (e.g. datetime.datetime) index is rejected with an explanatory ValueError rather than surfacing an opaque polars error.

polars only accepts datetime64 resolutions [D], [ms], [us] and [ns]. Any other resolution (the common [s], plus [h], [m], [W], [M], [Y]) is losslessly upcast to [us] before resampling, so it works instead of triggering an opaque polars error.

Parameters:
psPriceSeries

Series with a datetime64 index.

freqstr

Target polars frequency (e.g. "1w", "1mo").

agg{“last”, “mean”, “ohlc”}

Aggregation. ohlc returns a mapping with open/high/low/close.

Returns:
PriceSeries or dict of str to PriceSeries

The resampled series (or an open/high/low/close mapping for ohlc).

Raises:
ValueError

If the index is not a datetime64 array, or if agg is unknown.