RollingArgmax#

Description#

RollingArgmax returns the position (within the current window) of the rolling maximum value, rather than the maximum itself. Convention: 0 = oldest sample in the window, window_size−1 = newest. Matches numpy.argmax applied to the trailing window slice and pandas.Series.rolling(w).apply(np.argmax).

Parameters: window_size (int, positive).

NaN handling: NaN values should be preprocessed.

NaN handling#

Policy: ignore. A NaN in any input at index t causes the function to skip that step: output at t is NaN and internal state is unchanged. Subsequent finite samples are processed as if step t had not occurred.

Examples#

Usage example#

import numpy as np
from screamer import RollingArgmax, RollingMax

x = np.array([3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5], dtype=float)
RollingArgmax(5)(x)        # window offsets, 0 = oldest in window
RollingMax(5)(x)           # corresponding maxima

Implementation Details#

Algorithm#

Same monotonic-deque primitive (detail::MaxDeque) used by RollingMax, RollingMinMax, and RollingRange. Each deque entry stores (value, absolute_sample_index); the front entry is always the current rolling maximum, and we expose its window offset.

Complexity#

  • Time complexity: O(1) amortised per step.

  • Space complexity: O(window_size).

Reference#

Equivalent to pandas.Series.rolling(w).apply(np.argmax, raw=True) for samples after warmup. Also equivalent to TA-Lib's MAXINDEX.