math.finance: adding performance.

db4
John Benediktsson 2013-05-01 21:24:09 -07:00
parent 842a69c099
commit 2e94cb312a
2 changed files with 9 additions and 2 deletions

View File

@ -18,4 +18,8 @@ IN: math.finance.tests
[ { 1 3 1 } ] [ { 1 3 2 6 3 } 2 momentum ] unit-test
{ { 0.0 50.0 25.0 75.0 100.0 125.0 -50.0 -75.0 -90.0 } } [
{ 1 1.5 1.25 1.75 2.0 2.25 0.5 0.25 0.1 } performance
] unit-test
[ 4+1/6 ] [ 100 semimonthly ] unit-test

View File

@ -1,7 +1,7 @@
! Copyright (C) 2008 John Benediktsson, Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays assocs kernel grouping sequences shuffle
math math.functions math.statistics math.vectors ;
USING: fry grouping kernel math math.statistics math.vectors
sequences ;
IN: math.finance
: sma ( seq n -- newseq )
@ -41,6 +41,9 @@ PRIVATE>
: momentum ( seq n -- newseq )
[ tail-slice ] 2keep [ dup length ] dip - head-slice v- ;
: performance ( seq -- newseq )
dup first '[ _ [ - ] [ /f ] bi 100 * ] map ;
: monthly ( x -- y ) 12 / ; inline
: semimonthly ( x -- y ) 24 / ; inline