]> gitweb.factorcode.org Git - factor.git/blob - extra/math/finance/finance.factor
Merge branch 'master' into experimental
[factor.git] / extra / math / finance / finance.factor
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 ;
5 IN: math.finance
6
7 <PRIVATE
8
9 : weighted ( x y a -- z )
10     tuck [ * ] [ 1- neg * ] 2bi* + ;
11
12 : a ( n -- a )
13     1+ 2 swap / ;
14
15 PRIVATE>
16
17 : ema ( seq n -- newseq )
18     a swap unclip [ [ dup ] 2dip spin weighted ] accumulate 2nip ;
19
20 : sma ( seq n -- newseq )
21     clump [ mean ] map ;
22
23 : macd ( seq n1 n2 -- newseq )
24     rot dup ema [ swap ema ] dip v- ;
25
26 : momentum ( seq n -- newseq )
27     [ tail-slice ] 2keep [ dup length ] dip - head-slice v- ;
28