# Affine Structure Resolution for the Vasicek model

I would like to now how to solve the PDE of the affine structure under Vasicek.I am delineating the steps:

First let's posit the OU process under a Risk Neutral Measure such as : \begin{align*} \mathrm{d}r_t=\mu(t,r_t)\mathrm{d}t+\sigma(t,r_t)\mathrm{d}W_t \end{align*}

Then comes the bond PDE:

\begin{align*} P_t + \mu(t,r) P_r + \frac{1}{2}\sigma(t,r)^2P_{rr} -rP=0, \end{align*} We Write the penny zero coupon bond's formula and mixed it with the Original PDE,using a latent $$r_t$$ variable :

\begin{align*} P(t,T)=e^{A(t,T)-r_tB(t,T)} \end{align*}

\begin{align*} P_t(t,T) &=\big(A_t(t,T)-r_tB_t(t,T)\big)\cdot P(t,T), \\ P_r(t,T) &= -B(t,T)\cdot P(t,T), \\ P_{rr}(t,T) &= B(t,T)^2\cdot P(t,T). \end{align*}

\begin{align*} A_t(t,T) - \mu(t,r) B(t,T) + \frac{1}{2}\sigma(t,r)^2B(t,T)^2 +(-B_t(t,T)-1)r &=0. \end{align*}

In the Vasicek case, $$\mu(t,r_t)=\kappa(\theta-r_t)$$ and $$\sigma(t,r_t)=\sigma$$.Afterward the calculations are straightforward:

\begin{align*} A_t(t,T) - \kappa \theta B(t,T) + \kappa r B(t,T) + \frac{1}{2}\sigma^2B(t,T)^2 +(-B_t(t,T)-1)r &=0 \\ \implies A_t(t,T) - \kappa \theta B(t,T) + \frac{1}{2}\sigma^2B(t,T)^2-(1+B_t(t,T)-\kappa B(t,T))r &=0. \end{align*}

And we end up with two equations such :

\begin{align*} \begin{cases} A_t(t,T) - \kappa \theta B(t,T) + \frac{1}{2}\sigma^2B(t,T)^2 &= 0, \\ 1+B_t(t,T)-\kappa B(t,T) &= 0,\\ u.c : A(T,T)=B(T,T)=0 \end{cases} \end{align*} However I don't understand the development we must do so as to find $$B_t(t,T) = e^{-k(T-t)}$$ and hence $$B(t,T) = \frac{-1+e^{-k(T-t)}}{k}$$.

We begin with the equation $$1+B_t(t,T)-kB(t,T) = 0 \quad(1)$$
\begin{align} (1) & \iff e^{-kt}+e^{-kt}B_t(t,T)+(-k)e^{-kt}B(t,T) = 0 \\ & \iff e^{-kt}+ \frac{\partial}{\partial t}\left(e^{-kt}B(t,T)\right) = 0 \\ & \iff \int_t^Te^{-ku}du+ \int_t^T\frac{\partial}{\partial u}\left(e^{-ku}B(t,T)\right)du = 0 \\ & \iff \int_t^Te^{-ku}du+ \int_t^T\frac{\partial}{\partial u}\left(e^{-ku}B(t,T)\right)du = 0 \\ & \iff\frac{e^{-kt}-e^{-kT}}{k} +\left(e^{-kT}B(T,T) - e^{-kt}B(t,T)\right) = 0 \tag{2}\\ \end{align} From $$(2)$$, you can deduce the closed form expression of $$B(t,T)$$.