math.finance: adding performance.
parent
842a69c099
commit
2e94cb312a
|
@ -18,4 +18,8 @@ IN: math.finance.tests
|
||||||
|
|
||||||
[ { 1 3 1 } ] [ { 1 3 2 6 3 } 2 momentum ] unit-test
|
[ { 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
|
[ 4+1/6 ] [ 100 semimonthly ] unit-test
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
! Copyright (C) 2008 John Benediktsson, Doug Coleman.
|
! Copyright (C) 2008 John Benediktsson, Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: arrays assocs kernel grouping sequences shuffle
|
USING: fry grouping kernel math math.statistics math.vectors
|
||||||
math math.functions math.statistics math.vectors ;
|
sequences ;
|
||||||
IN: math.finance
|
IN: math.finance
|
||||||
|
|
||||||
: sma ( seq n -- newseq )
|
: sma ( seq n -- newseq )
|
||||||
|
@ -41,6 +41,9 @@ PRIVATE>
|
||||||
: momentum ( seq n -- newseq )
|
: momentum ( seq n -- newseq )
|
||||||
[ tail-slice ] 2keep [ dup length ] dip - head-slice v- ;
|
[ tail-slice ] 2keep [ dup length ] dip - head-slice v- ;
|
||||||
|
|
||||||
|
: performance ( seq -- newseq )
|
||||||
|
dup first '[ _ [ - ] [ /f ] bi 100 * ] map ;
|
||||||
|
|
||||||
: monthly ( x -- y ) 12 / ; inline
|
: monthly ( x -- y ) 12 / ; inline
|
||||||
|
|
||||||
: semimonthly ( x -- y ) 24 / ; inline
|
: semimonthly ( x -- y ) 24 / ; inline
|
||||||
|
|
Loading…
Reference in New Issue