# How do I pricing a ZCB using CIR (Cox-Ingersoll-Ross) model

My question is about input parameters (a, b and sigma)and their calculation.

For the long term mean "b", do we use effective Fed Fund rates? or 3m T-bills?

Also, how do I calculate the mean reversion speed 'a'?


import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import math

import timeit

start = timeit.default_timer()

def inst_to_ann(r):
return np.expm1(r)

def ann_to_inst(r):
return np.log1p(r)

def cir(n_years = 1, n_scenarios=1, a=0.05, b=0.03, sigma=0.05, steps_per_year=52, r_0=None):

if r_0 is None: r_0 = b
r_0 = ann_to_inst(r_0)
dt = 1/ steps_per_year
num_steps = int(n_years * steps_per_year) + 1  # because n_years might be a float

I = np.random.normal(0, scale=np.sqrt(dt), size=(num_steps, n_scenarios))
rates = np.empty_like(I)
rates[0] = r_0

## For Price Generation
h = math.sqrt(a ** 2 + 2 * sigma ** 2)
prices = np.empty_like(I)

def price(ttm, r):
_A = ((2 * h * math.exp((h + a) * ttm / 2)) / (2 * h + (h + a) * (math.exp(h * ttm) - 1))) ** (
2 * a * b / sigma ** 2)
_B = (2 * (math.exp(h * ttm) - 1)) / (2 * h + (h + a) * (math.exp(h * ttm) - 1))
_P = _A * np.exp(-_B * r)
return _P

prices[0] = price(n_years, r_0)

for step in range(1, num_steps):
r_t = rates[step - 1]
d_r_t = a * (b - r_t) * dt + sigma * np.sqrt(r_t) * I[step]
rates[step] = abs(r_t + d_r_t)
# generate prices at time t as well ...
prices[step] = price(n_years - step * dt, rates[step])

rates = pd.DataFrame(data=inst_to_ann(rates), index=range(num_steps))
### for prices
prices = pd.DataFrame(data=prices, index=range(num_steps))

return rates, prices

dfrates,dfprices = cir(n_scenarios=1000)
dfprices.plot()
plt.show()

print(dfprices)

stop = timeit.default_timer()
print('Time: ', stop - start)


# Monte Carlo simulation for pricing a zero coupon bond

To assess the value $$V_t$$ of a zero coupon bond $$B_{T, t}$$ issued today at time $$t$$ with expiry at time $$T$$, you can do so using the formula $$V_t = \mathbb{E}\left(\exp\left(-\int_t^T r_s \mathrm{d}s\right)\underbrace{B_{T, T}}_{=1}\right).$$ Now if you're using the CIR model the nice thing is that the distribution of $$r_T$$ given $$r_t$$ is known (it's a non-central $$\chi^2$$), and hence you can use the relation $$r_T = r_s + \int_t^T r_s \mathrm{d}s,$$ and re-arrange this to know the distribution of $$\int_t^T r_s \mathrm{d}s$$.

### Don't use the Euler-Maruyama scheme if you know the exact distribution

As we know the exact distribution of $$\int_t^T r_s \mathrm{d}s$$, there is no-need to use the Euler-Maruyama scheme to approximate a sample from this, as an exact sample can be drawn. This then makes using Monte Carlo to compute the expectation much easier (albeit the non-central $$\chi^2$$ is not cheap!), and thus pricing a zero coupon bond easy.

# Calibrating the model

You ask how to find the values for $$a$$, and what to use for $$b$$. The best way to do this is to calibrate your model, which is a trickier question, which I will let other answers address.

• thanks @oliversm
– TRex
Sep 8 '20 at 14:45

For the long term mean "b", do we use effective Fed Fund rates? or 3m T-bills?

I don't think so. For this particular short rate model, you have to provide 3 input parameters, namely: $$a$$, $$b$$ and $$\sigma$$ (using your notation).

I believe that $$a$$ and $$b$$ are obtained by fitting the current term structure of zero coupon bonds $$P^M(0,T)$$ present in the market and $$\sigma$$ comes from swaption prices.

For example, the Gaussian Short Rate model (GSR) has an analytical expression for $$b(t)$$, that depends on derivatives of $$P^M(0,T)$$, by means of the forward instantaneous rate $$f(0, T)$$ and its derivative. On the other hand, the CIR model does not have such analytical result.

Constructing $$P(0, T)$$ and $$f(0, T)$$ is a whole subject itself (commonly referred as bootstrapping the yield curve). I can elaborate on this if it is desired.

Hope it helps! Thanks!

• thanks @rvignolo, but isn't CIR an equilibrium model (as opposed to the non -arbitrage models HO-Lee or HullWhite where your input to the model is the current term structure?)
– TRex
Sep 8 '20 at 14:47
• Sorry, I missed your question! I believe that the Hull-White model is a one factor short rate model of Affine class, such as the CIR model and many others. In this context, it should be as well calibrated to fit the current term structure of the ZCB market prices. Finding that term structure is not simple: you have to bootstrap it from prices of deposits, forward rate agreements, swaps and other securities in the market! Sep 11 '20 at 13:00