Navigation :
expsmooth
expsmooth, function
def process expsmooth(src: number, factor: number; init: number): number
Returns an exponentially smoothed series over src using factor, with
initial value init. Use it with a scan clause.
src: input series.
factor: smoothing factor between 0 and 1.
init: initial value for the state.
Examples
table T = extend.range(5)
T.X = T.N * 10
T.Smooth = expsmooth(T.X, 0.5; 0) scan T.N
show table "Exp smooth" with
T.N
T.X
T.Smooth
This produces the following table:
| N |
X |
Smooth |
| 1 |
10 |
5 |
| 2 |
20 |
12.5 |
| 3 |
30 |
21.25 |
| 4 |
40 |
30.625 |
| 5 |
50 |
40.3125 |
The expsmooth process could be manually re-implemented as:
def process expsmooth_bis(src: number, factor: number; init: number) default 0 with
keep prev = init
prev = factor * src + (1 - factor) * prev
return prev