Gambler's ruin and martingale I don't understand 2 steps of the solution to a gambler's ruin exercise.
set-up for the gambler's ruin problem:

$(X_n)_{n\geq 1}$ are i.i.d. rv with $P(X_1=1)=1-P(X_1=-1)=p$ and $p\in (0,1),\ p\neq 1/2$. We have integers $0<a<b$, a sequence $S_0:=a$ with
$S_n:=S_{n-1}+X_n\quad n\geq 1$ and $\mathcal{F}_n=\sigma(X_1,\dots,X_n)$ and $T$ is the stopping time when either $S_n=0$ or $S_n=b$.

Exercises


*

*Deduce the value of $P(S_T=0)$ and $P(S_T=b)$


*Compute $E(T)$

I had to show that the following two are martingales, so this is known:
$$M_n:=\left(\frac{1-p}{p}\right)^{S_n}\qquad N_n:=S_n -n(2p-1)$$

The solutions says this:


*

*The stopped Martingales $M_T$ and $N_T$ are bounded, thus uniformely integrable with terminal value $M_T$ and $N_T$. As a consequence:
$$\left(\frac{1-p}{p}\right)^{a}=P(S_T=b)\left(\frac{1-p}{p}\right)^{b}+(1-P(S_T=b))\left(\frac{1-p}{p}\right)^{0}$$

I don't understand this equation. I understand that $E(M_T)=E(M_0)=\left(\frac{1-p}{p}\right)^{a}$ and it also makes sense that $S_T$ is either $b$ or $0$. But I don't understand why this $M_T$ is Bernoulli distributed with these parameters. Can someone explain?



*$E(N_T)=a$ that is $E(S_T)-(2p-1)E(T)=a$. We deduce:
$$E(T)=\frac{\left(\frac{\left(\frac{1-p}{p}\right)^{a}-1}{\left(\frac{1-p}{p}\right)^{b}-1}\right)b-a}{(2p-1)}$$

I don't see why $$E(S_T)=\left(\frac{\left(\frac{1-p}{p}\right)^{a}-1}{\left(\frac{1-p}{p}\right)^{b}-1}\right)b$$
 A: First, note that
$$
\mathbb E[M_T] = \mathbb E[M_T\mid S_T=0]\mathbb P(S_T=0) + \mathbb E[M_T\mid S_T=b]\mathbb P(S_T=b).
$$
Hence from $\mathbb E[M_T] = \left(\frac{1-p}p\right)^a$ we have
$$\left(\frac{1-p}p\right)^a = \left(\frac{1-p}p\right)^0\mathbb P(S_T=0) + \left(\frac{1-p}p\right)^b(1-\mathbb P(S_T=0)). $$
Solving for $\mathbb P(S_T=0)$ yields
$$\mathbb P(S_T=0) = \frac{\left(\frac{1-p}p\right)^a-\left(\frac{1-p}p\right)^b}{1-\left(\frac{1-p}p\right)^b}, $$
and hence
$$\mathbb P(S_T=b) = 1 - \mathbb P(S_T=0) = \frac{1-\left(\frac{1-p}p\right)^a}{1-\left(\frac{1-p}p\right)^b}. $$
From optional stopping it follows that  $\mathbb E[N_T]=\mathbb E[N_0]=a$ and hence
$$a = \mathbb E[S_T]- (2p-1)\mathbb E[T].$$
Solving for $\mathbb E[T]$ yields
$$\mathbb E[T] = \frac{\mathbb E[S_T]-a}{2p-1}, $$
and since we need not consider $\mathbb P(S_T=0)$ in computing the expectation, we conclude that
$$\mathbb E(T)=\frac{\left(\frac{1-\left(\frac{1-p}{p}\right)^{a}}{1-\left(\frac{1-p}{p}\right)^{b}}\right)b-a}{(2p-1)}.$$
