]> gitweb.factorcode.org Git - factor.git/blob - extra/math/finance/finance.factor
Delete empty unit tests files, remove 1- and 1+, reorder IN: lines in a lot of places...
[factor.git] / extra / math / finance / finance.factor
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 ;
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
29 : monthly ( x -- y ) 12 / ; inline
30
31 : semimonthly ( x -- y ) 24 / ; inline
32
33 : biweekly ( x -- y ) 26 / ; inline
34
35 : weekly ( x -- y ) 52 / ; inline
36
37 : daily-360 ( x -- y ) 360 / ; inline
38
39 : daily-365 ( x -- y ) 365 / ; inline