From 2e94cb312aef7d0b2f6b94c3f667c6ec7537997f Mon Sep 17 00:00:00 2001 From: John Benediktsson Date: Wed, 1 May 2013 21:24:09 -0700 Subject: [PATCH] math.finance: adding performance. --- extra/math/finance/finance-tests.factor | 4 ++++ extra/math/finance/finance.factor | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/extra/math/finance/finance-tests.factor b/extra/math/finance/finance-tests.factor index 0d14bcb6d3..f3fdede18e 100644 --- a/extra/math/finance/finance-tests.factor +++ b/extra/math/finance/finance-tests.factor @@ -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 diff --git a/extra/math/finance/finance.factor b/extra/math/finance/finance.factor index 9ab1d41619..90efa15df5 100644 --- a/extra/math/finance/finance.factor +++ b/extra/math/finance/finance.factor @@ -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