# ewma

> Exponentially Weighted Moving Average

Latest version **2.0.1** (published 2017-09-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install ewma
pnpm add ewma
yarn add ewma
bun add ewma
```

## Health

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

Positive: has types package; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2017-09-08 |
| First published | 2017-09-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/ewma) |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | Steve Gury |
| Maintainers | retrohacker |
| Keywords | JS, math, statistics |

## Links

- npm: https://www.npmjs.com/package/ewma
- Repository: https://github.com/ReactiveSocket/ewma
- Homepage: https://github.com/ReactiveSocket/ewma#readme
- Issues: https://github.com/ReactiveSocket/ewma/issues
- npm.io page: https://npm.io/package/ewma

## Dependencies (1)

- [assert-plus](https://npm.io/package/assert-plus.md) ^1.0.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 2.0.1 (latest) — 2017-09-08
- 2.0.0 — 2017-09-06
- 1.0.0 — 2017-09-01

## README

[![NPM Version](https://img.shields.io/npm/v/ewma.svg)](https://npmjs.org/package/ewma)
[![Build Status](https://travis-ci.org/ReactiveSocket/ewma.svg?branch=master)](https://travis-ci.org/ReactiveSocket/ewma)

# EWMA

An exponential weighted moving average for Node.js and the browser!

```bash
npm install -g ewma
```

## Usage

Compute the exponential weighted moving average of a series of values.  The
time at which you insert the value into `Ewma` is used to compute a weight
(recent points are weighted higher).  The parameter for defining the
convergence speed (like most decay process) is the half-life.

e.g. with a half-life of 10 unit, if you insert 100 at t=0 and 200 at t=10 the
ewma will be equal to (200 - 100)/2 = 150 (half of the distance between the new
and the old value).

### `var ewma = new EWMA(halfLifeMs, initialValue, clock)`

* `halfLifeMs` - `{Number}` parameter representing the speed of convergence
* `initialValue` - `{Number}` initial value
* `clock` - Optional `{Number}` clock object used to read time, must support
            `Date.now()` style method. Defaults to `Date`.

returns an object computing the ewma average

### `ewma.insert(x)`

* `x` - The next value, `ewma` will automatically compute the EWMA based on the
        clock difference between this value and the last time `insert` was
        called

### `ewma.reset(x)`

* `x` - Set the EWMA to exactly `x`.

### `ewma.value()`

Returns the current EWMA value.

## Examples

These are generated using a 500ms interval with a half life indicated in the
key. For the source code, or to reproduce yourself, check the
[Example](./example) directory.

![](./example/abs.png)
![](./example/sin.png)
![](./example/sawtooth.png)

## Contributions
Contributions welcome, please ensure `make` runs clean.

## License
MIT

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