Created
February 26, 2015 01:21
-
-
Save kungfuant/948a7e033405e601ecbc to your computer and use it in GitHub Desktop.
kelly criterion with more than two outcomes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var _ = require('lodash'); | |
var a = [0.2,0.1]; | |
var b = [10,30]; | |
var a0 = 1 - _.reduce(a, function(s, n) { return s + n; }); | |
function concave(x) { | |
var result = a0 * Math.log(1 - x); | |
for (var i = 0; i < a.length; ++i) | |
result += a[i] * Math.log(1 + b[i] * x); | |
return result; | |
} | |
function firstDerivative(x) { | |
var result = a0 / (x - 1); | |
for (var i = 0; i < a.length; ++i) | |
result += a[i] * b[i] / (1 + b[i] * x); | |
return result; | |
} | |
function sq(x) { return x * x; } | |
function secondDerivative(x) { | |
var result = - a0 / sq(x - 1); | |
for (var i = 0; i < a.length; ++i) | |
result -= a[i] * sq(b[i]) / sq(1 + b[i] * x); | |
return result; | |
} | |
function newton() { | |
var x = 0.5; | |
for (;;) { | |
var y = x - firstDerivative(x) / secondDerivative(x); | |
if (Math.abs(x - y) < 1e-8) | |
return y; | |
x = y; | |
} | |
} | |
console.log(a0); | |
console.log(a); | |
console.log(b); | |
console.log(newton()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment