Solution to General Linear SDE

In order to find a solution for the general linear SDE
\begin{align}
dX_t = \big( a(t) X_t + b(t) \big) dt + \big( g(t) X_t + h(t) \big) dB_t,
\end{align}
I assume that $a(t), b(t), g(t)$ and $h(t)$ are given deterministic Borel functions on $\mathbb{R}_+$ that are bounded on each compact time interval.

To find a suitable integrating factor $Z_t$,
\begin{align}
dX_t – \big( a(t) dt – g(t) dB_t \big) X_t = b(t) dt + h(t) dB_t
\end{align}
brings me to
\begin{align}
Z_t = e^{-\int_0^t ( a(s) – \frac{1}{2}g^2(s) )ds – \int_0^t g(s) dB_s}.
\end{align}
So,
\begin{align}
d(Z_tX_t) &= Z_t \big( b(t) dt + h(t) dB_t \big) \\
X_t &= Z_t^{-1} \big(X_0 + \int_0^t Z_s b(s) ds + \int_0^t Z_s h(s) dB_s \big).
\end{align}
To find an explicit solution for the SDE, I am considering
\begin{align}
X_t &= Z_t^{-1} Y_t \\
dX_t &= d(Z_t^{-1} Y_t) \\
&= Z_t^{-1} dY_t + Y_t dZ_t^{-1} + d[Z_t^{-1}, Y_t].
\end{align}
Where $dZ_t^{-1} = Z_t^{-1} \big( a(t) dt + g(t) dB_t \big)$ and $dY_t = Z_t \big( b(t) dt + h(t) dB_t \big)$.

My question is, how to find $d[Z_t^{-1}, Y_t]$ and how to work towards the explicit solution for the SDE?

Solutions Collecting From Web of "Solution to General Linear SDE"

Here is the complete solution to the problem including some special cases for an easy start.
With analogy to the integrating factor method from ODEs it seems natural to rearrange
\begin{align*}
\mathrm{d}X_t = (a(t)X_t+ b(t)) \mathrm{d}t + (g(t)X_t+ h(t))\mathrm{d}B_t
\end{align*}
to the form
\begin{align*}\mathrm{d}X_t – X_t \left( a(t)\mathrm{d}t+g(t)\mathrm{d}B_t\right) = b(t) \mathrm{d}t + h(t)\mathrm{d}B_t .\end{align*}
Now we want to find a “nice” stochastic process $Z_t$ such that
\begin{align*}( \star) \ \ \ \mathrm{d}(X_tZ_t) =& Z_t\mathrm{d}X_t \underbrace{- Z_tX_t \left( a(t)\mathrm{d}t+g(t)\mathrm{d}B_t\right)}_{X_t\mathrm{d}Z_t + \mathrm{d}X_t\mathrm{d}Z_t} \\ =& Z_t(b(t)\mathrm{d}t + h(t)\mathrm{d}B_t).\end{align*}
Assume that $Z_t$ is an Itô process such that
$$\mathrm{d}Z_t = f_1(t, Z_t)\mathrm{d}t + f_2(t, Z_t)\mathrm{d}B_t , \ \ Z_0 = 1.$$
Let us apply Itô’s product formula to $\mathrm{d}(X_tZ_t)$ we obtain that
\begin{align*}\mathrm{d}(X_tZ_t) =& Z_t \mathrm{d}X_t + X_t \mathrm{d}Z_t + \mathrm{d}X_t \mathrm{d}Z_t \\ ( \star \star) \ \ \ \ \qquad = & Z_t\mathrm{d}X_t + X_t \left( f_1(t, Z_t)\mathrm{d}t + f_2(t, Z_t)\mathrm{d}B_t \right) + (g(t)X_t + h(t))f_2(t, Z_t) \mathrm{d}t.\end{align*}
Comparing the above with the right hand-side of $(\star)$ we arrive at
\begin{align*}- Z_tX_t \left( a(t)\mathrm{d}t+g(t)\mathrm{d}B_t\right) = X_t \left( f_1(t, Z_t)\mathrm{d}t + f_2(t, Z_t)\mathrm{d}B_t \right) + (g(t)X_t + h(t))f_2(t, Z_t) \mathrm{d}t \end{align*}
and thus
\begin{align*} -Z_tX_tg(t)\mathrm{d}B_t &= X_t f_2(t, Z_t)\mathrm{d}B_t \\
-Z_tX_ta(t)\mathrm{d}t &= \big(X_tf_1(t, Z_t)+(X(t)g(t)+h(t))f_2(t,Z_t)\big)\mathrm{d}t.\end{align*}
From the first equation we can deduce that $f_2(t, Z_t) = -Z_tg(t)$ and so the second one converts to
$$-Z_tX_ta(t)\mathrm{d}t = \big(X_tf_1(t, Z_t)-Z_tg(t)(X(t)g(t)+h(t))\big)\mathrm{d}t,$$
and so
$$ Z_t (-X_ta(t)+X(t)g^2(t)+g(t)h(t)) \mathrm{d}t = X_tf_1(t, Z_t)\mathrm{d}t.$$
Hence,
$$f_1(t, Z_t) = Z_t(-a(t)+g^2(t)+X_t^{-1}g(t)h(t)).$$

