I'm trying to chart the probability for absorption for a random walk starting at a reflective barrier. I'm using an equation from this paper:
And I'm messing it up somehow.
A quick word on the context: I play Hearthstone, the Warcraft-based collectible card game, and in its ranked mode, there is a rank floor you can't drop below (the reflective barrier), and 25 net wins above it you achieve the ultimate rank, Legend (the absorbing barrier).
A common criticism of streamers who reach Legend is that it was less about skill and more about just playing a lot, and that even with a sub-50% winrate you could reliably reach Legend if you played video games for a day job (you would inevitably reach Legend, of course, but I suspect not in the amount of games you could play before the monthly reset).
Anyway, I found the paper to model this exact scenario, and I'm building a widget that, for a given winrate, will show you the probability of reaching Legend after up-to-1200 games:
https://jsfiddle.net/fs3dovj5/
The problem is it seems to be going haywire:
Here's my javascript-ification of the equation, what am I doing wrong?
function absorptionProbability(t, i, p) {
var riemannSum = 0;
for (n = 0; n < i; n++) {
var phi = ((2 * n + 1) / (2 * b + 1)) * Math.PI;
riemannSum += Math.pow(-1, n) * Math.sin(phi) * Math.cos((b - i + 0.5) * phi) * Math.pow(1 - 4 * p * Math.pow(Math.sin(phi / 2), 2), t - 1);
}
probability = (4 * p / (2 * b + 1)) * riemannSum;
return probability;
}


