Why Bond pricing formula is changed? [closed]

When I first learn about finance, a bond with continuous yield was priced via

$$Z = e^{-rT},$$ where $$r$$ is the yield, $$T$$ the time to maturity.

But, when I learned about stochastic interest rate models like Ho-Lee and Hull & White, etc. the formula changed to

$$Z= e^{A-Br},$$ where $$A$$, $$B$$ are functions.

What is the reason for it? Is there any reference which deal with this? I need explanation that is intuitive.

• In the first formula, which is always true, $r$ is the interest rate (or YTM) for the term of the bond (i.e. the 7 year interest rate in the case of a 7 year bond). In the second formula $r_t$ is the instantaneous i.r., or Spot Rate, which is the (annualized) rate for lending money for a short period if time, such as 1 day. You can use two different letters (such as $y$ and $r_t$) if you want. – noob2 May 7 '20 at 14:23

In general, the time $$t$$ price of a zero-coupon bond maturing at time $$T$$ is given by \begin{align*} P(t,T) &= \mathbb{E}^\mathbb{Q}\left[\exp\left(-\int_t^T r_s\mathrm{d}s\right) \Bigg|\mathcal{F}_t\right]. \end{align*} Here, $$r_t$$ is the short rate, i.e. the cost for borrowing time from $$t$$ until $$t+\mathrm{d}t$$. This formula follows directly from the absence of arbitrage.
If $$r_t\equiv r$$ is constant, then \begin{align*} P(t,T)=e^{-r(T-t)}, \end{align*} which is the first formula you mentioned.
If $$r_t$$ is time-varying, you have to used the above equation with the conditional expectations. As it happens, in the Ho-Lee and the Hull-White models (and others too), this conditional expectation can be written as \begin{align*} P(t,T)=e^{A(t,T)+r_tB(t,T)}, \end{align*} for suitable functions $$A,B$$, see here.