Solution (source code)

= Solution

Define the risk-neutral claim value
$$
V(t,s)=e^{-r(T-t)}
\int_{\mathbb R}g\left(
s e^{(r-\sigma^2/2)(T-t)+\sigma\sqrt{T-t}\,z}
\right)\phi(z)\,dz.
$$
Then $V(0,S_0)=x$, $V(T,s)=g(s)$, and the <Black-Scholes equation> holds. Differentiation under the integral gives the delta
$$
\partial_sV(t,s)=e^{-r\tau}
\mathbb E\left[
g'(se^{(r-\sigma^2/2)\tau+\sigma\sqrt\tau Z})
e^{(r-\sigma^2/2)\tau+\sigma\sqrt\tau Z}
\right],
\qquad \tau=T-t.
$$
A Gaussian shift $Z\mapsto Z+\sigma\sqrt\tau$ rewrites this as
$$
\partial_sV(t,s)=
\int_{\mathbb R}
g'(se^{(r+\sigma^2/2)\tau+\sigma\sqrt\tau z})\phi(z)\,dz,
$$
which is exactly the stated $\theta_t$ at $s=S_t$.

Apply <Itô formula> to $V(t,S_t)$. The PDE gives
$$
dV(t,S_t)=r\{V-\theta_tS_t\}\,dt+\theta_t\,dS_t.
$$
This is the same wealth equation as part a, with the same initial value $x$. Uniqueness therefore gives $X_t^{x,\theta}=V(t,S_t)$ and hence
$$
X_T^{x,\theta}=V(T,S_T)=g(S_T).
$$