# HullWhite¶

The main Space in the BasicHullWhite model.

Mathematical notations are defined consistent with those in Brigo and Mercurio (2001, 2nd Ed. 2006)

• Damiano Brigo, Fabio Mercurio (2001, 2nd Ed. 2006). Interest Rate Models — Theory and Practice with Smile, Inflation and Credit

scen_size

Number of scenarios. 1000 by default.

np

numpy module.

step_size

Number of time steps. 360 by default.

time_len

Simulation length in years. 30 by default.

a

Parameter $$a$$ in the Hull-White stochastic differential equation. 0.1 by default.

sigma

Parameter $$\sigma$$ in the Hull-White stochastic differential equation. 0.1 by default.

seed1

Seed number to generate random numbers. 1234 by default. See std_norm_rand().

seed2

Seed for the second random numbers used for accum_short_rate2().

Cells

 A_t_T(i, j) $$A(t_i, t_j)$$ in $$P(t_i, t_j)$$ B_t_T(i, j) $$B(t_i, t_j)$$ in $$P(t_i, t_j)$$ The expected values of $$r(t_i)$$ at time 0 for all $$t_i$$. E_rt_s(i, j) Conditional expected values of $$r(t_j)$$ P_t_T(i, j) The price at $$t_i$$ of a zero-coupon bond paying off 1 at $$t_j$$ V_t_T(i, j) The variance of $$\int_{t_j}^{t_i} r(u)du|\mathcal{F}_{t_i}$$ The variance of $$r(t_i)$$ at time 0 for all $$t_i$$. Var_rt_s(i, j) The variance of $$r(t_j)$$ conditional on $$\mathcal{F}_{t_i}$$ Accumulated short rates. Alternative implementation of accumulated short rates. $$\alpha(t_i)$$ Discount factors Discount factor scenarios. Discount factor means The means of generated short rates The initial instantaneous forward rate for t_(i). The initial price of zero coupon bond Stochastic short rates at t_(i) Short rate paths. std_norm_rand([seed]) Random numbers from the standard normal distribution. t_(i) time index $$t_i$$ Variance of generated short rates
A_t_T(i, j)[source]

$$A(t_i, t_j)$$ in $$P(t_i, t_j)$$

B_t_T(i, j)[source]

$$B(t_i, t_j)$$ in $$P(t_i, t_j)$$

E_rt()[source]

The expected values of $$r(t_i)$$ at time 0 for all $$t_i$$.

Returns, in a numpy array, the expected values of $$r(t_i)$$ for all $$t_i$$. Calculated as $$E\{r(t_i) | \mathcal{F}_{0}\}$$.

E_rt_s(i, j)[source]

Conditional expected values of $$r(t_j)$$

Returns, in a numpy array, $$E\{r(t_j) | \mathcal{F}_{i}\}$$, the expected values of $$r(t_j)$$ conditional on $$\mathcal{F}_{i}$$ for all scenarios. $$E\{r(t) | \mathcal{F}_{s}\}$$ is calculated as:

$r(s)e^{-a(t-s)} + \alpha(t) - \alpha(s)e^{-a(t-s)}$

where $$\alpha(t)$$ is calculated by alpha().

P_t_T(i, j)[source]

The price at $$t_i$$ of a zero-coupon bond paying off 1 at $$t_j$$

This formula corresponds to $$P(t, T)$$ in Brigo and Mercurio, which is defined as:

$P(t, T)=A(t, T)e^{-B(t, T)r(t)}$

where $$t_i$$ and $$t_j$$ substitute for $$t$$ and $$T$$.

V_t_T(i, j)[source]

The variance of $$\int_{t_j}^{t_i} r(u)du|\mathcal{F}_{t_i}$$

This formula corresponds to $$V(t, T)$$ in Brigo and Mercurio, which is defined as:

$V(t, T)=\frac{\sigma^2}{a^2}\left[T-t+\frac{2}{a}e^{-a(T-t)}-\frac{1}{2a}e^{-2a(T-t)}-\frac{3}{2a}\right]$

where $$t_i$$ and $$t_j$$ substitute for $$t$$ and $$T$$.

• sigma for $$\sigma$$

• a for $$a$$

• Brigo and Mercurio (2001, 2nd Ed. 2006). Interest Rate Models — Theory and Practice with Smile, Inflation and Credit

Var_rt()[source]

The variance of $$r(t_i)$$ at time 0 for all $$t_i$$.

