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 ; //possible numeric overflow denominator += weight ; ++ counter ; } WMA /= denominator ; return WMA ; }
Weighted Moving Average