Delta replication from a local-volatility pricing equation (source code)

= Delta replication from a local-volatility pricing equation
{title2=$h^S=V_S,\quad h^B=(V-SV_S)/B$}

Let a sufficiently smooth $V$ satisfy the <pricing equation for a local volatility model>, and assume its proposed holdings are stochastically integrable. Hold $h_t^S=V_S(t,S_t)$ stocks and $h_t^B=[V(t,S_t)-S_tV_S(t,S_t)]/B_t$ units of the <bank account>. Their value is $V(t,S_t)$. The <Itô formula> and the pricing equation give
$$
dV(t,S_t)=rV(t,S_t)dt+S_t\sigma(t,S_t)V_S(t,S_t)dW_t^Q=h_t^B\,dB_t+h_t^S\,dS_t.
$$
Thus the holdings form a <self-financing strategy> with terminal value $g(S_T)$, rather than merely a decomposition of today's value. This is a <delta hedge>. If $V\ge0$, the replicating strategy has nonnegative wealth and satisfies the standard <admissible trading strategy> lower-bound condition. The stock and bank wealth amounts are $S_tV_S$ and $V-S_tV_S$; they differ from the numbers of asset units held.