However, we want $Z_t$ to be free of $X_t$ for that we consider two cases

CASE 1. $g(t) \neq 0$, $h(t)=0$

Then $Z_t$ would satisfy
$$\mathrm{d}Z_t = Z_t(-a(t)+g^2(t))\mathrm{d}t -Z_t g(t)\mathrm{d}B_t , \ \ Z_0 = 1$$
(We solve the above SDE by a standard trick involving Ito’s formula, that is, first we divide by $Z_t$ to obtain the expression for $Z_t^{-1}\mathrm{d}Z_t$ and then derive the expression $\mathrm{d}(\ln(Z_t))$)

and so $$Z_t = \exp\left( \int_0^t\left( \frac{1}{2}g^2(s) – a(s)\right) \mathrm{d}s – \int_0^t g(s)\mathrm{d}B_s\right).$$
This is the integrating factor which you obtained, and it is not the correct one if $h(t) \neq 0$.

If we continue then we obtain
\begin{align*}\mathrm{d}(Z_tX_t) =& Z_tb(t)\mathrm{d}t
\\ Z_tX_t =& X_0 + \int_0^t Z_sb(s) \mathrm{d}s\\
X_t =& X_0Z_t^{-1}+ Z_t^{-1}\int_0^t Z_sb(s) \mathrm{d}s\\
X_t =& \exp\left( \int_0^t\left( a(s) – \frac{1}{2}g^2(s) \right) \mathrm{d}s + \int_0^t g(s)\mathrm{d}B_s\right) \\ &\cdot \left(X_0+ \int_0^{t} b(s)\exp\left( \int_0^s\left( \frac{1}{2}g^2(r) – a(r)\right) \mathrm{d}r – \int_0^s g(r)\mathrm{d}B_r\right)\mathrm{d}s\right).
\end{align*}

CASE 2. $g(t) = 0$, $h(t) \neq 0$

Then $(Z_t)$ satisfies
$$\mathrm{d}Z_t = -a(t)Z_t\mathrm{d}t, \ \quad Z_0 =1 $$
and so
$$Z_t = \exp\left( -\int_0^t a(s)\mathrm{d}s\right).$$

Therefore,
\begin{align*}\mathrm{d}(X_tZ_t) =& Z_tb(t)\mathrm{d}t+ Z_t h(t)\mathrm{d}B_t
\\ X_tZ_t =& X_0 + \int_0^t Z_sb(s) \mathrm{d}s + \int_0^t Z_sb(s) \mathrm{d}B_s\\
X_t = & X_0Z_t^{-1}+ Z_t^{-1}\left( \int_0^t Z_sb(s) \mathrm{d}s + \int_0^t Z_sb(s) \mathrm{d}B_s\right) \\
X_t = & X_0 e^{ \int_0^t a(s)\mathrm{d}s}\\ &+ e^{ \int_0^t a(s)\mathrm{d}s}\left( \int_0^t e^{ -\int_0^s a(r)\mathrm{d}r}b(s) \mathrm{d}s + \int_0^t e^{ -\int_0^s a(r)\mathrm{d}r}b(s) \mathrm{d}B_s\right).
\end{align*}

The general case

