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>
MovingAverage
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondoubledoubleprotected voidonRollingWindow(double firstValue) Called when the oldest value is evicted from the window.voidreset()voidupdate(double value) Adds a value to the rolling window and updates the running sum.Methods inherited from class WindowSeriesStore
add, clear, getValue, getWindowSize, isEmpty, iterator, sizeMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface Iterable
forEach, spliteratorMethods inherited from interface WritableWindowSeries
add
-
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 viaonRollingWindow(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:
onRollingWindowin classWindowSeriesStore- Parameters:
firstValue-
-