Solution (source code)

= Solution

Let $Q$ denote the given unique <equivalent martingale measure>. A <zero-coupon bond> paying one at $T$ has <risk-neutral pricing> value
$$
P_t(T)=\mathbb E_Q\left[\exp\left(-\int_t^Tr_sds\right)\middle|\mathcal F_t\right].
$$
Write $h=T-t$. Split the integrated <short rate> into its known and future parts:
$$
\int_t^Tr_sds=\int_t^Tg(s)ds+\sigma h\widehat W_t+\sigma\int_t^T(\widehat W_s-\widehat W_t)ds.
$$
By integrating the future <Brownian motion> increments in the opposite order, the last integral equals $\int_t^T(T-u)d\widehat W_u$. It is independent of $\mathcal F_t$ and is a <Gaussian random variable> of mean zero and <variance>
$$
\int_t^T(T-u)^2du=\frac{h^3}{3}.
$$
The <Gaussian> <exponential moment> formula $\mathbb E[e^{aZ}]=e^{a^2\operatorname{Var}(Z)/2}$ for centered $Z$ therefore gives the bond price in this <Gaussian short-rate model with a deterministic shift>:
$$
\boxed{P_t(T)=\exp\left[-\int_t^Tg(s)ds-\sigma(T-t)\widehat W_t+\frac{\sigma^2(T-t)^3}{6}\right].}
$$
The <instantaneous forward rate> is the negative maturity <derivative> of the logarithm of the bond price. Consequently
$$
\boxed{f_t(T)=g(T)+\sigma\widehat W_t-\frac{\sigma^2}{2}(T-t)^2.}
$$
In particular, $P_t(t)=1$ and $f_t(t)=g(t)+\sigma\widehat W_t=r_t$, as required. The <derivative> formula is pointwise for continuous $g$ and almost everywhere for locally integrable $g$.