LMM#

Monthly LMM interest rate scenarios fitted to an initial curve.

The LIBOR market model (Brigo and Mercurio, 2nd ed. 2006, chapter 6), with the shift of their section 10.1, under the spot-LIBOR measure. The forward rate \(F_k\) covers the period \((T_{k-1}, T_k]\) between the tenor dates \(T_k = k\tau\), where \(\tau\) is tenor_mth() months, and \(F_k + \alpha\) is lognormal, where \(\alpha\) is shift():

\[\begin{split}\frac{d(F_k + \alpha)}{F_k + \alpha} = {} & \lambda_k \cdot \sum_{j=\beta(t)}^{k} \frac{\tau(F_j + \alpha)}{1 + \tau F_j}\lambda_j\,dt \\ & + \lambda_k \cdot dW(t)\end{split}\]

\(W\) is a Brownian motion with as many dimensions as the volatility table has factors, \(\lambda_k\) the volatility vector of \(F_k\), and \(\beta(t)\) the first rate not yet set at \(t\). The rates start from the forward rates of the initial curve \(P^M(0, t)\) and move every month by a log-Euler step (fwd_rates()). Bonds that mature on tenor dates are products of the rates, and bonds of every other monthly maturity are interpolated between them (defl_zcb()), so the deflators reproduce the initial curve up to Monte Carlo noise. Time is in years, and month i is \(t_i = i/12\) (t_()). N is scen_size(), n is step_size(), p is tenor_mth(), K is tenor_size() and d is factor_size().

Inputs are read at run time from the Excel file input_file, located next to the model folder: sheet Params (the shift, the tenor and the run settings), sheet Curve (initial spot rates by maturity, one column per curve ID), sheet Vol (the volatility of the forward rates by time to expiry, one column per factor) and sheet Fund (shares of bond funds by years to maturity). Neither the curve nor the volatility table is extrapolated, so they must reach every maturity a run needs. After editing the file in place, call clear_all() on the model; assigning another input_file recalculates automatically.

Outputs for liability models are arrays with one row per scenario, named and shaped as in BasicG2PP. Row 0 is the certainty-equivalent (CE) scenario, which follows the initial forward curve, and row k is stochastic scenario k (see scen_index()):

input_file#

Name of the Excel input file, relative to the folder that contains the model folder, or an absolute path. "lmm_input.xlsx" by default.

dt#

Length of a monthly step in years, 1/12.

np#

The numpy module.

pd#

The pandas module.

See also

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

  • Erik Schlögl (2002). Arbitrage-free interpolation in models of market observable interest rates. In K. Sandmann and P. Schönbucher (eds), Advances in Finance and Stochastics

Cells

P_t_T(i, j)

Zero-coupon bond price \(P(t_i, t_j) = D(t_i; t_j) / D(t_i)\) by scenario

antithetic()

Whether antithetic variates are used, from the Params sheet

bank_return_mth(i)

Bank-account return \(R_i = D(t_i)/D(t_{i+1}) - 1\) over \([t_i, t_{i+1})\) by scenario

bank_return_paths()

Bank-account returns over \([t_i, t_{i+1})\) for every scenario and month

caplet_vol(k)

Black volatility \(\sigma_k\) of \(F_k + \alpha\) up to its expiry \(T_{k-1}\), k >= 2

ce_bank_return_mth(i)

Bank-account return of the CE scenario, the one-month forward \(P^M(0, t_i)/P^M(0, t_{i+1}) - 1\)

ce_disc_factor(i)

Deflator of the CE scenario, \(P^M(0, t_i)\)

ce_libor_rate(i)

LIBOR rate of the CE scenario, the forward \((P^M(0, t_i)/P^M(0, t_{i+p}) - 1)/\tau\)

ce_spot_rate(i, m)

Annually compounded m-month yield at \(t_i\) in the CE scenario, \((P^M(0, t_i)/P^M(0, t_{i+m}))^{12/m} - 1\)

