I'd been reading on Hull-White model, when I encountered the bond-pricing formula, that is if
$$ dr(t) = (\alpha(t)-\beta(t)r(t))dt + \sigma(t)dW(t)$$
for some deterministic function $\alpha, \beta, \sigma$, and $W$ being the Wiener process, then the zero bond price at time $t$ with maturity $T$ is given by
$$B(t,T)=\exp(-r(t)C(t,T)-A(t,T))$$
where $C(t,T)$ and $A(t,T)$ are completely deterministic; they are determined by $\alpha(t)$, $\beta(t)$, and $\sigma(t)$.
When I want to derive $dB(t,T)$, I want to use Ito's Lemma, so here are my steps:
Assuming $T$ is fixed, $B$ is determined by a process $r$ and time $t$, thus letting $$f(x,t) = \exp(-xC(t,T)-A(t,T))$$ We have:
$$f_x = -C(t,T) f(x,t), f_{xx} = C(t,T)^2f(x,t), f_t = \left[-xC_t(t,T)-A_t(t,T)\right]f(x,t)$$
Thus according to Ito's Lemma,
$$dB(t,T)=f_x(r(t),t)dr(t)+\frac{1}{2}f_{xx}(r(t),t)dr(t)dr(t)+f_t(r(t),t)dt$$ $$=B(t,T)\left[-C(t,T)dr(t)+\frac{1}{2}C(t,T)^2dr(t)dr(t)-r(t)C_t(t,T)dt-A_t(t,T)dt\right]$$
However, as it turns out, this is incorrect; the correct answer, which is due to the expression of $A(t,T)$ and $C(t,T)$ (which I will give later as I think we should be able to obtain $dB(t,T)$ without looking at $A(t,T)$ and $C(t,T)$), is
$$dB(t,T)=B(t,T)\left[-C(t,T)dr(t)-\frac{1}{2}C(t,T)^2dr(t)dr(t)-r(t)C_t(t,T)dt-A_t(t,T)dt\right]$$
I managed to obtain this correct answer though, by an algebraic manipulation (which I'm also not sure is valid, or not):
Consider the fact that $$B(t,T)\exp(r(t)C(t,T)+A(t,T))=1$$ Then, taking the differential, $$dB(t,T)\exp(r(t)C(t,T)+A(t,T)) + B(t,T)d\left[\exp(r(t)C(t,T)+A(t,T))\right] = 0$$
Now, by Ito's Lemma, we have $$d\left[\exp(r(t)C(t,T)+A(t,T))\right]$$ $$=\exp(r(t)C(t,T)+A(t,T))\cdot$$ $$\left[C(t,T)dr(t)+\frac12C(t,T)^2dr(t)dr(t)+r(t)C_t(t,T)dt+A_t(t,T)dt\right]$$
Using this fact and cancelling out $\exp(r(t)C(t,T)+A(t,T))$, we have
$$dB(t,T)+B(t,T)\left[C(t,T)dr(t)+\frac12C(t,T)^2dr(t)dr(t)+r(t)C_t(t,T)dt+A_t(t,T)dt\right]=0$$ and we have: $$dB(t,T)=B(t,T)\left[-C(t,T)dr(t)-\frac{1}{2}C(t,T)^2dr(t)dr(t)-r(t)C_t(t,T)dt-A_t(t,T)dt\right]$$
Why is my first derivation incorrect, yet my second derivation correct?
Note:
This is the explicit form of $A(t,T)$ and $C(t,T)$. Firstly, let
$$K(t)=\int_0^t\beta(u)du$$
then
$$A(t,T)=\int_t^T\left[e^{K(v)}\alpha(v)\left(\int_v^Te^{-K(y)}dy\right)-\frac12e^{2K(v)}\sigma(v)^2\left(\int_v^Te^{-K(y)}dy\right)^2\right]dv$$
$$C(t,T)=e^{K(t)}\left(\int_t^Te^{-K(y)}dy\right)$$
Thank you! I am still self-studying on stochastic calculus, and as such I still don't have a strong grip on the concept itself.
Looks like the first derivation is correct. In the second derivation, taking the differential of $B \exp(rC + A)$ gives $$B d(\exp(rC+A)) + \exp(rC+A)dB + (dB)(d(\exp(rC+A)).$$ The extra term $(dB)(d(\exp(rC+A))$ is where the $C^2(dr)(dr)$ difference comes from.