Class AbstractMa
java.lang.Object
com.illumon.numerics.movingaverages.AbstractMa
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
Ema
public abstract class AbstractMa extends Object implements Serializable
Base class for computing moving averages.
- See Also:
- Serialized Form
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAbstractMa.Modestatic classAbstractMa.Type -
Field Summary
Fields Modifier and Type Field Description protected doublelastSampleprotected longlastTimestampprotected AbstractMa.Modemodeprotected doubletimeScaleprotected AbstractMa.Typetype -
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractMa()empty constructor needed for externalizableAbstractMa(AbstractMa.Type type, AbstractMa.Mode mode, double timeScale)Constructs a new MA which use the given timescale. -
Method Summary
Modifier and Type Method Description abstract doublegetCurrent()Gets the current value of the ema.doublegetLastSample()longgetLastTimestamp()Gets the last time the ema was updated.doublegetTimeScale()voidprocessDouble(long timestamp, double data)protected abstract voidprocessDoubleLocal(long timestamp, double data)abstract voidreset()abstract voidsetCurrent(double value)Sets the current value of the ema state.voidsetTimeScale(double timeScale)
-
Field Details
-
type
-
mode
-
timeScale
protected double timeScale -
lastTimestamp
protected long lastTimestamp -
lastSample
protected double lastSample
-
-
Constructor Details
-
AbstractMa
protected AbstractMa()empty constructor needed for externalizable -
AbstractMa
Constructs a new MA which use the given timescale.- Parameters:
type- type of EMAmode- compute the ema by tick or timetimeScale- timescale for the EMAs.
-
-
Method Details
-
processDouble
public void processDouble(long timestamp, double data) -
processDoubleLocal
protected abstract void processDoubleLocal(long timestamp, double data) -
getCurrent
public abstract double getCurrent()Gets the current value of the ema.- Returns:
- current value of the ema.
-
setCurrent
public abstract void setCurrent(double value)Sets the current value of the ema state.- Parameters:
value- new value of the ema state.
-
getTimeScale
public double getTimeScale() -
reset
public abstract void reset() -
setTimeScale
public void setTimeScale(double timeScale) -
getLastTimestamp
public long getLastTimestamp()Gets the last time the ema was updated.- Returns:
- last time the ema was updated.
-
getLastSample
public double getLastSample()
-