Validation#

Checks of the LMM space against closed forms and martingale properties.

Every test returns a DataFrame with the columns

  • mc: the Monte Carlo estimate over the stochastic scenarios 1 to N,

  • theory: the value it should converge to,

  • se: its standard error, from antithetic pair means when antithetic variates are on,

  • z: \((\mathrm{mc} - \mathrm{theory}) / \mathrm{se}\).

With correct formulas, each z is roughly standard normal, so \(|z| > 3\) is rare for a single check. Tests that cover many months or rates contain many z-scores, so a larger maximum is expected by chance: summary() compares the largest \(|z|\) of each test with a limit that allows for the number of z-scores. Where the estimate is exact by construction, z is 0 (see mcstats.check).

The martingale tests check the deflated bonds, and so the interpolation between tenor dates. The caplet tests check the distribution of the forward rates, and with it the monthly step. swaption_test() is a diagnostic: its formula is an approximation.

The tests read the scenarios through the Reference lmm, so they run on whatever input the LMM space uses. Statistical power grows with scen_size; 10,000 antithetic scenarios is a good setting for validation.

lmm#

The LMM space.

mcstats#

User module with check(), which turns samples into the DataFrame above. Saved in the model folder as mcstats.py.

np#

The numpy module.

pd#

The pandas module.

stats#

The scipy.stats module, for the normal distribution.

Cells

caplet_cf(k, x)

Closed-form price of the caplet on \(F_k\) with strike x

caplet_mc(k, x)

Monte Carlo price of the caplet of caplet_cf(), against the closed form

caplet_test()

At-the-money caplets on the rates that expire at every whole year up to \(t_n\)

curve_fit_test()

Spot rates implied by the mean deflators against the input curve

fund_martingale_test()

Deflated value of the selected fund against 1, for every month

fwd_swap(a, b)

Forward swap rate \(S(0)\) and annuity \(A(0)\) of the b-year swap starting in a years

martingale_test()

Mean deflator against the initial curve, for every month

summary()

Largest \(|z|\) of each test on the current input, against its limit

swaption_test(a, b)

At-the-money payer swaption, Monte Carlo against the price from swaption_vol()

swaption_vol(a, b)

Black volatility of the forward swap rate plus \(\alpha\), by Rebonato's formula

zcb_martingale_test(i, j)

Deflated bond prices: \(E[D(t_i) P(t_i, t_j)] = P^M(0, t_j)\)

martingale_test()[source]#

Mean deflator against the initial curve, for every month

\(E[D(t_i)] = P^M(0, t_i)\) for i = 0 to n. In the first tenor period the deflators are known at time 0, so z is 0 there.

Returns:

pandas.DataFrame indexed by month t, columns mc, theory, se, z

fund_martingale_test()[source]#

Deflated value of the selected fund against 1, for every month

\(E[D(t_i) AV(t_i)/AV_0] = 1\) with \(AV(t_i)/AV_0 = \prod_{k<i}(1 + R^F_k)\), because the fund trades only bonds and the bank account. For an all-cash fund this holds in every scenario, so z is 0.

Returns:

pandas.DataFrame indexed by month t, columns mc, theory, se, z

curve_fit_test()[source]#

Spot rates implied by the mean deflators against the input curve

At each maturity of the selected curve that is a whole number of months no later than \(t_n\), the spot rate implied by the mean of \(D(t)\) (compounded as the input) against the input spot rate. The standard error comes from that of martingale_test() by the delta method. Where the deflator is known at time 0, in the first tenor period, z is 0, as in mcstats.check.

Returns:

pandas.DataFrame indexed by maturity in years, columns mc, theory, se, z

zcb_martingale_test(i, j)[source]#

Deflated bond prices: \(E[D(t_i) P(t_i, t_j)] = P^M(0, t_j)\)

Returns:

pandas.DataFrame with one row indexed by (i, j)

caplet_cf(k, x)[source]#

Closed-form price of the caplet on \(F_k\) with strike x

The caplet pays \(\tau(F_k(T_{k-1}) - x)^+\) at \(T_k\). Under the forward measure of \(T_k\), \(F_k + \alpha\) is lognormal with the Black volatility \(\sigma_k\) of lmm.caplet_vol, so Black’s formula with the shifted rate and strike gives, with \(v = \sigma_k\sqrt{T_{k-1}}\):

