1 ! Copyright (C) 2008 John Benediktsson.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: arrays assocs kernel grouping sequences shuffle
4 math math.functions math.statistics math.vectors ;
9 : weighted ( x y a -- z )
10 tuck [ * ] [ 1- neg * ] 2bi* + ;
17 : ema ( seq n -- newseq )
18 a swap unclip [ [ dup ] 2dip spin weighted ] accumulate 2nip ;
20 : sma ( seq n -- newseq )
23 : macd ( seq n1 n2 -- newseq )
24 rot dup ema [ swap ema ] dip v- ;
26 : momentum ( seq n -- newseq )
27 [ tail-slice ] 2keep [ dup length ] dip - head-slice v- ;