1 ! Copyright (C) 2008 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
4 USING: arrays assocs kernel grouping sequences shuffle
5 math math.functions math.statistics math.vectors ;
11 : weighted ( x y a -- z )
12 tuck [ * ] [ 1 swap - * ] 2bi* + ;
19 : ema ( seq n -- newseq )
20 a swap unclip [ [ dup ] 2dip swap rot weighted ] accumulate 2nip ;
22 : sma ( seq n -- newseq )
25 : macd ( seq n1 n2 -- newseq )
26 rot dup ema [ swap ema ] dip v- ;
28 : momentum ( seq n -- newseq )
29 2dup tail-slice -rot swap [ length ] keep
30 [ - neg ] dip swap head-slice v- ;