RollingSum

Description

The RollingSum class computes the sum of values within a specified moving window over a sequence of data. This rolling sum provides a dynamic aggregate of values in the window as it moves across the data, enabling analysis of trends over localized segments.

Initial values: The constructor requires a positive integer window_size parameter to define the rolling window.
NaN handling: NaN values are not handled natively and should be preprocessed if necessary.

Usage Example and Plot

Implementation Details

Algorithm

RollingSum implements cyclic buffers to accumulate windowed statistics.

Complexity

  • Time Complexity: O(log(1)) per new element due to the insertion and deletion operations in the heaps.

  • Space Complexity: O(window_size), as only elements within the current window are stored.