## CIR model

We derive the CIR term structure model formulae.

### Short rate dynamics: Probability Distribution

We show that the CIR dynamics $$d r_{t}= \kappa \left( \theta-r_{t} \right) dt + \sigma \sqrt{r_t} d w_{t}$$ imply that the short rate is distributed as a scalar times a Non-central Chi-Squared with degree of freedom $$n=\frac{4 \kappa \theta }{\sigma^2}$$ and non-centrality parameter $$\lambda= \frac{ 4 \kappa e^{-\kappa \left( t-s\right)}}{\sigma^2 \left( 1 - e^{- \kappa \left(t-s \right)}\right)} r_s$$.

By definition, the sum of the squares of n standard normal variables(mean=0, and std=1) follows a Chi-Squared distribution with n degree of freedom. If the individual normal variables have non-zero means (but still standard deviations of 1), then the sum of their squares follows a Non-central Chi-Squared distribution with n degree of freedom and non-centrality parameter equal to the sum of the squares of the means.

Let $$X_i$$ be a normal random variables, then we posit:

$$r_{t}= X_{1,t}^2 + X_{2,t}^2 + X_{3,t}^2 + . . . + X_{n,t}^2$$

Where we assume each $$X_{i,t}$$ has the following dynamics (similar to Vasicek but with mean level of zero):

$$dX_{i,t} = - \frac{1}{2} \kappa X_{i,t} dt + \frac{1}{2} \sigma d w_{t}$$

Rearranging the equation, multiplying both sides by the integrating factor, and integrating from s to t, we get:

$$dX_{i,t} + \frac{1}{2} \kappa X_{i,t} dt = \frac{1}{2} \sigma d w_{t}$$ $$e^{\kappa t /2} dX_{i,t} + \frac{1}{2} e^{\kappa t /2} \kappa X_{i,t} dt = \frac{1}{2} e^{\kappa t /2} \sigma d w_{t}$$ $$d \left( e^{\kappa t /2} X_{i,t} \right) = \frac{1}{2} e^{\kappa t /2} \sigma d w_{t}$$ $$\int_{s}^{t} {d \left( e^{\kappa u /2} X_iu \right)} = \frac{1}{2}\sigma \int_{s}^{t} {e^{ \kappa u /2 } d w_{u}}$$ $$e^{\kappa t /2} X_{i,t} - e^{\kappa s /2} X_{i,s} = \frac{1}{2}\sigma \int_{s}^{t} {e^{ \kappa u /2 } d w_{u}}$$ $$X_{i,t} = e^{-\kappa \left( t-s\right)/2} X_{i,s} + \frac{1}{2}\sigma \int_{s}^{t} {e^{-\kappa \left( t- u \right) /2 } d w_{u}}$$

The mean and variance of which are given by,

$$E \left[ X_{i,t} \mid X_{i,s} \right]= e^{-\kappa \left( t-s\right)/2} X_{i,s}$$ $$V \left[ X_{i,t} \mid X_{i,s} \right]= V \left[ \frac{\sigma}{2} \int_{s}^{t} {e^{-\kappa \left( t- u \right) /2 } d w_{u}} \right]$$ $$\quad \quad = \frac{\sigma^2}{4} \int_{s}^{t} {e^{- \kappa \left(t-u \right)} du}$$ $$\quad \quad = \frac{\sigma^2}{4 \kappa} \left( e^{- \kappa \left(t-t \right)} - e^{- \kappa \left(t-s \right)}\right)$$ $$\quad \quad = \frac{\sigma^2}{4 \kappa} \left( 1 - e^{- \kappa \left(t-s \right)}\right)$$

We want the variables to have unit variances (standard deviations of 1), which we achieve by dividing each $$X_{i,t}$$ by the standard deviation (square root of variance) derived above. Let's denote the transformed variable with prime, thus