So far we were not able to find the solution for the general case, to find it we need to modify and rearrange our initial equation in a slightly different way.
Let write the SDE for $(X_t)$ as follows
\begin{align*}\mathrm{d}X_t = (a(t)X_t + b(t)+g(t)h(t) – g(t)h(t))\mathrm{d}t + (g(t)X_t+h(t))\mathrm{d}B_t
\end{align*}
after rearranging we have
\begin{align*}\mathrm{d}X_t – \left((a(t)X_t+g(t)h(t))\mathrm{d}t+ g(t)X_t\mathrm{d}B_t\right)= (b(t)- g(t)h(t))\mathrm{d}t + h(t)\mathrm{d}B_t
\end{align*}
Now let ($Z_t$) be an Ito process that satisfies
$$\mathrm{d}Z_t = f_1(t, Z_t)\mathrm{d}t + f_2(t, Z_t)\mathrm{d}B_t , \ \ Z_0 = 1.$$
After multiplying our SDE by $Z_t$ we obtain
\begin{align*}Z_t\mathrm{d}X_t – Z_t\left((a(t)X_t+g(t)h(t))\mathrm{d}t+ g(t)X_t\mathrm{d}B_t\right)= Z_t \left((b(t)- g(t)h(t))\mathrm{d}t + h(t)\mathrm{d}B_t\right)
\end{align*}
Applying Ito product formula to $X_tZ_t$ we get
$$ \mathrm{d}(X_tZ_t) = Z_t\mathrm{d}X_t + X_t\mathrm{d}Z_t+ \mathrm{d}X_t\mathrm{d}Z_t,$$

we want to have
\begin{align*}X_t\mathrm{d}Z_t+ \mathrm{d}X_t\mathrm{d}Z_t = – Z_t\left((a(t)X_t+g(t)h(t))\mathrm{d}t+ g(t)X_t\mathrm{d}B_t\right)\end{align*}

The LHS equals to
\begin{align*}X_t\left(f_1(t, Z_t)\mathrm{d}t + f_2(t, Z_t)\mathrm{d}B_t \right)+ (g(t)X_t+h(t))f_2(t, Z_t)\mathrm{d}t.\end{align*}

We compare with the RHS
\begin{align*}X_t\left(f_1(t, Z_t)\mathrm{d}t + f_2(t, Z_t)\mathrm{d}B_t \right)+ (g(t)X_t+h(t))f_2(t, Z_t)\mathrm{d}t = – Z_t\left((a(t)X_t+g(t)h(t))\mathrm{d}t+ g(t)X_t\mathrm{d}B_t\right)\end{align*}

and conclude that $f_2(t, Z_t) = -g(t)Z_t$. Now

\begin{align*}X_t\left(f_1(t, Z_t)\mathrm{d}t -g(t)Z_t\mathrm{d}B_t \right)- (g(t)X_t+h(t))g(t)Z_t\mathrm{d}t = – Z_t\left((a(t)X_t+g(t)h(t))\mathrm{d}t+ g(t)X_t\mathrm{d}B_t\right)\end{align*}
simplifies to
\begin{align*}X_tf_1(t, Z_t)\mathrm{d}t -g(t)^2Z_tX_t\mathrm{d}t = – a(t)Z_tX_t\mathrm{d}t\end{align*}
and so
\begin{align*}X_tf_1(t, Z_t)\mathrm{d}t = X_t\left( (g(t)^2- a(t))Z_t\right)\mathrm{d}t\end{align*}
let us conclude that
$$ f_1(Z_t, t) = (-a(t)+g(t)^2)Z_t.$$
Thus $$\mathrm{d}Z_t = (-a(t)+g^2(t))Z_t \mathrm{d}t – g(t)Z_t\mathrm{d}B_t,$$
you can see the explicit form of $Z_t$ in Case 1 and
$$\mathrm{d}(Z_tX_t) = (b(t)-h(t)g(t))Z_t\mathrm{d}t + h(t)Z_t\mathrm{d}B_t.$$

Using Ito’s lemma we can show that $(Y_t):= (Z_t^{-1})$ is an Ito process such that it satisfies
$$ \mathrm{d}Y_t = a(t)Y_t \mathrm{d}t + g(t)Y_t\mathrm{d}B_t,\ \ Y_0 = 1$$
it has an explicit form
$$ Y_t = \exp\left(\int_0^t (a(s)-\frac{1}{2}g^2(s)) \mathrm{d}s +\int_0^t g(s)\mathrm{d}B_s\right).$$

Finally, we see that
\begin{align*}\mathrm{d}(Z_tX_t) =& (b(t)-h(t)g(t))Z_t\mathrm{d}t + h(t)Z_t\mathrm{d}B_t \end{align*}
yields
\begin{align*}Z_tX_t =& Z_0X_0 + \int_0^t (b(s)-h(s)g(s))Z_s\mathrm{d}s + \int_0^t h(s)Z_s\mathrm{d}B_s \end{align*}
Hence, we have the explicit solution
\begin{align*}X_t =& Z_0X_0Y_t + Y_t\left(\int_0^t (b(s)-h(s)g(s))Z_s\mathrm{d}s + \int_0^t h(s)Z_s\mathrm{d}B_s\right). \end{align*}