# Ornstein–Uhlenbeck process – integration by parts

While deriving the solution for the stochastic differential equation that models the Ornstein–Uhlenbeck process, Paul Wilmott (Paul Wilmott on Quantitative Finance, chapter 4, page 87) performs the following integration by parts ($$X$$ is normal):

$$\int_0^t e^{\gamma(s-t)} \, dX(s) = X - \gamma \int_0^t e^{\gamma(s-t)}X(s) \, ds$$

I was trying to replicate this result by using the following result from calculus:

$$u=e^{\gamma(s-t)} \implies du = \gamma e^{\gamma(s-t)} \, ds$$ $$dv = dX(s) \implies v = X(s)$$

Then, we could write

$$\int_0^t u\, dv = u\,v|_0^t - \int_0^t v \, du = X(1-e^{-\gamma t})-\gamma \int_0^t e^{\gamma(s-t)}X(s) \, ds$$

which is different from his original solution. Where is my mistake? Is there any other way of evaluating integration by parts in the context of stochastic calculus?

First and foremost if $$u=e^{\gamma (s-t)}$$ then $$\frac{du}{ds} = \gamma e^{\gamma(s-t)} \iff du=\gamma e^{\gamma(s-t)} \,ds$$. Now, in the Ornstein–Uhlenbeck process $$X_t$$ is a Wiener process and satisfies $$X_0 = 0 \: \: \text{a.s.}$$ (see this and this). Then, the first term in the integration by parts formula specified above gives you:
$$uv\vert^t_0 = e^{\gamma (t-t)} X_t - e^{\gamma (0-t)} X_0 = X_t$$
In conclusion, we get: \begin{align} \int_0^t u \: dv &= uv\vert^t_0 - \int_0^t v \: du\\ &= X_t - \int_0^t X(s) \gamma e^{\gamma(s-t)} \,ds\\ &= X_t - \gamma\int_0^t e^{\gamma(s-t)} X(s) \,ds \end{align}