Expectation of integration Brownian motion at stopping time. Consider the problem:
Let $X_t = \mu t+ \sigma  B_t$ with $\mu, \sigma >0$ where $B_t$ is a standard BM. Fix $\beta>0$, let $\tau = \inf\{t: X_t = \beta\}$. Calculate $$\mathbb{E}\int_0^\tau(\beta - X_t)dt$$
Here's my thought: since $\beta - X_t$ is continuous,
$$\mathbb{E}\int_0^\tau(\beta - X_t)dt = \int_0^\tau\mathbb{E}(\beta - X_t)dt =\int_0^\tau(\beta - \mu t - \sigma\mathbb{E}(B_t))dt = \beta \tau - \frac{1}{2}\mu \tau^2$$
The problemis, I did not use the properties of the stopping time $\tau$. This makes me feel weird.
Can someone please let me know where I made a mistake?
 A: Way 1: begin with
$$\mathbb{E} \left [ \int_0^\tau \beta-X_t dt \right ] = \beta \mathbb{E}[\tau]-\frac{\mu}{2} \mathbb{E}[\tau^2]-\sigma \mathbb{E} \left [ \int_0^\tau B_t dt \right ]$$
assuming all these expectations are finite.
We want to simplify the last term. To do that, consider the differential of $Y_t=B_t^3/3$. It is
$$dY_t=B_t^2 dB_t + B_t dt$$
by the Ito formula. Thus
$$\mathbb{E} \left [ \int_0^\tau B_t dt \right ] = \mathbb{E}[Y_\tau]-\mathbb{E} \left [ \int_0^\tau B_t^2 dB_t \right ]$$
and the LHS is the thing we want to get. So we need to look at the two RHS terms. For the first one, by the definition of $\tau$:
$$Y_\tau=\frac{1}{3} \left ( \frac{\beta-\mu \tau}{\sigma} \right )^3.$$
The second term can be shown to be zero provided that we can provided that we can justify applying optional stopping to the martingale $\int_0^t B_t^2 dB_t$. So plugging everything in:
$$\mathbb{E} \left [ \int_0^\tau \beta-X_t dt \right ] = \beta \mathbb{E}[\tau] - \frac{\mu}{2} \mathbb{E}[\tau^2] - \frac{\sigma}{3} \mathbb{E} \left [ \left ( \frac{\beta-\mu \tau}{\sigma} \right )^3 \right ].$$
Thus you need the first three moments of $\tau$ and nothing else in order to finish the problem.
I think you can obtain the MGF of $\tau$ using another martingale technique, which allows you to finish the problem. However $\mathbb{E}[\tau]$ is more easily obtained as we will see below.
Way 2: begin with
$$\mathbb{E} \left [ \int_0^\tau \beta-X_t dt \right ] = \int_0^\infty \mathbb{E} \left [ \int_0^t \beta-X_s ds \mid \tau=t \right ] d\mathbb{P}(\tau=t).$$
Under these assumptions, $B_t$ goes from $0$ to $\frac{\beta-\mu t}{\sigma}$ in time $t$, and so its conditional expected value at time $s$ is $\frac{s}{t} \frac{\beta-\mu t}{\sigma}$ by the properties of the Brownian bridge. Therefore the conditional expected value of $X_s$ is $\mu s + \frac{s}{t}(\beta-\mu t)=\frac{s}{t} \beta$. Therefore
$$\mathbb{E} \left [ \int_0^\tau \beta-X_t dt \right ] = \int_0^\infty \int_0^t (1-s/t) \beta \, ds \, d \mathbb{P}(\tau=t) \\
= \int_0^\infty \frac{\beta}{2} t \, d \mathbb{P}(\tau=t) \\
= \frac{\beta}{2} \mathbb{E}[\tau].$$
I do know how to get the first moment off the top of my head: $\mathbb{E}[\tau]$ is $\lim_{a \to -\infty} u(a,0)$ where
$$\mu \partial_x u(a,x) + \frac{\sigma^2}{2} \partial^2_x u(a,x) = -1 \\
u(a,a)=0 \\
u(a,\beta)=0.$$
The intuition for the derivation of this equation is to write the equation $u(a,x)=h+\int_{\mathbb{R}} u(a,y) d\mathbb{P}(X_h=y \mid X_0=x)$ and then get an estimate of the integral for small $h$, then rearrange and send $h \to 0$.
Now for $\mu \neq 0$ we have
$$u(a,x)=c_1 + c_2 e^{-kx} - x/\mu$$
where $k=2\mu/\sigma^2$. So
$$c_1 + c_2 e^{-ka} = a/\mu \\
c_1 + c_2 e^{-k\beta} = \beta/\mu \\
u(a,0)=c_1+c_2.$$
If $\mu>0$ then we recover $\lim_{a \to -\infty} u(a,0)=\frac{\beta}{\mu}$. If $\mu<0$ then we recover $\lim_{a \to -\infty} u(a,0)=+\infty$.
In the $\mu=0$ case the situation is simpler:
$$u(a,x)=-\frac{1}{\sigma^2} (x-a)(x-\beta)$$
and so $\mathbb{E}[\tau]$ is again $+\infty$.
Thus we find that when $\mu>0$, the desired quantity is $\frac{\beta^2}{2\mu}$, and otherwise it is $+\infty$. Somewhat surprisingly, $\sigma$ does not enter this at all.
