TimeFrame.rolling_aggregate¶
- TimeFrame.rolling_aggregate(window_size, aggregation_function, columns=None, missing_criteria=None, alignment=RollingAlignment.TRAILING, **kwargs)[source]¶
Apply a rolling aggregation function to this TimeFrame and return a new TimeFrame with the same temporal structure.
Unlike
aggregate(), which reduces the resolution of the data, rolling aggregation preserves the original timestamps: each row in the output corresponds to a row in the input, with the aggregation computed over a sliding window of the specified size.- Parameters:
window_size (
Period|str) – The size of the rolling window.aggregation_function (
Union[str,Type[AggregationFunction],AggregationFunction]) – The aggregation function to apply.columns (
str|list[str] |None) – The column(s) containing the data to be aggregated. If omitted, will use all data columns.missing_criteria (
tuple[str,float|int] |None) – How the aggregation handles missing data. When the actual number of values in a window is below the threshold the result is flagged as invalid via avalid_<column>column.alignment (
RollingAlignment|str) –Where the window is positioned relative to each timestamp:
TRAILING(default): window looks backward -(t - window_size, t]. Edge effects appear at the start of the series.LEADING: window looks forward -[t, t + window_size). Edge effects appear at the end of the series.CENTER: window is centered -[t - window_size/2, t + window_size/2]. Edge effects appear at both ends. Not supported for calendar-based window sizes.
Accepts a
RollingAlignmentinstance or a string ('trailing','leading','center').**kwargs – Parameters specific to the aggregation function.
- Return type:
Self- Returns:
A TimeFrame with the same resolution, periodicity, and time anchor as this TimeFrame, containing the rolling aggregation results.