Nitpick: Kelly betting does not ever go bankrupt, at all. Unless the probability is exactly 1 or 0 (which is bad) the Kelly bet will always be less than the total amount of money you have right now—meaning that you can never lose all of your money on a Kelly bet.
That said, the code you linked is systematically losing money over time (though never actually hitting zero) because this line is backwards:
When dice < pwin, that should be a win (assuming that pwin is supposed to be the probability of winning), so the bet resolution should be positive in that case, not negative. With that fixed, wealth shoots up at a pretty quick exponential clip, eventually passes max double (~10^308) and becomes infinity, and then becomes NaN.
Nitpick: Kelly betting does not ever go bankrupt, at all. Unless the probability is exactly 1 or 0 (which is bad) the Kelly bet will always be less than the total amount of money you have right now—meaning that you can never lose all of your money on a Kelly bet.
That said, the code you linked is systematically losing money over time (though never actually hitting zero) because this line is backwards:
When dice < pwin, that should be a win (assuming that pwin is supposed to be the probability of winning), so the bet resolution should be positive in that case, not negative. With that fixed, wealth shoots up at a pretty quick exponential clip, eventually passes max double (~10^308) and becomes infinity, and then becomes NaN.
Oh darn, you’re right. Thank you!