Code:
double DLLPEXPORT KellyVector(
double *dProbs, // array of independent event probabilities (input not changed)
double *dOdds, // array of independent event odds (input not changed)
double *dKellyOutVector, // array of Kelly stakes (output)
long lEvents, // number of events (input not changed)
double dKellyMult, // Kelly multiplier > 0 (input not changed)
long lOddsType /* odds type (input not changed)
0 ==> all odds > 0 are decimal, all odds < 0 US
1 ==> all odds are US
2 ==> all odds < 0 or >=100 are US
*/
){
long i, j;
long lParlaySize, lParlayNum, lThisAND, lOutcomes, lBetIdx, lResIdx;
lOutcomes = 1<= 100)
dOdds[i] = g_US2DEC(dOdds[i]);
}
}
if(dOdds[i] == NULL) goto END;
dSingKellyV[i] = SBKelly(dProbs[i], dOdds[i], dKellyMult);
}
lMapV[lOutcomes-1] = 0;
lBetsPerSize[lEvents] = 1;
lCombins[lEvents] = lOutcomes-1;
for(i=1; i 1 || dWinProb < 0 || dKellyMult <= 0)
return NULL;
dWinQuant = dDecOdds - 1;
dKellyStake = (pow(dWinQuant * dWinProb, dKellyMult) - pow(1 - dWinProb, dKellyMult)) / (pow(dWinQuant * dWinProb, dKellyMult) + dWinQuant * pow(1 - dWinProb, dKellyMult));
return dKellyStake>0 ? dKellyStake : 0;
}
inline double DLLEXPORT g_US2DEC(double dUSOdds){
if(dUSOdds<0)
return 1-100/dUSOdds;
else if(dUSOdds>0)
return 1+dUSOdds/100;
else
return 1;
}
inline long perm(long n, long r){
long i;
long lAns = 1;
if (n < 0) n = 0;
if (r > n)
r = n;
else if (r < 1)
r = 1;
for(i = n; i > r; i--)
lAns *= i;
return lAns;
}
inline long DLLEXPORT combin(long n, long r){
if (n > r+r)
return perm(n,n-r)/perm(r,1);
else
return perm(n,r)/perm(n-r,1);
}