Paste: ema

Author: mrjbq7
Mode: factor
Date: Tue, 23 Sep 2008 18:52:33
Plain Text |
: ema ( seq n -- newseq )
    #! An exponentially-weighted moving average:
    #! A = 2.0 / (N + 1)
    #! EMA[t] = (A * VAL[t]) + ((1-A) * EMA[t-1])
    1+ 2.0 swap / dup 1 swap - swap rot
    [ [ dup ] dip * ] map swap drop 0 swap
    [ [ dup ] 2dip [ * ] dip + dup ] map 
    [ drop drop ] dip 1 tail-slice >array ;

New Annotation

Summary:
Author:
Mode:
Body: