@Test public void testWeightedMovingAverage() { logger.info("weightedMovingAverage"); FlatDataList flatDataList = generateFlatDataList(); int N = 3; double expResult =22.0; double result = Smoothing.weightedMovingAverage(flatDataList, N); assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH); }
public static double weightedMovingAverage(FlatDataList flatDataList, int N) { double WMA=0; double denominator=0.0; int counter=0; for(int i=flatDataList.size()-1;i>=0;--i) { double Yti = flatDataList.getDouble(i); if(counter>=N) { break; } double weight=(N-counter); WMA+=weight*Yti; denominator+=weight; ++counter; } WMA/=denominator; return WMA; }
Smoothing { public static double weightedMovingAverage(FlatDataList flatDataList, int N) { double WMA=0; double denominator=0.0; int counter=0; for(int i=flatDataList.size()-1;i>=0;--i) { double Yti = flatDataList.getDouble(i); if(counter>=N) { break; } double weight=(N-counter); WMA+=weight*Yti; denominator+=weight; ++counter; } WMA/=denominator; return WMA; } }
Smoothing { public static double weightedMovingAverage(FlatDataList flatDataList, int N) { double WMA=0; double denominator=0.0; int counter=0; for(int i=flatDataList.size()-1;i>=0;--i) { double Yti = flatDataList.getDouble(i); if(counter>=N) { break; } double weight=(N-counter); WMA+=weight*Yti; denominator+=weight; ++counter; } WMA/=denominator; return WMA; }  }
Smoothing { public static double weightedMovingAverage(FlatDataList flatDataList, int N) { double WMA=0; double denominator=0.0; int counter=0; for(int i=flatDataList.size()-1;i>=0;--i) { double Yti = flatDataList.getDouble(i); if(counter>=N) { break; } double weight=(N-counter); WMA+=weight*Yti; denominator+=weight; ++counter; } WMA/=denominator; return WMA; }  static double simpleMovingAverage(FlatDataList flatDataList, int N); static double simpleMovingAverageQuick(double Yt, double YtminusN, double Ft, int N); static double weightedMovingAverage(FlatDataList flatDataList, int N); static double simpleExponentialSmoothing(FlatDataList flatDataList, double a); static double simpleExponentialSmoothingQuick(double Ytminus1, double Stminus1, double a); static double holtWintersSmoothing(FlatDataList flatDataList, int season_length, double alpha, double beta, double gamma, double dev_gamma); }
Smoothing { public static double weightedMovingAverage(FlatDataList flatDataList, int N) { double WMA=0; double denominator=0.0; int counter=0; for(int i=flatDataList.size()-1;i>=0;--i) { double Yti = flatDataList.getDouble(i); if(counter>=N) { break; } double weight=(N-counter); WMA+=weight*Yti; denominator+=weight; ++counter; } WMA/=denominator; return WMA; }  static double simpleMovingAverage(FlatDataList flatDataList, int N); static double simpleMovingAverageQuick(double Yt, double YtminusN, double Ft, int N); static double weightedMovingAverage(FlatDataList flatDataList, int N); static double simpleExponentialSmoothing(FlatDataList flatDataList, double a); static double simpleExponentialSmoothingQuick(double Ytminus1, double Stminus1, double a); static double holtWintersSmoothing(FlatDataList flatDataList, int season_length, double alpha, double beta, double gamma, double dev_gamma);  }