A quick check reveals that the probability of going bust after $1$ step is given by $C_0(1-p)$. Here $C_i$ is the $i$-th Catalan number. Going bust after $3$ steps is given by $C_1p(1-p)^2$ and $5$ steps is given by $C_2p^2(1-p)^3$, So we can see the pattern. So the answer for your question is the following sum: $$(1-p)\sum_{i=0}^{\infty}(2i+1)C_i(p(1-p))^i$$ Divided by the probability of ever going bust. Note that according to the point by Aaron Meyerowitz it is not guaranteed that we will ever go bust, so we need to divide our first weighted sum by the probability of ever going bust which is given by the following sum: $$(1-p)\sum_{i=0}^{\infty}C_i(p(1-p))^i$$ You can calculate the sumboth sums by using the well-known generating function for the Catalan numbers: $$c(x)=\sum_{i=0}^{\infty}C_ix^i=\frac{1-\sqrt{1-4x}}{2x}$$ Now if you look at $\frac{d (xc(x^2))}{dx}$ and then plug in $x=\sqrt{p(1-p)}$ and then multiply by $1-p$ you get the answer given by the series abovefirst sum. Doing so gives us the answer of $\frac{1-\sqrt{(1-2p)^2}}{2p\sqrt{(1-2p)^2}}$. Which if $p\geq 1/2$ gives $1/(1-2p)$ and if $p< 1/2$ it givesSimilarly for the second sum we just need to calculate $\frac{(1-p)}{p(2p-1)}$$(1-p)c(p(1-p))$. In your case thisThis is equal to $10$ as mentioned by$\frac{1-\sqrt{(2p-1)^2}}{2p}$. So the otherfinal answer. which is the ratio of these two numbers is going to be $\frac{1}{|1-2p|}$
We can verify this by a simple Monte-Carlo simulation as below:
from scipy.stats import bernoulli
p=0.45
tries=50000
steps_array=[]
def experiment(array):
steps=0
money=1
while money>0:
r = bernoulli.rvs(p, size=1)
if r==1:
money+=1
steps+=1
else:
money-=1
steps+=1
array.append(steps)
return
while tries>0:
experiment(steps_array)
tries-=1
print(sum(steps_array)/len(steps_array))
Doing so I got the answer 9.96044 which is pretty close to the answer calculated above.