moving_average library
A class to calculate simple, weighted or exponential moving averages of lists of objects or numbers.
A simple moving average is the mean: mean(1, 2, 3) = (1 + 2 + 3) / 3 = 2.0
A weighted moving average is a weighted mean: weighted(2, 1, 4) = (12 + 21 + 3*4) / (1 + 2 + 3) = (2 + 2 + 12) / 6 = 2.66666
Calculate a simple moving average on a list of numbers with:
final simpleMovingAverage = MovingAverage<num>(
averageType: AverageType.simple,
windowSize: 3,
getValue: (num n) => n,
add: (List<num> data, num value) => value,
);
final result = simpleMovingAverage(input_data);
Calculate a weighted moving average for a list of Points with:
final weightedMovingAverage = MovingAverage<Point>(
averageType: AverageType.weighted,
windowSize: 2,
getValue: (Point p) => p.y,
add: (List<Point> data, num value) => Point(data.last.x, value),
);
final result = weightedMovingAverage(input_data);
Calculate an exponential moving average for a list of Points with:
final exponentialMovingAverage = MovingAverage<Point>(
averageType: AverageType.exponential,
factor: 0.1,
getValue: (Point p) => p.y,
add: (List<Point> data, num value) => Point(data.last.x, value),
);
final result = exponentialMovingAverage(input_data);
Classes
-
MovingAverage<
T> - A class to calculate simple, weighted or exponential moving averages of lists of objects.
Enums
- AverageType
- Spell out the types of moving average calculations available in this package.