Class RollingPercentileRTIndicator
- All Implemented Interfaces:
Resettable, RTIndicator
Maintains a circular buffer (insertion order) and a parallel sorted array for O(1) percentile lookup. Each tick:
- Remove the evicted value from the sorted array (binary search + shift)
- Insert the new value into the sorted array (binary search + shift)
- 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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoublegetMax()Returns the maximum value in the current window.doubleReturns the median of the current window.doublegetMin()Returns the minimum value in the current window.doubleintbooleanisReady()Returns whether this indicator has received enough data to produce meaningful values.voidreset()doubleupdate(double value) Methods inherited from class AbstractRTIndicator
equals, getDisplayHint, getMeta, getValue, hashCode, hide, isPoison, setValue, toString, toString, withDisplayHint, withMeta
-
Constructor Details
-
RollingPercentileRTIndicator
public RollingPercentileRTIndicator(int periods, double percentile)
-
-
Method Details
-
getPeriods
public int getPeriods() -
isReady
public boolean isReady()Description copied from interface:RTIndicatorReturns 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 returnstrue, the indicator's output is statistically valid.The default implementation returns
truefor 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:
trueif 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:
resetin interfaceResettable- Overrides:
resetin classAbstractRTIndicator
-
update
public double update(double value) - Specified by:
updatein interfaceRTIndicator- Overrides:
updatein classAbstractRTIndicator
-