\[\begin{split}\mathrm{Cpl} = {} & \tau P^M(0, T_k)\left[(F_k(0) + \alpha)\Phi(d_1) - (x + \alpha)\Phi(d_1 - v)\right] \\ d_1 = {} & \frac{1}{v}\ln\frac{F_k(0) + \alpha}{x + \alpha} + \frac{v}{2}\end{split}\]

A strike at or below \(-\alpha\) is always exceeded, so the caplet is then worth \(\tau P^M(0, T_k)(F_k(0) - x)\).

caplet_mc(k, x)[source]#

Monte Carlo price of the caplet of caplet_cf(), against the closed form

The mean of the deflated payoffs \(D(T_k)\,\tau(F_k(T_{k-1}) - x)^+\). Needs the expiry \(T_{k-1}\) within the projection.

Returns:

pandas.DataFrame with one row indexed by (k, x)

caplet_test()[source]#

At-the-money caplets on the rates that expire at every whole year up to \(t_n\)

For each year y, the caplet on the rate \(F_k\) set at \(T_{k-1} = y\), with the strike \(F_k(0)\), against caplet_cf(). If the run is shorter than a year, the rates set at every tenor date up to \(t_n\). Together the caplets check the distribution of the rates, and with it the monthly step.

Returns:

pandas.DataFrame indexed by (k, expiry in years), columns mc, theory, se, z

fwd_swap(a, b)[source]#

Forward swap rate \(S(0)\) and annuity \(A(0)\) of the b-year swap starting in a years

The swap has a yearly fixed leg, paid at the anniversaries \(T_l\) from a + 1 to a + b years: \(A(0) = \sum_l P^M(0, T_l)\) and \(S(0) = (P^M(0, a) - P^M(0, a + b)) / A(0)\).

Returns:

tuple of the forward swap rate and the annuity

swaption_vol(a, b)[source]#

Black volatility of the forward swap rate plus \(\alpha\), by Rebonato’s formula

For the swaption that expires in a years on the b-year swap of fwd_swap(), with the forward rates \(F_j\) of the swap, j from \(a/\tau + 1\) to \((a + b)/\tau\), frozen at time 0 in the weights:

\[\begin{split}\sigma_S^2 a = {} & \sum_{i=0}^{12a - 1} \frac{1}{12} \left|\sum_j z_j\lambda((j-1)p - i)\right|^2 \\ z_j = {} & \frac{\partial S}{\partial F_j}\frac{F_j(0) + \alpha}{S(0) + \alpha}\end{split}\]

Brigo and Mercurio, section 6.15, with the shift and a fixed leg that pays less often than the tenor. It is an approximation; swaption_test() compares it with the Monte Carlo price.

swaption_test(a, b)[source]#

At-the-money payer swaption, Monte Carlo against the price from swaption_vol()

The deflated payoff at \(T_\alpha\) = a years is

\[\left(D(T_\alpha) - D(T_\alpha; T_\beta) - S(0)\sum_l D(T_\alpha; T_l)\right)^+\]

and the approximate price \(A(0)(S(0) + \alpha)(2\Phi(v/2) - 1)\), Black’s formula at the money with \(v = \sigma_S\sqrt{a}\). A diagnostic, not a test: the formula is an approximation, so its z-score need not be small.

Returns:

pandas.DataFrame with one row indexed by (a, b)

summary()[source]#

Largest \(|z|\) of each test on the current input, against its limit

Runs every test, with the deflated bond at \(t_i\), i = n // 2, maturing maturity_size months later. swaption_test() is left out, because its formula is an approximation.

A test with m z-scores passes if its largest \(|z|\) is below \(\Phi^{-1}(1 - 0.00135/m)\). That keeps the chance of a false alarm at that of a single 3-sigma check, 0.27%, if the z-scores were independent; positively correlated ones, such as those of neighbouring months, make it smaller still. The limit is 3 for a single check and about 4.5 for 600 months.

Returns:

pandas.DataFrame indexed by test, columns checks (number of z-scores), max_abs_z, limit, ok and at (the row of the largest \(|z|\))