1 ! Copyright (C) 2008 John Benediktsson, Doug Coleman.
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- ;
29 : monthly ( x -- y ) 12 / ; inline
31 : semimonthly ( x -- y ) 24 / ; inline
33 : biweekly ( x -- y ) 26 / ; inline
35 : weekly ( x -- y ) 52 / ; inline
37 : daily-360 ( x -- y ) 360 / ; inline
39 : daily-365 ( x -- y ) 365 / ; inline