compounding()

Compounding of the input spot rates, "annual" or "continuous"

curve_adj(j)

Factor \(\kappa_j\) that fits the bond maturing at month j to the initial curve

curve_id()

Column of the Curve sheet to use, from the Params sheet

curve_knots()

Knots of the selected initial curve

curve_table()

Spot rates from the Curve sheet

defl_tenor_zcb(i, k)

Deflated price \(D(t_i; T_k)\) of the bond maturing at the tenor date \(T_k\), by scenario

defl_zcb(i, j)

Deflated price \(D(t_i; t_j)\) of the bond maturing at month \(j \ge i\), by scenario

disc_factor(i)

Deflator \(D(t_i)\), the reciprocal of the bank account, by scenario

disc_factor_paths()

Deflators \(D(t_i)\) for every scenario and month

factor_size()

Number d of factors, the factor columns of the Vol sheet

fund_bond_shares()

Shares of the selected fund in zero-coupon bonds, by maturity in months

fund_cash_share()

Share of the selected fund held in the bank account (0 if it has no cash row)

fund_id()

Column of the Fund sheet to use, from the Params sheet

fund_return_mth(i)

Market-value return \(R^F_i\) of the selected fund over \([t_i, t_{i+1})\), by scenario

fund_return_paths()

Returns of the selected fund over \([t_i, t_{i+1})\) for every scenario and month

fund_table()

Fund shares from the Fund sheet

fwd_rates(i)

Forward rates \(F_k(t_i)\), k = c+1 to K, by scenario, with \(c = \lfloor i/p \rfloor\)

input_path()

Path of the Excel input file

libor_rate(i)

LIBOR rate \(L(t_i)\), the simply compounded rate for the tenor from \(t_i\), by scenario

libor_rate_paths()

LIBOR rates \(L(t_i)\) for every scenario and month

maturity_size()

Number of monthly bond maturities carried at every month, from the Params sheet

mkt_fwd_rates()

Initial forward rates \(F_k(0)\), k = 1 to K

mkt_zcb(i)

Initial discount factor \(P^M(0, t_i)\)

param_table()

Validated values from the Params sheet

scen_index()

Scenario IDs 0 to N, where 0 is the CE scenario

scen_size()

Number of stochastic scenarios N, from the Params sheet

scenario_table()

Deflators, returns and LIBOR rates for every scenario and month, in long format

seed()

Seed of the random number generator, from the Params sheet

shift()

Shift \(\alpha\) of the forward rates, from the Params sheet

spot_rate(i, m)

Annually compounded m-month yield at \(t_i\), \(P(t_i, t_{i+m})^{-12/m} - 1\), by scenario

spot_rate_paths(m)

Annually compounded m-month yields for every scenario and month

std_norm_rand()

Standard normal random numbers for all steps, scenarios and factors

step_size()

Number of monthly steps n, from the Params sheet

swap_rate(i, k)

k-year par rate at \(t_i\) with an annual fixed leg, by scenario

t_(i)

Time \(t_i = i/12\) in years of month i

tenor_disc_factor(l)

Deflator \(D(T_l)\) at the tenor date \(T_l\), by scenario

tenor_mth()

Tenor p of the forward rates in months, from the Params sheet

tenor_size()

Number K of forward rates

vol_loadings()

Volatility vectors \(\lambda(m)\) of the forward rates by months to expiry

vol_table()

Volatility of the forward rates from the Vol sheet

zcb_return_mth(i, m)

Return over \([t_i, t_{i+1})\) of a zero-coupon bond with m months to maturity at \(t_i\), by scenario

input_path()[source]#

Path of the Excel input file

input_file resolved against the folder that contains the model folder, so the default lmm_input.xlsx sits next to BasicLMM/. An absolute input_file is used as it is.

Returns:

pathlib.Path

param_table()[source]#

Validated values from the Params sheet

