Quote:
Originally Posted by jokerjoe
Hi, I'm trying to understand how the calculator works for mutually exclusive events but can't work it out from the post linked (nor from the java, don't really know it unfortunately...).
Would be really grateful of an explanation!
|
This is the relevant function in the javascript
:
Code:
function calcMutExKelly(a_dEdge, a_dOdds, dKellyMult) {
var lSingles;
var a_sParlayNames;
var a_dRealKellyStakes;
if (dKellyMult == undefined || dKellyMult <= 0 || isNaN(dKellyMult)) dKellyMult = 1;
dKellyMult = parseFloat(dKellyMult);
if (!isArray(a_dEdge) || !isArray(a_dOdds) ) {
var err = "calcMutExKelly: Odds and Edge arguments must both be arrays";
alert(err);
return err;
}
lSingles = a_dOdds.length;
if(lSingles != a_dEdge.length) {
var err = "calcMutExKelly: Edge (size=" + a_dEdge.length + ") and odds (size=" + lSingles + ") arrays are different sizes";
alert(err);
return err;
}
a_dRealKellyStakes = new Array(Math.pow(2,lSingles)-1);
a_sParlayNames = new Array(Math.pow(2,lSingles)-1);
var oSortedByEdge = new Array(lSingles-1);
var dTotProb = 0;
for (var i=0; i<=lSingles-1;i++) {
var mydProb = edge2prob(a_dEdge[i], a_dOdds[i]);
dTotProb += mydProb ;
oSortedByEdge[i] = { n: i, dEdge: a_dEdge[i], dOdds: a_dOdds[i], dProb: mydProb};
}
if(dTotProb > 1 + 1e-6) {
var err = "calcMutExKelly: Sum of probabilities of mutually exclusive outcomes (" + dTotProb + ") may not be > 1";
alert(err);
return err;
}
var fnSortByEdge = function(a,b) { return(b.dEdge - a.dEdge); } ;
oSortedByEdge.sort(fnSortByEdge);
var dMinResult = 1, dOverround = 0, dSumProb = 0, dSumOddsRecip = 0;
for (var i = 0; i<=lSingles-1; i++) {
dSumProb += oSortedByEdge[i].dProb;
if ( dSumProb > 1 ) dSumProb = 1; // due to rounding error probability may erroneously be slightly > 1
dOverround += 1 / oSortedByEdge[i].dOdds;
var dProposedMinResult = (1-dSumProb) / (1-dOverround );
if (dProposedMinResult > 0 && dProposedMinResult < dMinResult) {
dMinResult = dProposedMinResult ;
}
}
for (var i = 0; i<=lSingles-1; i++) {
if (dOverround < 1 && dSumProb >= 1 - 1e-7 ) {
a_dRealKellyStakes[Math.pow(2,oSortedByEdge[i].n)] = oSortedByEdge[i].dProb;
} else {
a_dRealKellyStakes[Math.pow(2,oSortedByEdge[i].n)] = Math.max(0, oSortedByEdge[i].dProb - dMinResult / oSortedByEdge[i].dOdds);
}
a_sParlayNames[Math.pow(2,oSortedByEdge[i].n)] = ''+(1+oSortedByEdge[i].n);
}
g_arrStakes = a_dRealKellyStakes;
return {arrNames: a_sParlayNames, arrStakes: a_dRealKellyStakes};
}
With the long variable names it's pretty straightforward to the point of almost being pseudo code.
I highlighted in red the two loops that do the real "work".
What part exactly are you stuck on?