# moving-average

> Exponential Moving Average

Latest version **1.0.1** (published 2021-03-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install moving-average
pnpm add moving-average
yarn add moving-average
bun add moving-average
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2021-03-09 |
| First published | 2013-03-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 62 |
| Author | Pedro Teixeira |
| Maintainers | pgte |
| Keywords | moving, average, average, statistics |

## Links

- npm: https://www.npmjs.com/package/moving-average
- Repository: https://github.com/pgte/moving-average
- Homepage: https://github.com/pgte/moving-average#readme
- Issues: https://github.com/pgte/moving-average/issues
- npm.io page: https://npm.io/package/moving-average

## Recent versions

- 1.0.1 (latest) — 2021-03-09
- 1.0.0 — 2017-10-10
- 0.2.0 — 2017-10-05
- 0.1.1 — 2016-02-15
- 0.1.0 — 2016-02-08
- 0.0.5 — 2014-05-02
- 0.0.4 — 2013-03-21
- 0.0.3 — 2013-03-21
- 0.0.2 — 2013-03-21
- 0.0.1 — 2013-03-21

## README

# moving-average

[![Build Status](https://travis-ci.org/pgte/moving-average.svg?branch=master)](https://travis-ci.org/pgte/moving-average)

Online calculation of Exponential Moving Average for Node.js.

Also suports Moving Variance, Moving Deviation and Forecast.

The [following](https://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average) online algorithm is implemented:

```
diff := x - mean
incr := alpha * diff
mean := mean + incr
variance := (1 - alpha) * (variance + diff * incr)
forecast := mean + alpha * diff
```

## Install

```bash
$ npm install moving-average
```

## Use

```javascript
var timeInterval = 5 * 60 * 1000; // 5 minutes

var MA = require('moving-average');
var ma = MA(timeInterval);

setInterval(function() {
  ma.push(Date.now(), Math.random() * 500);
  console.log('moving average now is', ma.movingAverage());
  console.log('moving variance now is', ma.variance());
  console.log('moving deviation now is', ma.deviation());
  console.log('forecast is', ma.forecast());
});
```

## License

MIT

---
_Source: https://npm.io/package/moving-average · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