Reads the Params sheet (columns parameter, value and description) of input_path(), converts each value to its type and checks it. Raises ValueError listing every problem: a missing value or one of the wrong type, tenor_mth other than 1, 2, 3, 4, 6 or 12, shift negative or not below 12 / tenor_mth, maturity_size below tenor_mth, sizes below 1, a negative seed, an odd scen_size with antithetic on, or a compounding other than annual or continuous.

Returns:

pandas.Series indexed by parameter name, with object dtype (values are float, int, bool or str)

curve_table()[source]#

Spot rates from the Curve sheet

Column maturity holds maturities in years and every other column is a curve, named by its curve ID. A curve ends at its last non-blank row. Raises ValueError for maturities that are not positive and increasing, or a blank inside a curve.

Returns:

pandas.DataFrame indexed by maturity (years), one float column per curve ID

vol_table()[source]#

Volatility of the forward rates from the Vol sheet

Column maturity holds times to expiry in years, and every other column is a factor. A row is the volatility vector of a forward rate with that time to expiry: its length is the rate’s volatility, and the angle between two rows gives the correlation of two rates. Raises ValueError for times to expiry that are negative or not increasing, a sheet with no factor column, or a value that is blank or not a number.

Returns:

pandas.DataFrame indexed by maturity (years), one float column per factor

fund_table()[source]#

Fund shares from the Fund sheet

Column maturity holds the years to maturity of zero-coupon bonds (a whole number of months), or cash for the bank account. Every other column is a fund, named by its fund ID, holding its shares; a blank share is 0. Raises ValueError for a maturity that is neither cash nor a positive whole number of months, a repeated maturity, a negative share, or a fund whose shares do not sum to 1 within 1e-9.

Returns:

pandas.DataFrame indexed by maturity ("cash" or years), one float column per fund ID

shift()[source]#

Shift \(\alpha\) of the forward rates, from the Params sheet

\(F_k + \alpha\) is lognormal, so the forward rates stay above \(-\alpha\). A shift of 0 gives the lognormal LMM.

tenor_mth()[source]#

Tenor p of the forward rates in months, from the Params sheet

The tenor dates are \(T_k = t_{kp}\), and \(\tau = p/12\) years. p is 1, 2, 3, 4, 6 or 12, so every anniversary is a tenor date.

maturity_size()[source]#

Number of monthly bond maturities carried at every month, from the Params sheet

Bonds that mature up to maturity_size months after a projection month are available at that month, for the fund and for yields: tenor_size() covers them.

scen_size()[source]#

Number of stochastic scenarios N, from the Params sheet

step_size()[source]#

Number of monthly steps n, from the Params sheet

The projection runs from month 0 to month n. The forward rates cover n plus maturity_size() months, so the curve must reach the tenor date that ends them, \(T_K\) (tenor_size()).

seed()[source]#

Seed of the random number generator, from the Params sheet

antithetic()[source]#

Whether antithetic variates are used, from the Params sheet

If True, stochastic scenario k + N/2 uses the negated random numbers of scenario k. See std_norm_rand().

curve_id()[source]#

Column of the Curve sheet to use, from the Params sheet

compounding()[source]#

Compounding of the input spot rates, "annual" or "continuous"

fund_id()[source]#

Column of the Fund sheet to use, from the Params sheet

tenor_size()[source]#

Number K of forward rates

The smallest K with \(Kp \ge n + \bar{m}\), where p is tenor_mth(), n is step_size() and \(\bar{m}\) is maturity_size(): the rates cover every bond maturity that a run needs. The curve must reach the last tenor date \(T_K\).

curve_knots()[source]#

Knots of the selected initial curve

The maturities \(t_k\) of the curve curve_id() and the log discount factors \(\ln P^M(0, t_k) = -t_k \ln(1 + s_k)\) for annually compounded spot rates \(s_k\), or \(-t_k s_k\) for continuously compounded ones. Both arrays start with the knot \(t = 0\), \(\ln P^M(0, 0) = 0\).

