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.

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

Remarks

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
User Contributed Notes
0 notes + add a note