Class MovingAverage

java.lang.Object
com.wualabs.qtsurfer.engine.core.state.WindowSeriesStore
com.wualabs.qtsurfer.engine.indicators.statistics.MovingAverage
All Implemented Interfaces:
WindowSeries, WritableWindowSeries, Iterable<Double>

public final class MovingAverage extends WindowSeriesStore
MovingAverage
  • Constructor Details

    • MovingAverage

      public MovingAverage(int periods)
  • Method Details

    • update

      public void update(double value)
      Adds a value to the rolling window and updates the running sum. When the window is full, the oldest value is automatically evicted via onRollingWindow(double), which subtracts it from the sum.
      Parameters:
      value - the value to add
    • reset

      public void reset()
    • getAverage

      public double getAverage()
    • getAverageSample

      public double getAverageSample()
      Returns:
      See Also:
    • onRollingWindow

      protected void onRollingWindow(double firstValue)
      Called when the oldest value is evicted from the window. Subtracts it from the running sum for O(1) average computation instead of re-summing all values.
      Overrides:
      onRollingWindow in class WindowSeriesStore
      Parameters:
      firstValue -