Raises ValueError if curve_id() is not a column of the Curve sheet, or if the curve ends before the last tenor date \(T_K\) (tenor_size()). The curve is not extrapolated.

Returns:

tuple of two 1-D numpy arrays of equal length, the knot times and the log discount factors

mkt_zcb(i)[source]#

Initial discount factor \(P^M(0, t_i)\)

\(\ln P^M(0, t)\) is interpolated linearly in \(t\) between the knots of curve_knots(), so instantaneous forwards are flat between knots. Raises ValueError for \(t_i\) past the last maturity: the curve is not extrapolated.

mkt_fwd_rates()[source]#

Initial forward rates \(F_k(0)\), k = 1 to K

\[F_k(0) = \frac{1}{\tau}\left(\frac{P^M(0, T_{k-1})}{P^M(0, T_k)} - 1\right)\]

Raises ValueError if a rate is not above \(-\alpha\), the lower bound of the shifted-lognormal rates, and names the shift it needs.

Returns:

numpy array of shape (K,)

curve_adj(j)[source]#

Factor \(\kappa_j\) that fits the bond maturing at month j to the initial curve

For \(j = lp + r\) with \(0 \le r < p\) and \(w = r/p\):

\[\kappa_j = \frac{P^M(0, t_j)}{(1 - w)P^M(0, T_l) + wP^M(0, T_{l+1})}\]

\(\kappa_j\) is 1 on tenor dates. On the example curves it stays within 1.5e-4 of 1 with a tenor of 12 months.

factor_size()[source]#

Number d of factors, the factor columns of the Vol sheet

vol_loadings()[source]#

Volatility vectors \(\lambda(m)\) of the forward rates by months to expiry

Row m is the volatility vector of a forward rate with m months to its expiry at the start of a month, read from vol_table() at the middle of that month, \(u = (m - \frac{1}{2})/12\) years: linear between the rows of the table, and flat before its first row. Row 0, a rate at its expiry, is 0. A rate’s volatility vector is constant within each month, so caplet volatilities are exact sums (caplet_vol()).

Raises ValueError if the table ends before the longest time to expiry of the run, \(((K-1)p - \frac{1}{2})/12\) years. The table is not extrapolated.

Returns:

numpy array of shape ((K-1)p + 1, d)

caplet_vol(k)[source]#

Black volatility \(\sigma_k\) of \(F_k + \alpha\) up to its expiry \(T_{k-1}\), k >= 2

\[\sigma_k^2 T_{k-1} = \frac{1}{12}\sum_{m=1}^{(k-1)p} |\lambda(m)|^2\]

A caplet on \(F_k\) with strike \(x\) is then worth \(\tau P^M(0, T_k)\,\mathrm{Black}(F_k(0) + \alpha, x + \alpha, \sigma_k)\).

std_norm_rand()[source]#

Standard normal random numbers for all steps, scenarios and factors

Drawn by numpy.random.default_rng(seed()) in step-major order, so a longer projection leaves earlier months unchanged. With antithetic(), the first N/2 scenarios are drawn and the rest are their negatives.

Returns:

numpy array of shape (n, N, d)

fwd_rates(i)[source]#

Forward rates \(F_k(t_i)\), k = c+1 to K, by scenario, with \(c = \lfloor i/p \rfloor\)

Column 0 is \(F_{c+1}\), the rate of the current tenor period, set at \(T_c\). The other columns are the rates not yet set. Each month they take a log-Euler step, with \(\Delta\) = dt, \(Z \sim N(0, I_d)\) from std_norm_rand() and \(\lambda_k = \lambda((k-1)p - i)\) from vol_loadings():

\[\begin{split}\ln(F_k(t_{i+1}) + \alpha) = {} & \ln(F_k(t_i) + \alpha) + \left(\mu_k - \tfrac{1}{2}|\lambda_k|^2\right)\Delta \\ & + \sqrt{\Delta}\,\lambda_k \cdot Z \\ \mu_k = {} & \lambda_k \cdot \sum_{j=c+2}^{k} \frac{\tau(F_j(t_i) + \alpha)}{1 + \tau F_j(t_i)}\lambda_j\end{split}\]

