2008-12-07 00:12:38 -05:00
|
|
|
! Copyright (C) 2008 John Benediktsson, Doug Coleman.
|
2008-11-07 01:36:02 -05:00
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
2008-09-24 15:24:01 -04:00
|
|
|
USING: arrays assocs kernel grouping sequences shuffle
|
|
|
|
math math.functions math.statistics math.vectors ;
|
2008-09-23 13:33:36 -04:00
|
|
|
IN: math.finance
|
|
|
|
|
2008-09-23 17:10:04 -04:00
|
|
|
<PRIVATE
|
|
|
|
|
2008-11-07 01:36:02 -05:00
|
|
|
: weighted ( x y a -- z )
|
2009-11-05 23:22:21 -05:00
|
|
|
[ * ] [ 1 - neg * ] bi-curry bi* + ;
|
2008-09-23 17:10:04 -04:00
|
|
|
|
2008-11-07 01:36:02 -05:00
|
|
|
: a ( n -- a )
|
2009-08-13 20:21:44 -04:00
|
|
|
1 + 2 swap / ;
|
2008-09-23 17:10:04 -04:00
|
|
|
|
|
|
|
PRIVATE>
|
2008-09-23 13:33:36 -04:00
|
|
|
|
|
|
|
: ema ( seq n -- newseq )
|
2008-11-08 15:30:28 -05:00
|
|
|
a swap unclip [ [ dup ] 2dip spin weighted ] accumulate 2nip ;
|
2008-09-23 13:33:36 -04:00
|
|
|
|
|
|
|
: sma ( seq n -- newseq )
|
|
|
|
clump [ mean ] map ;
|
|
|
|
|
|
|
|
: macd ( seq n1 n2 -- newseq )
|
2008-09-23 17:10:04 -04:00
|
|
|
rot dup ema [ swap ema ] dip v- ;
|
2008-09-23 13:33:36 -04:00
|
|
|
|
|
|
|
: momentum ( seq n -- newseq )
|
2008-11-07 01:36:02 -05:00
|
|
|
[ tail-slice ] 2keep [ dup length ] dip - head-slice v- ;
|
2008-09-23 13:33:36 -04:00
|
|
|
|
2008-12-07 00:05:02 -05:00
|
|
|
: monthly ( x -- y ) 12 / ; inline
|
|
|
|
|
|
|
|
: semimonthly ( x -- y ) 24 / ; inline
|
|
|
|
|
|
|
|
: biweekly ( x -- y ) 26 / ; inline
|
|
|
|
|
|
|
|
: weekly ( x -- y ) 52 / ; inline
|
|
|
|
|
|
|
|
: daily-360 ( x -- y ) 360 / ; inline
|
|
|
|
|
|
|
|
: daily-365 ( x -- y ) 365 / ; inline
|