The idealized Kelly strategy is unrealistic largely because the bet size as a fixed fraction of capital must be allowed to become arbitrarily small. For this reason the strategy maximizes the expected logarithmic rate-of-growth and at the same time imposes a zero probability of ruin. In realistic gambling scenarios there is a minimum allowed bet size so the second property is not preserved.
Another beneficial property, in theory, is that the expected time to reach a specified goal is asymptotically less than any other strategy (including non-proportional strategies).
The fact that the strategy assumes no limit on the number of bets is unrealistic, of course, but only in the following sense. There can be runs of bad luck that drive capital close to zero and reversion of the running logarithmic rate-of-growth back to the expected rate may require an incredibly long time and an impractically large number of further bets.
Nevertheless, in a situation where a maximum number of bets $n$ is restricted, the same Kelly optimal fraction applies as long as the strategy is to bet a fixed fraction of wealth. Again, the optimal fraction maximizes the expected logarithm of terminal wealth (and the expected logarithmic rate-of-growth).
In your example, the outcome of each bet is a binary random variable $X_k$ where $P(X_k = 1) = p$ and $P(X_k = -1) = q= 1-p$. Given initial capital $W_0$ the capital after $n$ bets using a fixed betting fraction $f$ is
$$W_n = W_0(1 +f X_1)\cdots(1 + f X_n),$$
and so
$$\log \frac{W_n}{W_0} = \sum_{k=1}^n \log(1 + fX_k)$$
Since the random variables are identically distributed we have
$$\mathbb{E} \left(\log \frac{W_n}{W_0}\right) = n\left(p \log(1+f) + q\log(1-f) \right)$$
The optimal fraction $f^* \in [0,1]$ that maximizes this expectation (found by taking the derivative with respect to $f$ and equating to zero) is
$$f^* = p - q = 2p -1,$$
and this result holds for any choice of $n$.
The probability of ruin is still zero since the worst-case scenario of $n$ repeated losses results in
$$\tag{*}W_n = W_0 (1-f^*)^n = W_0 2^n(1-p)^n > 0$$
However, with a small number of bets, the variance of potential outcomes — with the worst case (*) — may be very unappealing. The desirable asymptotic properties of the Kelly strategy may never be seen. For example, one may run out of bets while still in a deep drawdown.
It may be preferable to apply a strategy for achieving some goal, e.g., increasing capital by $25 \%$ while minimizing the variance of outcomes or the probability of ruin.
If the odds are unfavorable ($p < 1/2$) then the strategy that minimizes the probability of ruin with a goal of doubling the capital is to bet everything at once. Gambling with smaller bets allows play to continue longer (a possible objective) but in the face of unfavorable odds the probability of ruin increases. Of course, casino owners like this phenomenon.
For more see Gambler's ruin.
You have an error in your code.
The logarithmic growth rate for $k$ bets with optimal fraction $\ell^*$ is
$$B=\frac{1}{k}\log\left(\frac{W_k}{W_0}\right) = \frac{1}{k} \sum_{j=1}^k\log(1+ \ell^*X_j),$$
where $X_1,X_2, \ldots$ are independent and identically distributed Bernoulli random variables with $P(X_j = 1) = p = 0.55$ and $P(X_j = -1) = q=1-p = 0.45$.
The expected growth rate is
$$E(B) = \frac{1}{k} \sum_{j=1}^k E[ \log(1+\ell^* X_j)] = E[\log(1+ \ell^*X_1)] = p\log(1 + \ell^*) + q\log(1 - \ell^*)$$
Note that the expected growth rate does not depend on $k$.
The variance of the growth rate is
$$var(B) = E(B^2) - [E(B)]^2 = p[\log(1+\ell^*)]^2+ q[\log(1-\ell^*)]^2 - [p\log(1+\ell^*) + q\log(1- \ell^*)]^2$$
For the given parameters we have
$$E(B) \approx0.005008,\,\,\,\, \sqrt{var(B)} \approx0.099832 $$
Your simulation generates a sequence of $k$ bets, computes the growth rate for the sequence and then repeats the process $n$ times. In the end, you compute the average of the growth rates for each sequence. Since the expected growth rate is independent of the length of the sequence you are effectively sampling the random variable $\log(1+\ell^*X_1)$ a total of $n \cdot k = 20,000,000$ times and computing the mean. The standard error of the estimate should be
$$SE = \frac{\sqrt{var(B)}}{\sqrt{nk}} \approx 0.000022$$
In fact, as $k$ is increased the distribution of $k$-bet growth rates approaches a normal distribution asymptotically by the central limit theorem.
This suggests that in many repetitions of the simulation the estimate of the expected value should be roughly $0.005008 \pm 2.32 * 0.000022 = 0.005008 \pm 0.000052$ with $99 \%$ confidence.
I ran the simulation myself and obtained estimates consistently close to $0.005$ using different random number seeds with only $100000$ simulation paths.
Best Answer
I believe an easy way to understand the Kelly's criterion is the following:
Think about the following growth process: you have a discrete-time process where in each step you invest and amount/proportion $f$ of your current capital, and you start with an amount of cash equal to $W_0$. Each time-step, if you win, your wealth will increase by the product $(1-f)+f(1+b) = (1+fb)$ with $b>0$ being equal to the return rate each time you win, and conversely, if you loose at the actual stage your wealth will decrease by the product $(1-f)+f(1-a)=(1-fa)$ with $a>0$ being equal to the return rate reduction each time you loose (so, if my return is $-6\%$ the reduction in my wealth is going to be given by the product $(1-f\cdot 6\%)$). All of these, assuming that your probability of winning or loosing at each stage are independent, lets say, you could be winning at each stage with probability $p$ or loosing with probability $q = 1-p$.
With these, note that the order of winning and looses don't matter, so my current wealth at any stage $t=T$ will be given by the number of winning $N$ and the number of looses $M$ (where $N+M = T$): $$ \begin{array}{r c l} W_t & = & W_0 \cdot (1+fb) \cdot (1+fb) \cdot (1-fa) \cdots (1-fa) \cdot (1+fb) \\ & = & W_0\cdot(1+fb)^N \cdot (1-fa)^M \end{array}$$
Now, let try to calculate the equivalent Compound Growth rate $\tau$ for the process at stage $T$ $$\begin{array}{rcl} (1+\tau)^T & = & (1+fb)^N \cdot (1-fa)^M \\ & = & \left( (1+fb)^\frac{N}{T} \cdot (1-fa)^\frac{M}{T}\right)^T \\ & = & \left( (1+fb)^\frac{N}{N+M} \cdot (1-fa)^\frac{M}{N+M}\right)^T \\ & \overset{\text{behave as when}\,T\to\infty}{\approx} & \left( (1+fb)^p \cdot (1-fa)^q\right)^T \\ \end{array}$$ so if you think as the time-expected-average path of the process could be defined as $\left< W_t \right>_t = W_0 \cdot (1+\tau)^t$ you can now figure out the meaning of the proportion $1+\tau = (1+fb)^p \cdot (1-fa)^q$ which is maximized through the Kelly's proportion $f^* = \frac{pb-aq}{ab}$, and understanding also the relation of the exponents that will tend to be the winning/loosing probabilities at each stage.
I believe that John Larry Kelly Jr. made one of the most important discoveries in Information Theory through this, founding that exist an optimal investing proportion which make a random process to growth exponentially, and since it doesn´t arise directly from Markowitz Theory it could be saying that important improvements could be done to optimal portfolios theories (maybe, maximizing the mode instead of the mean, but it just speculation right now). An interesting review is given by Edward O. Thorp here.
Additional review:
Think about the required return at each stage (betting my whole wallet each time): if I am betting in the casino, at each bet I could loose the whole amount I am investing so $1-a=100\%$, so, if each bet gives a prize of $\nu = 1+b$, at each bet I will win or loose with an outcome given by the expected value $E_t = (\nu p -1\cdot(1-p)) > 1$ if I want to be making money in the long term, so it requires that $\nu > 2/p-1$ which is always $\nu >1$ and highly restrictive, as example, for $p=0.5$ you need a prize of at least a $\nu >3$ times your bet.
But now, thinking in investing, if I loose (go bankrupt), I still can sell my assets to pay the doubt and keep some of my money (if I was and responsible manager), so the loosing proportion $\eta = (1-a)$ will be less than one (different from making a bet), so now the outcome given by the expected value $E_t = \nu p -\eta(1-p) > 1$ if I want to be making money in the long term, so will require that $\nu > 1/p+\eta(1-p)/p$, which could be even $\nu < 1$ and having an $E_t > 1$ given some values from $\eta$, so is sensefull to be doing investing, and is also different from making bets.
Right now coming back to Kelly's, if I invest a proportion $f$ on each trial/stage, the expected outcome by stage will be $E_t = f(\nu p -\eta(1-p)) > 1$ to be winning in the long term, so it will require that $f<1/(p(b-a)+2p+a-1)$ so doing bets as martingales are actually bad strategies even if I have residual value in my investing.