The rates stay above \(-\alpha\). On a tenor date, the rate of the period just ended is dropped. fwd_rates(0) is mkt_fwd_rates() in every scenario.

Returns:

numpy array of shape (N, K - c)

tenor_disc_factor(l)[source]#

Deflator \(D(T_l)\) at the tenor date \(T_l\), by scenario

\[D(T_l) = \prod_{j=1}^{l} \frac{1}{1 + \tau F_j(T_{j-1})}\]

It is known at \(T_{l-1}\), when \(F_l\) is set.

Returns:

numpy array of shape (N,)

defl_tenor_zcb(i, k)[source]#

Deflated price \(D(t_i; T_k)\) of the bond maturing at the tenor date \(T_k\), by scenario

For \(c = \lfloor i/p \rfloor \le k \le K\):

\[D(t_i; T_k) = \frac{P(t_i, T_k)}{B_d(t_i)} = D(T_c)\prod_{j=c+1}^{k}\frac{1}{1 + \tau F_j(t_i)}\]

where \(B_d\) is the bank account of the spot-LIBOR measure, and \(D(T_c)\) is tenor_disc_factor(). Each is a martingale, and once \(T_k\) has passed it is the deflator \(D(T_k)\).

Returns:

numpy array of shape (N,)

defl_zcb(i, j)[source]#

Deflated price \(D(t_i; t_j)\) of the bond maturing at month \(j \ge i\), by scenario

For \(j = lp + r\) with \(0 \le r < p\) and \(w = r/p\), the price is linear in maturity between those of the two tenor bonds, times curve_adj():

\[D(t_i; t_j) = \kappa_j\left[(1 - w)D(t_i; T_l) + wD(t_i; T_{l+1})\right]\]

This is Schlögl’s (2002) interpolation, in which a bond that matures within the current tenor period has no volatility. As a fixed combination of martingales, it is a martingale, and \(\kappa_j\) makes it start at \(P^M(0, t_j)\).

Raises ValueError for a bond that matures after \(T_K\): raise maturity_size() to carry it.

Returns:

numpy array of shape (N,)

disc_factor(i)[source]#

Deflator \(D(t_i)\), the reciprocal of the bank account, by scenario

The deflated price of the bond that matures at \(t_i\), \(D(t_i) = D(t_i; t_i)\) (defl_zcb()), so that \(E[D(t_i)] = P^M(0, t_i)\).

Returns:

numpy array of shape (N,)

bank_return_mth(i)[source]#

Bank-account return \(R_i = D(t_i)/D(t_{i+1}) - 1\) over \([t_i, t_{i+1})\) by scenario

The deflated price of a bond does not change in its last month, so \(R_i = 1/P(t_i, t_{i+1}) - 1\) is known at \(t_i\).

Returns:

numpy array of shape (N,)

P_t_T(i, j)[source]#

Zero-coupon bond price \(P(t_i, t_j) = D(t_i; t_j) / D(t_i)\) by scenario

Needs \(t_j\) no later than \(T_K\).

Returns:

numpy array of shape (N,)

libor_rate(i)[source]#

LIBOR rate \(L(t_i)\), the simply compounded rate for the tenor from \(t_i\), by scenario

\[L(t_i) = \frac{1}{\tau}\left(\frac{1}{P(t_i, t_{i+p})} - 1\right)\]

On a tenor date \(T_c\) it is the rate just set, \(F_{c+1}(T_c)\).

Returns:

numpy array of shape (N,)

spot_rate(i, m)[source]#

Annually compounded m-month yield at \(t_i\), \(P(t_i, t_{i+m})^{-12/m} - 1\), by scenario

Returns:

numpy array of shape (N,)