Returns, in a numpy array, the variance of $$r(t_i)$$ for all $$t_i$$. Calculated as $$Var\{r(t_i) | \mathcal{F}_{0}\}$$.

Var_rt_s(i, j)[source]

The variance of $$r(t_j)$$ conditional on $$\mathcal{F}_{t_i}$$

$$Var\{r(t_{j}) | \mathcal{F}_{t_i}\}$$, the variance of $$r(t_j)$$ conditional on $$\mathcal{F}_{t_i}$$, calculated as:

$Var\{ r(t) | \mathcal{F}_s \} = \frac{\sigma^2}{2a} (1 - e^{-2a(t-s)})$

accum_short_rate(i)[source]

Accumulated short rates.

a descrete approximation to the integral $$\int_0^{t_i}r(t)dt$$, calculated as $$\sum_{j=1}^{i}r(t_{j-1})(t_j-t_{j-1})$$

accum_short_rate2(i)[source]

Alternative implementation of accumulated short rates.

An alternative approach to simulate $$Y(t_i)=\int_0^{t_i}r(t)dt$$ by using the fact that $$Y(t_i)$$ follows a normal distribution, and by simulating the joint distribution of $$(r(t_i), Y(t_i))$$, as suggested in Glasserman (2003).

alpha(i)[source]

$$\alpha(t_i)$$

Returns, in a numpy array, $$\alpha(t_i)$$ for all scenarios. $$\alpha$$ appears in the expression of $$E\{r(t) | \mathcal{F}_{s}\}$$ and is defined as:

$\alpha(t) = f^M(0, t) + \frac{\sigma^2} {2a^2}(1-e^{-at})^2$

disc_factor(i)[source]

Discount factors

Returns, in a numpy array, the discount factors for cashflows at $$t_i$$ for all scenarios. Defined as:

np.exp(-accum_short_rate(i))


• accum_short_rate

disc_factor_paths()[source]

Discount factor scenarios.

Returns, as a 2D numpy array, the simulated discount factors for all scenarios.

mean_disc_factor()[source]

Discount factor means

Returns, as a numpy array, the mean of discount factors of all scenarios for each $$t_i$$.

mean_short_rate()[source]

The means of generated short rates

Returns, as a numpy array, the means of short rates of all scenarios for all $$t_i$$. This should converge to the theoretical variances calculated by E_rt().

mkt_fwd(i)[source]

The initial instantaneous forward rate for t_(i).

By default, returns 0.05 for all i.

mkt_zcb(i)[source]

The initial price of zero coupon bond

The initial price of the unit zero coupon bond maturing at t_(i).

If i=0 returns 1. Otherwise, defined as:

mkt_zcb(i-1) * np.exp(-mkt_fwd(i-1)*dt)


where dt = t_(i) - t_(i-1).

short_rate(i)[source]

Stochastic short rates at t_(i)

Returns, in a numpy array, simulated stochastic short rates at t_(i) for all scenarios.

For i=0, defined as mkt_fwd(0).

For i>0, defined as $$r(t_i) = E\{r(t_i) | \mathcal{F}_{i-1}\} + \sqrt{Var\{ r(t_i) | \mathcal{F}_{i-1} \}} * Z$$,

where $$E\{r(t_i) | \mathcal{F}_{i-1}\}$$, the expected value of $$r(t_i)$$ conditional on $$\mathcal{F}_{i-1}$$ is calculated by E_rt_s(i-1, i), $$Var\{ r(t_i) | \mathcal{F}_{i-1} \}$$ the variance of $$r(t_i)$$ conditional on $$\mathcal{F}_{i-1}$$ is calculated by Var_rt_s(i-1, i), and $$Z$$, a random number drawn from $$\mathcal{N}(0, 1)$$ a standard normal distribution calculated by std_norm_rand().

short_rate_paths()[source]

Short rate paths.

Returns, as a 2D numpy array, the simulated short rate paths for all scenarios.

std_norm_rand(seed=1234)[source]

Random numbers from the standard normal distribution.

Returns a numpy array shaped scen_size x step_size. The elements are random numbers drawn from the standard normal distribution.

t_(i)

time index $$t_i$$

var_short_rate()[source]

Variance of generated short rates

Returns, as a vector in a numpy array, the variances of the generated short rates for all $$t_i$$. This should converge to the theoretical variances calculated by Var_rt().