Solution (source code)

= Solution

The <delta replication from a local-volatility pricing equation> uses the asset-unit holdings
$$
\boxed{h^S_t=V_S(t,S_t),\qquad h^B_t=\frac{V(t,S_t)-S_tV_S(t,S_t)}{B_t}.}
$$
Their wealth is exactly $V(t,S_t)$. Moreover,
$$
h^B_t\,dB_t+h^S_t\,dS_t=rV(t,S_t)dt+\sigma(S_t)S_tV_S(t,S_t)d\widehat W_t=dV(t,S_t),
$$
where the final equality is the calculation in part (i). Thus the holdings are a <self-financing strategy> with terminal wealth $g(S_T)$, proving replication. Since $V\geq0$, this <replicating strategy> has nonnegative wealth and is an <admissible trading strategy>. The equality of trading gains is unchanged by replacing the drift with its physical-measure value: the stock drift in <Itô formula> and in the stock holding changes by the same amount. If $\pi_t$ denotes wealth fractions, then, wherever $V>0$, its stock fraction is $S_tV_S/V$ and its bank fraction is $1-S_tV_S/V$.