$$\frac{dX_t}{X_t}=\alpha\frac{dS_t}{S_t}+(1-\alpha)\frac{dS^0_t}{S^0_t}$$
where $\alpha$ is proportion of the investment in the risky asset $S_t$ and $S^0_t$ is the risk-free asset. $S_t$ follows a geometric Brownian motion,
$$\begin{aligned} \frac{dS_t}{S_t} &= \mu{dt} + \sigma{dW_t} \\ \frac{dS^0_t}{S^0_t} &= r dt \end{aligned}$$
Substituting the equation, we get
$$\frac{dX_t}{X_t}=(\alpha\mu+(1-\alpha)r)dt+\alpha\sigma{dW_t}$$
Solving the following SDE yields
$$X_t = X_0 \exp\left(\left(\alpha\mu + (1-\alpha) r -\frac{(\alpha\mu)^2}{2}\right)t+\sigma{W_t}\right)$$
So we have to maximize $\alpha\mu+(1-\alpha)r-\frac{(\alpha\mu)^2}{2}$. Differentiating the above expression $\mu-r-\alpha\sigma^2$, so $\alpha=\frac{\mu-r}{\sigma^2}$. I think there might be an error in my derivation. I looked at this part and felt that something was off.
$$X_t = X_0 \exp\left(\left(\alpha\mu+(1-\alpha)r-\frac{(\alpha\mu)^2}{2}\right)t+\sigma{W_t}\right)$$
Did I derive the Kelly formula correctly?