PHP code example of dcvn / moving-average

1. Go to this page and download the library: Download dcvn/moving-average library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dcvn / moving-average example snippets



$array = $movingAverage->getCalculatedFromArray($sourceArray);

$generator = $movingAverage->generateFromArray($sourceArray);

$array = $movingAverage->getCalculatedFromGenerator($sourceGenerator);

$generator = $movingAverage->generateFromGenerator($sourceGenerator);

 $values = [0, 2, 4, 6, 8, 4, 6, 8, 12, 10, 6, 8, 10, 14, 8, 10];


$movingAverage = new MovingAverage();
$movingAverage->setPeriod(1);

$data = $movingAverage->getCalculatedFromArray($values);


$movingAverage = new MovingAverage();
$movingAverage->setPeriod(4);


$movingAverage = new MovingAverage(MovingAverage::WEIGHTED_ARITHMETIC);
$movingAverage->setPeriod(4)
    ->setWeights([2, 3, 5, 1]);


$movingAverage = new MovingAverage();
$movingAverage->setPeriod(5)
    ->setDelay(2);


$movingAverage = new MovingAverage(MovingAverage::WEIGHTED_ARITHMETIC);
$movingAverage->setPeriod(5)
    ->setDelay(2)
    ->setWeights([2, 4, 5, 3, 1]);