Class ExponentialMovingAverage

  • All Implemented Interfaces:
    Average

    public class ExponentialMovingAverage
    extends java.lang.Object
    implements Average
    Implements an exponential moving average.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private double prevEMA  
      private float weight  
    • Constructor Summary

      Constructors 
      Constructor Description
      ExponentialMovingAverage​(float weight)
      Create a new exponential moving average, using the given smoothing rate weight.
      ExponentialMovingAverage​(int periods)
      Create a new exponential moving average which smooths over the given number of periods.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      double getAverage()
      Return average-so-far.
      void reset()
      sets back to start-of-day
      double update​(double newValue)
      Update average and return average-so-far.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • weight

        private final float weight
      • prevEMA

        private double prevEMA
    • Constructor Detail

      • ExponentialMovingAverage

        public ExponentialMovingAverage​(int periods)
        Create a new exponential moving average which smooths over the given number of periods.
      • ExponentialMovingAverage

        public ExponentialMovingAverage​(float weight)
        Create a new exponential moving average, using the given smoothing rate weight.
    • Method Detail

      • reset

        public void reset()
        Description copied from interface: Average
        sets back to start-of-day
        Specified by:
        reset in interface Average
      • update

        public double update​(double newValue)
        Update average and return average-so-far.
        Specified by:
        update in interface Average
      • getAverage

        public double getAverage()
        Return average-so-far.
        Specified by:
        getAverage in interface Average