MathPHP\Statistics\Average::exponentialMovingAverage PHP Метод

exponentialMovingAverage() публичный статический Метод

The start of the EPA is seeded with the first data point. Then each day after that: EMAtoday = α⋅xtoday + (1-α)EMAyesterday where α: coefficient that represents the degree of weighting decrease, a constant smoothing factor between 0 and 1.
public static exponentialMovingAverage ( array $numbers, integer $n ) : array
$numbers array
$n integer Length of the EPA
Результат array of exponential moving averages
    public static function exponentialMovingAverage(array $numbers, int $n) : array
    {
        $m = count($numbers);
        $α = 2 / ($n + 1);
        $EMA = [];
        // Start off by seeding with the first data point
        $EMA[] = $numbers[0];
        // Each day after: EMAtoday = α⋅xtoday + (1-α)EMAyesterday
        for ($i = 1; $i < $m; $i++) {
            $EMA[] = $α * $numbers[$i] + (1 - $α) * $EMA[$i - 1];
        }
        return $EMA;
    }