Class MovingAverage

  • All Implemented Interfaces:
    Average

    public class MovingAverage
    extends java.lang.Object
    implements Average
    Implements a basic moving average.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private double[] data  
      private int periods  
      private int pos  
      private double total  
    • Constructor Summary

      Constructors 
      Constructor Description
      MovingAverage​(int periods)
      Create a new moving average.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private double calculateAve()  
      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

      • periods

        private final int periods
      • data

        private double[] data
      • pos

        private int pos
      • total

        private double total
    • Constructor Detail

      • MovingAverage

        public MovingAverage​(int periods)
        Create a new moving average.
    • 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
      • calculateAve

        private double calculateAve()