Stochastic integration rules I stumbled upon a stochastic integration result in a book and I'm not sure how it is derived. It goes as follows: Suppose the process $Y^{(t,y)}$ has dynamics under the equivalent martingale measure $$dY^{(t,y)}(s)=Y^{(t,y)}(s)\big(-rds+\theta^2ds-\theta dW^Q(s)\big]$$ and $Y^{(t,y)}(t)=y$. Here $r$ is the spot interest rate, $W^Q$ is a brownian motion under $Q$ and $\theta$ is the market price of risk in the Black-Scholes model. Let $u$ be some smooth function, for which the following holds:
$$d\Big(e^{-\int_t^s r dz}u(s, \log Y^{(t,y)}(s))\Big)=-e^{-\int_t^s r ds}f(s, Y^{(t,y)}(s))ds-e^{-\int_t^s r ds}u_{\eta}(s, \log Y^{(t,y)}(s))\theta dW^Q(s),$$ where $u_{\eta}$ means differentiation wrt. the second variable and $f$ is a decreasing real function. We let $$\tau_n :=(T-\frac{1}{n})\vee \inf \{s\in[t,T]:|\log Y^{(t,y)}(s)|\geq n\}$$
Integrating and taking expectations we supposedly obtain $$u(t, \log y)=\mathbb{E}^Q \int_t^{\tau_n}e^{-\int_t^s r dz}f(s, Y^{(t,y)}(s))ds+\mathbb{E}^Q e^{-\int_t^{\tau_n} r dz}u(\tau_n,\log Y^{(t,y)}(\tau_n))$$
How do we arrive at this result? There are no further comments in the text. Any ideas?
Thanks
 A: I will simplify the notation a bit, but the steps you mention are the only things we need to do: 
1) Integrate - This means only not to write it in differential form. (Remember that the differential form is just a convenient way to rewrite an equation involving integrals).
2) Take unconditional expectations and analize each term. 
Start by "integrating" (rewriting). 
Remember what the ITO formula means in terms of differentials: 
If $(X^1, \cdots, X^d)$ is a $d$-dimensional vector semi-martingale, let $F \in \mathbf{C}^2(\mathbb{R}^d, \mathbb{R}) $ then 
$$ F(X_t) - F(X_0) = \sum_{i=1}^d \int_{0}^t \frac{\partial}{\partial x_i} F(X_s) dX_s^i + \frac{1}{2} \sum_{i,j} \int_0^t \frac{\partial^2 } {\partial x_i \partial x_j} F(X_s) d \langle X^i, X^j \rangle_s $$ 
But for convenience we write this in differential form as: 
$$ dF(X_s) = \sum_{i}^n \partial_i F(X_s) dX_s^i + \frac{1}{2} \sum_{i,j} \partial_{i,j}^2 F(X_s)dX_s^i dX_s^j $$
So for the first step we just rewrite your sde in terms of integrals from $t$ to $\tau_n$. (There are some technicallities as $\tau_n$ is a stopping time and so I will give you the rough intuitive ideas)
$$ e^{-\int_t^t rdz} u(t, \log(Y(t))) - e^{-\int_t^{\tau_n} rdz} u(\tau_n, \log(Y(\tau_n)) = \\ - \int_{\tau_n}^t e^{-\int_t^{s} rdz} u_{\eta}(s,\log(Y(s)) \theta dW_s - \int_{\tau_n}^t e^{-\int_t^s rdz} f(s,Y(s))ds $$
Repeating, the left hand-side of the equation corresponds to just evaluating the function at the times (with the stopping time details skipped) and the right hand-side is using the equation given by the problem. 
Now for step 2 take expectations on both side with respect to $\mathbf{Q}$, check out each term: 
$$ 1) \: \:  \mathbf{E}^Q \bigg[ e^{-\int_t^t rdz} u(t, \log(Y(t))) \bigg] = u(t, \log(Y(t)))  = u(t,\log(y)) $$ 
$$ 2) \: \: \: \: \mathbf{E}^Q \bigg[ e^{-\int_t^{\tau_n} rdz} u(\tau_n, \log(Y(\tau_n)) \bigg] \text{ nothing to simplify here. } $$
$$ 3) \: \: \:  \mathbf{E}^Q \bigg[ - \int_{\tau_n}^t e^{-\int_t^{s} rdz} u_{\eta}(s,\log(Y(s)) \theta dW_s  \bigg] = \mathbf{E}^Q \bigg[ - \int_{0}^t e^{-\int_t^{s} rdz} u_{\eta}(s,\log(Y(s)) \theta dW_s + \int_{0}^{\tau_n} e^{-\int_t^{s} rdz} u_{\eta}(s,\log(Y(s)) \theta dW_s  \bigg] =  0 \text{ expected value of integral with respect BM under } \mathbf{Q}  $$
$$ 4) \: \mathbf{E}^Q \bigg[ \int_{\tau_n}^t e^{-\int_t^s rdz} f(s,Y(s))ds \bigg] \text{ nothing to simplify here. } $$
But realize terms $ 1), 2) $ and $4)$ are exactly the ones on the result, so we are done. 
I hope I didn't make mistakes as I tried to do it quickly, let me know if there are. 
