]> gitweb.factorcode.org Git - factor.git/commitdiff
math.finance: adding performance.
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 2 May 2013 04:24:09 +0000 (21:24 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 2 May 2013 04:24:09 +0000 (21:24 -0700)
extra/math/finance/finance-tests.factor
extra/math/finance/finance.factor

index 0d14bcb6d39142d30294ac722c9e29d1e1fcf706..f3fdede18ed71207fb748d9edfa5a51e2c5fffb2 100644 (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
index 9ab1d416194a241b4db2f22dd8c885d1fcaceb58..90efa15df51b85d911484058fefd05f7f226a517 100644 (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