Class RollingPercentileRTIndicator

java.lang.Object
com.wualabs.qtsurfer.engine.indicators.core.AbstractRTIndicator
com.wualabs.qtsurfer.engine.indicators.statistics.pro.RollingPercentileRTIndicator
All Implemented Interfaces:
Resettable, RTIndicator

public class RollingPercentileRTIndicator extends AbstractRTIndicator
Rolling Percentile with O(n) per-tick updates via sorted insertion.

Maintains a circular buffer (insertion order) and a parallel sorted array for O(1) percentile lookup. Each tick:

  1. Remove the evicted value from the sorted array (binary search + shift)
  2. Insert the new value into the sorted array (binary search + shift)
  3. Read the percentile at the interpolated index

Uses linear interpolation between adjacent ranks (same as Excel PERCENTILE.INC). The percentile parameter is in [0, 1]: 0.5 = median, 0.95 = 95th percentile.

Returns 0 until the window has at least 1 value.

  • Constructor Details

    • RollingPercentileRTIndicator

      public RollingPercentileRTIndicator(int periods, double percentile)
  • Method Details

    • getPeriods

      public int getPeriods()
    • isReady

      public boolean isReady()
      Description copied from interface: RTIndicator
      Returns whether this indicator has received enough data to produce meaningful values.

      During the warmup period, RTIndicator.getValue() may return 0 or a partial estimate that should not be used for trading decisions. Once this method returns true, the indicator's output is statistically valid.

      The default implementation returns true for backward compatibility. Indicators with warmup requirements should override this method.

      For composite indicators (e.g. Bollinger Bands, MACD), readiness is determined by the slowest internal component.

      Returns:
      true if the indicator has completed its warmup period
    • getPercentile

      public double getPercentile()
    • getMedian

      public double getMedian()
      Returns the median of the current window.
    • getMin

      public double getMin()
      Returns the minimum value in the current window.
    • getMax

      public double getMax()
      Returns the maximum value in the current window.
    • reset

      public void reset()
      Specified by:
      reset in interface Resettable
      Overrides:
      reset in class AbstractRTIndicator
    • update

      public double update(double value)
      Specified by:
      update in interface RTIndicator
      Overrides:
      update in class AbstractRTIndicator