$$X^{\prime}_{i,t}=\frac{X_{i,t}}{\sqrt{\frac{\sigma^2}{4 \kappa} \left( 1 - e^{- \kappa \left(t-s \right)}\right)}}$$ $$E \left[ X^{\prime}_{i,t} \mid X^{\prime}_{i,s} \right]= \frac{e^{-\kappa \left( t-s\right)/2} X_{i,s}}{\sqrt{\frac{\sigma^2}{4 \kappa} \left( 1 - e^{- \kappa \left(t-s \right)}\right)}}$$ $$V \left[ X^{\prime}_{i,t} \mid X^{\prime}_{i,s} \right]=1$$ $$r_{t}= X_{1,t}^2 + X_{2,t}^2 + X_{3,t}^2 + . . . + X_{n,t}^2$$ $$\quad = {\frac{\sigma^2}{4 \kappa} \left( 1 - e^{- \kappa \left(t-s \right)}\right)} \left[ {X^{\prime}}_{1,t}^2 + {X^{\prime}}_{2,t}^2 + {X^{\prime}}_{3,t}^2 + . . . + {X^{\prime}}_{n,t}^2 \right]$$

Thus $$r_t$$ is equal to $$\frac{\sigma^2}{4 \kappa} \left( 1 - e^{- \kappa \left(t-s \right)}\right)$$ times a Non-central Chi-Squared variable with non-centrality parameter equal to (the sum of the squares of the mean of the individual $$X^{\prime}_i$$s ):

$$\lambda = \sum_{i=1}^n { {E \left[ X^{\prime}_{i,t} \mid X^{\prime}_{i,s} \right]}^2} = \sum_{i=1}^n {\frac{e^{-\kappa \left( t-s\right)} {X_{i,s}}^2}{\frac{\sigma^2}{4 \kappa} \left( 1 - e^{- \kappa \left(t-s \right)}\right)}}$$ $$\quad = \frac{e^{-\kappa \left( t-s\right)}}{\frac{\sigma^2}{4 \kappa} \left( 1 - e^{- \kappa \left(t-s \right)}\right)}\sum_{i=1}^n{{X_{i,s}}^2}$$ $$\quad =\frac{ 4 \kappa e^{-\kappa \left( t-s\right)}}{\sigma^2 \left( 1 - e^{- \kappa \left(t-s \right)}\right)} r_s$$

And degree of freedom equal to n, which we establish by studying the dynamics of $$r_t$$. Recall that $$r_t$$ is the sum of n independent $$X_{i,t}^2$$, where the dynamics of each $$X_{i,t}^2$$ is given by

$$d \left( X_{i,t}^2 \right)= \frac{\partial X_{i,t}^2 }{\partial X_{i,t}} dX_{i,t} + \frac{1}{2} \frac{\partial X_{i,t}^2 }{\partial X_{i,t}^2} d X_{i,t}^2$$ $$\quad= 2 X_{i,t} dX_{i,t} + \frac{1}{2} 2 d X_{i,t}^2$$ $$\quad= 2 X_{i,t} \left( - \frac{1}{2} \kappa X_{i,t} dt + \frac{1}{2} \sigma d w_{t} \right) + \frac{\sigma^2}{4} dt$$ $$\quad= \left(-\kappa X_{i,t}^2 + \frac{\sigma^2}{4} \right) dt + \sigma X_{i,t} d w_{t}$$

Thus:

$$d r_{t}= d X_{1,t}^2 + d X_{2,t}^2 + d X_{3,t}^2 + . . . + d X_{n,t}^2 =\sum_{i=1}^n{d X_{i,t}^2 }$$ $$\quad = \sum_{i=1}^n{ \left(-\kappa X_{i,t}^2 + \frac{\sigma^2}{4} \right) dt} + \sum_{i=1}^n{\sigma X_{i,t} d w_{t} }$$ $$\quad = { \left(-\kappa \sum_{i=1}^n{X_{i,t}^2} + \frac{n \sigma^2}{4} \right) dt} + \sigma \sum_{i=1}^n{ X_{i,t}} d w_{t}$$ $$\quad = { \left(-\kappa r_t + \frac{n \sigma^2}{4} \right) dt} + \sigma \sqrt{r_t} \frac{\sum_{i=1}^n{ X_{i,t}}}{\sqrt{r_t}} d w_{t}$$ $$\quad = { \left(-\kappa r_t + \frac{n \sigma^2}{4} \right) dt} + \sigma \sqrt{r_t} d w^{\prime}_{t}$$

