]> gitweb.factorcode.org Git - factor.git/commitdiff
math.extras: adding the Kelly criterion.
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 2 Apr 2015 04:34:54 +0000 (21:34 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 2 Apr 2015 04:34:54 +0000 (21:34 -0700)
extra/math/extras/extras-tests.factor
extra/math/extras/extras.factor

index 3f56fe2c2ed4780584d11a72e9fb07c6c5df8b92..6fc69a25f2a4a5a6f04c216f1fd86e37066bffbd 100644 (file)
@@ -157,3 +157,7 @@ IN: math.extras.test
 } [
     30 [1,b] [ mobius ] map
 ] unit-test
+
+{ 0.2 } [ 0.6 1 kelly ] unit-test
+{ 0.0 } [ 0.5 1 kelly ] unit-test
+{ -0.2 } [ 0.4 1 kelly ] unit-test
index 90d8d4f19fa4e7eb7cb820248fb030cb822953ac..1072b9801b000b83149b619fddad32cb521fcbf5 100644 (file)
@@ -322,3 +322,6 @@ M: iota-tuple sum-cubes sum sq ;
         dup [ 1 > ] any?
         [ drop 0 ] [ length even? 1 -1 ? ] if
     ] if-empty ;
+
+: kelly ( winning-probability odds -- fraction )
+    [ 1 + * 1 - ] [ / ] bi ;