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 class
AbstractMa.Mode
static class
AbstractMa.Type
-
Field Summary
Fields Modifier and Type Field Description protected double
lastSample
protected long
lastTimestamp
protected AbstractMa.Mode
mode
protected double
timeScale
protected AbstractMa.Type
type
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractMa()
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 double
getCurrent()
Gets the current value of the ema.double
getLastSample()
long
getLastTimestamp()
Gets the last time the ema was updated.double
getTimeScale()
void
processDouble(long timestamp, double data)
protected abstract void
processDoubleLocal(long timestamp, double data)
abstract void
reset()
abstract void
setCurrent(double value)
Sets the current value of the ema state.void
setTimeScale(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()
-