avibryant/simmer — pull request #18 by alaiacano (2013-11-26 19:37:32+00:00)
Title: Exponential Moving Average

The parameter is the percent of the new value you want to keep: `average = percent * new + (1-percent) * old`. I was going to make the input be something like `ema0.5:x 1`, but it would take some work to parse a `Double`.

Example input:

```
ema50:x	1
ema50:x	2
ema50:x	3
ema50:x	4
ema50:x	5
ema50:x	6
ema50:x	7
ema50:x	6
ema50:x	5
ema50:x	4
ema50:x	3
ema50:x	2
ema50:x	1
```

Example output:

```
ema50:x	1.968994140625	1.968994140625
```

Here's how I'd calculate this in "normal" scala. Note that the first value has to go into the fold's init parameter.

```
scala> val x = Seq[Double](2,3,4,5,6,7,6,5,4,3,2,1)
x: Seq[Double] = List(2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 6.0, 5.0, 4.0, 3.0, 2.0, 1.0)

scala> x.foldLeft(1.0)(_*.5 + _*.5)
res1: Double = 1.968994140625
```