# boxema

> Exponential Moving Average based on a box filter, matching numpy example EMA

Latest version **0.0.0** (published 2016-08-13) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.0 |
| Published | 2016-08-13 |
| First published | 2016-08-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | cjd |

## Links

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

## Dependencies (1)

- [linspace](https://npm.io/package/linspace.md) ~1.0.0

## Recent versions

- 0.0.0 (latest) — 2016-08-13

## README

# Box filter based Exponential Moving Average
This EMA is designed to be identical to the EMA given in http://matplotlib.org/examples/pylab_examples/finance_work2.html
however it is rolling (can be updated at any time). Because it is a rolling EMA, beware that the
first *n* results will be different from the python example. This is because the python example uses
result *n* + 1 for all results 0-*n* and since this algorithm is rolling, that is not possible.
Discard the first *n* results and all following result will be the same.

To use:

```javascript
const Ema = require('boxema');

// Create an EMA with period 8
const ema8 = Ema.create(8);

[1,3,5,7,9].forEach((x) => {
    console.log("EMA is now " + ema8.update(x));
});

console.log("it can also be used as a list converter:");
console.log([2,4,6,8].map(ema8));

console.log("you can get the last result using ema.get()");
console.log(ema8.get());
```


The python code on which this is based is as follows, note the commented line which is not possible
with a rolling EMA.

```python
def moving_average(x, n):
    weights = np.exp(np.linspace(-1., 0., n))
    weights /= weights.sum()
    a =  np.convolve(x, weights, mode='full')[:len(x)]
    #a[:n] = a[n]  ## This is not possible with a rolling EMA so it is removed.
    return a
```

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