swap_rate(i, k)[source]#

k-year par rate at \(t_i\) with an annual fixed leg, by scenario

\[\frac{1 - P(t_i, t_i + k)}{\sum_{l=1}^{k} P(t_i, t_i + l)}\]
Returns:

numpy array of shape (N,)

ce_disc_factor(i)[source]#

Deflator of the CE scenario, \(P^M(0, t_i)\)

ce_bank_return_mth(i)[source]#

Bank-account return of the CE scenario, the one-month forward \(P^M(0, t_i)/P^M(0, t_{i+1}) - 1\)

ce_libor_rate(i)[source]#

LIBOR rate of the CE scenario, the forward \((P^M(0, t_i)/P^M(0, t_{i+p}) - 1)/\tau\)

ce_spot_rate(i, m)[source]#

Annually compounded m-month yield at \(t_i\) in the CE scenario, \((P^M(0, t_i)/P^M(0, t_{i+m}))^{12/m} - 1\)

fund_cash_share()[source]#

Share of the selected fund held in the bank account (0 if it has no cash row)

fund_bond_shares()[source]#

Shares of the selected fund in zero-coupon bonds, by maturity in months

Bonds with a zero share are left out. Their longest maturity must not exceed maturity_size().

Returns:

pandas.Series of floats indexed by maturity in months (int)

zcb_return_mth(i, m)[source]#

Return over \([t_i, t_{i+1})\) of a zero-coupon bond with m months to maturity at \(t_i\), by scenario

The bond is bought at \(t_i\) and sold a month later. With \(T = t_{i+m}\):

\[\frac{P(t_{i+1}, T)}{P(t_i, T)} - 1 = (1 + R_i)\frac{D(t_{i+1}; T)}{D(t_i; T)} - 1\]
Returns:

numpy array of shape (N,)

fund_return_mth(i)[source]#

Market-value return \(R^F_i\) of the selected fund over \([t_i, t_{i+1})\), by scenario

The fund holds the bank account and zero-coupon bonds in the shares of fund_cash_share() and fund_bond_shares(), sells the bonds after a month and rebalances to the same shares:

\[R^F_i = w_c R_i + \sum_m w_m \left[\frac{P(t_{i+1}, t_{i+m})}{P(t_i, t_{i+m})} - 1\right]\]
Returns:

numpy array of shape (N,)

scen_index()[source]#

Scenario IDs 0 to N, where 0 is the CE scenario

Returns:

pandas.RangeIndex named scen_id

disc_factor_paths()[source]#

Deflators \(D(t_i)\) for every scenario and month

Returns:

numpy array of shape (N+1, n+1); row 0 is the CE scenario

bank_return_paths()[source]#

Bank-account returns over \([t_i, t_{i+1})\) for every scenario and month

Returns:

numpy array of shape (N+1, n); row 0 is the CE scenario

fund_return_paths()[source]#

Returns of the selected fund over \([t_i, t_{i+1})\) for every scenario and month

In the CE scenario every bond earns the one-month forward, so row 0 is the CE bank-account return whatever the fund’s shares.

Returns:

numpy array of shape (N+1, n); row 0 is the CE scenario

libor_rate_paths()[source]#

LIBOR rates \(L(t_i)\) for every scenario and month

Returns:

numpy array of shape (N+1, n+1); row 0 is the CE scenario

spot_rate_paths(m)[source]#

Annually compounded m-month yields for every scenario and month

Needs m no longer than maturity_size().

Returns:

numpy array of shape (N+1, n+1); row 0 is the CE scenario

scenario_table()[source]#

Deflators, returns and LIBOR rates for every scenario and month, in long format

For inspection and export to CSV or npz. The returns over the month after \(t_n\) are NaN.

Returns:

pandas.DataFrame indexed by (scen_id, t) with columns disc_factor, bank_return_mth, fund_return_mth and libor_rate

t_(i)#

Time \(t_i = i/12\) in years of month i