Where $$d w^{\prime}_{t} = \frac{\sum_{i=1}^n{ X_{i,t}}}{\sqrt{r_t}} d w_{t}$$ is a Brownian motion as can be easily verified. Comparing this to the CIR model $$d r_{t}= \kappa \left( \theta-r_{t} \right) dt + \sigma \sqrt{r_t} d w_{t}$$, we find the degree of freedom n to be:

$$\frac{n \sigma^2}{4}= \kappa \theta \quad \Rightarrow \quad n= \frac{4 \kappa \theta }{\sigma^2}$$

We are done with the derivation of the distribution as we have shown that $$r_t$$ is equal to $$\frac{\sigma^2}{4 \kappa} \left( 1 - e^{- \kappa \left(t-s \right)}\right)$$ times a Non-central Chi-Squared variable with non-centrality parameter= $$\frac{ 4 \kappa e^{-\kappa \left( t-s\right)}}{\sigma^2 \left( 1 - e^{- \kappa \left(t-s \right)}\right)} r_s$$ and degree of freedom $$=\frac{4 \kappa \theta }{\sigma^2}$$.

However, CIR formula for the density of short rate is presented in a slightly different form, which we can easily transform our equations into by making the same substitutions that CIR chose to make (don't ask me why!): $$c=\frac{ 2 \kappa }{\sigma^2 \left( 1 - e^{- \kappa \left(t-s \right)}\right)}$$ $$u=c e^{-\kappa \left( t-s\right)} r_s$$ $$v=c r_t$$ $$q=\frac{2 \kappa \theta }{\sigma^2}-1$$ $$x \sim {\chi^{\prime}}^2_n (\lambda) \mbox{ i.e., x is Non-central Chi-Squared distributed with n degree of freedom and non-centrality parameter } \lambda$$ $$\Rightarrow f_X (x;n,\lambda)=\frac{1}{2} e^{-\frac{x+\lambda}{2}} {\left( \frac{x}{\lambda}\right)}^{\frac{n-2}{4}} I_{\frac{n-2}{2}} \left( \sqrt{\lambda x} \right)$$

Where we added the last equation as this is the density of a Non-central Chi-Squared (see wikipedia). Making the substitutions, we get.

$$n=\frac{4 \kappa \theta }{\sigma^2}=2 \left( \frac{2 \kappa \theta }{\sigma^2} -1\right)+2=2q+2$$ $$\lambda=\frac{ 4 \kappa e^{-\kappa \left( t-s\right)}}{\sigma^2 \left( 1 - e^{- \kappa \left(t-s \right)}\right)} r_s=2u$$ $$r_t= \frac{\sigma^2}{4 \kappa} \left( 1 - e^{- \kappa \left(t-s \right)}\right) x= \frac{1}{2c} x$$ $$\Rightarrow r_t \sim \frac{1}{2c} {\chi^{\prime}}^2_n (\lambda)$$

And we finally derive the formula for the density of $$r_t$$ by transforming the density of x. $$f_X (x;n,\lambda)=\frac{1}{2} e^{-\frac{x+\lambda}{2}} {\left( \frac{x}{\lambda}\right)}^{\frac{n-2}{4}} I_{\frac{n-2}{2}} \left( \sqrt{\lambda x} \right)$$

$$f_r (r;n,\lambda)= f_X (x^{-1}(r);n,\lambda) \left| \frac{dx}{dr}\right|$$

Where $$r=\frac{1}{2c} x \Rightarrow x=2c r \Rightarrow \frac{dx}{dr}=2c$$, and we get

$$f_r (r;n,\lambda)= 2 c f_X (2 c r;n,\lambda)$$ $$f_r (r;n,\lambda)= 2 c \frac{1}{2} e^{-\frac{x+\lambda}{2}} {\left( \frac{x}{\lambda}\right)}^{\frac{n-2}{4}} I_{\frac{n-2}{2}} \left( \sqrt{\lambda x} \right)$$ $$f_r (r;n,\lambda)= 2 c \frac{1}{2} e^{-\frac{2v+2u}{2}} {\left( \frac{2v}{2u}\right)}^{\frac{2q+2-2}{4}} I_{\frac{2q+2-2}{2}} \left( \sqrt{2u 2v} \right)$$ $$f_r (r;n,\lambda)= c e^{-(v+u)} {\left( \frac{v}{u}\right)}^{\frac{q}{2}} I_{q} \left( 2\sqrt{u v} \right)$$