Statement of problem
From Oksendal SDEs question 5.18:
The geometric mean reversion process is a solution to:
$$ dX_t = k (a - \log X_t) X_t dt + \sigma X_t dB_t $$
In showing that solution is given by:
$$ X_t = \exp ( e^{-k t}\log X_0+(a-\sigma^2/2k)(1-e^{k t})+\sigma e^{-k t}\int_0^t e^{k s}dB_s)$$
It says to take $Y_t = \log X_t$
Then:
$$ Y_t= e^{-k t}\log X_0+(a-\sigma^2/2k)(1-e^{k t})+\sigma e^{-k t}\int_0^t e^{k s}dB_s$$
and go from there..
Attempt:
I have seen elsewhere that the next step should lead to:
$$dY_t = \left( -kY_t+k\left(a-\frac{\sigma^2}{2k}\right)\right)dt+\sigma dB_s$$
But I am unsure about $Y_t = f(t,B_t)$, and when using Itô's formula to evaluate $$dY_t = \partial_t f(t,B_t)dt + \partial_x f(t,B_t)dB_t + \frac{1}{2}\partial_{xx}f(t,B_t) dt$$
I do not know how to determine the function $f(t,x)$ for use in the formula due to the stochastic integral contained in $Y_t$.
After saz post
$$f(t,x)=\sigma e^{-k t}x + \left(a -\frac{\sigma ^2}{2k }\right)\left(1-e^{k t}\right)$$
For the formula you need the following partial derivatives:
$$ \partial_t f(t,x)=-e^{-k t} k x \sigma -e^{t k } k \left(a -\frac{\sigma ^2}{2 k }\right) $$
$$ \partial_x f(t,x) = e^{-k t} \sigma $$
Then: $$ Z_t = \left(\frac{1}{\sigma }Y_0+\int_0^t e^{k s} \, dB_s\right) $$
$$Y_t = f(t,Z_t)$$
So:
$$dY_t =\left[ -e^{-k t} k \left(\frac{1}{\sigma }Y_0+\int_0^t e^{k s} \, dB_s\right) \sigma -e^{t k } k \left(a -\frac{\sigma ^2}{2 k }\right) \right] dt + e^{-kt} \sigma dZ_t $$
$$ dY_t = \left[ k\left(a-\frac{\sigma^2}{2k}\right) -kY_t \right] dt + e^{-kt} \sigma dZ_t $$
$$ dY_t = \left[ k(a-Y_t)-\frac{\sigma ^2}{2}\right]\text{dt} + \sigma \text{dB}_t $$
If
$$ dY_t = \left[ k(a-Y_t) - \frac{\sigma^2}{2}\right]dt + \sigma dB_t $$
Then by Ito's with $X_t = e^{Y_t}$:
$$ dX_t = k(a-\log X_t) X_t dt + X_t \sigma dB_t \,\,\,\, \blacksquare$$
No, you cannot simply set
$$g(t,x) = \int_0^t e^{ks} \, dx$$
since the stochastic integral $\int_0^t e^{ks} \, dB_s$ is not pathwise defined. In order to find the differential of $(Y_t)_{t \geq 0}$, you have to apply Itô's formula for Itô processes. Namely, if
$$dZ_t = \sigma_t \, dB_t$$
then Itô's formula states that
$$\begin{align*} f(t,Z_t)-f(0,Z_0) &= \int_0^t \partial_x f(s,Z_s) \sigma_s \, dB_s + \int_0^t \left( \frac{1}{2} \partial_{xx} f(s,Z_s) \sigma_s^2 + \partial_t f(s,Z_s) \right) \, ds. \end{align*}$$
Apply this to
$$\begin{align*} Z_t &:= \left(\frac{1}{\sigma} Y_0 + \int_0^t e^{ks} \, dB_s \right) \\ f(t,x) &:= \sigma e^{-kt} x + \left(a- \frac{\sigma^2}{2k} \right) (1-e^{kt}). \end{align*}$$