Class VarianceRTIndicator

All Implemented Interfaces:
ClockAware, Resettable, RTIndicator

public class VarianceRTIndicator extends AbstractDecorableIncrementalRTIndicator
Variance RTIndicator

In periodic mode, computes rolling variance in O(1) per tick using the algebraic identity Var(X) = E(X²) - E(X)², maintaining a running sum of squares with rolling eviction.

  • Constructor Details

    • VarianceRTIndicator

      public VarianceRTIndicator()
    • VarianceRTIndicator

      public VarianceRTIndicator(int periods)
    • VarianceRTIndicator

      public VarianceRTIndicator(RTIndicator indicator)
    • VarianceRTIndicator

      public VarianceRTIndicator(RTIndicator indicator, int periods)
  • Method Details

    • reset

      public void reset()
      Specified by:
      reset in interface Resettable
      Overrides:
      reset in class AbstractDecorableIncrementalRTIndicator
    • withAverageSample

      public VarianceRTIndicator withAverageSample(boolean averageSample)
    • tickValue

      protected double tickValue(int tick, boolean init, boolean endPeriod, double newValue)
      Periodic variance computation using O(1) incremental sum-of-squares tracking. Maintains a running sumSq = Σx² that is updated on each add and adjusted on window eviction. Variance is computed as Var = sumSq/n - mean² (population) or with Bessel's correction (sumSq - n×mean²)/(n-1) (sample). Returns 0 until the first complete period.
      Overrides:
      tickValue in class AbstractIncrementalRTIndicator
      Parameters:
      tick - current tick within the period
      init - true on the very first update
      endPeriod - true when this tick completes a period
      newValue - the new input value
      Returns:
      the computed variance, or 0 if insufficient data
    • nextValue

      protected double nextValue(double prevValue, double newValue)
      Non-periodic (2-period) variance: running average of squared deviations.
      Overrides:
      nextValue in class AbstractDecorableIncrementalRTIndicator
      Parameters:
      prevValue - the previous variance value
      newValue - the new input value
      Returns:
      the smoothed variance
    • getSma

      public SmaRTIndicator getSma()