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():
\(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()):
disc_factor_paths(): deflators \(D(t_i)\), for discounting cash flows at \(t_i\)fund_return_paths(): returns over \([t_i, t_{i+1})\) of the bond fund chosen byfund_id()bank_return_paths(): bank-account returns over \([t_i, t_{i+1})\)libor_rate_paths(),spot_rate_paths(): LIBOR rates and yields
- 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
|
Zero-coupon bond price \(P(t_i, t_j) = D(t_i; t_j) / D(t_i)\) by scenario |
Whether antithetic variates are used, from the |
|
Bank-account return \(R_i = D(t_i)/D(t_{i+1}) - 1\) over \([t_i, t_{i+1})\) by scenario |
|
Bank-account returns over \([t_i, t_{i+1})\) for every scenario and month |
|
|
Black volatility \(\sigma_k\) of \(F_k + \alpha\) up to its expiry \(T_{k-1}\), k >= 2 |
Bank-account return of the CE scenario, the one-month forward \(P^M(0, t_i)/P^M(0, t_{i+1}) - 1\) |
|
Deflator of the CE scenario, \(P^M(0, t_i)\) |
|
LIBOR rate of the CE scenario, the forward \((P^M(0, t_i)/P^M(0, t_{i+p}) - 1)/\tau\) |
|
|
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 of the input spot rates, |
|
|
Factor \(\kappa_j\) that fits the bond maturing at month j to the initial curve |
|
Column of the |
Knots of the selected initial curve |
|
Spot rates from the |
|
|
Deflated price \(D(t_i; T_k)\) of the bond maturing at the tenor date \(T_k\), by scenario |
|
Deflated price \(D(t_i; t_j)\) of the bond maturing at month \(j \ge i\), by scenario |
|
Deflator \(D(t_i)\), the reciprocal of the bank account, by scenario |
Deflators \(D(t_i)\) for every scenario and month |
|
Number d of factors, the factor columns of the |
|
Shares of the selected fund in zero-coupon bonds, by maturity in months |
|
Share of the selected fund held in the bank account (0 if it has no cash row) |
|
|
Column of the |
Market-value return \(R^F_i\) of the selected fund over \([t_i, t_{i+1})\), by scenario |
|
Returns of the selected fund over \([t_i, t_{i+1})\) for every scenario and month |
|
Fund shares from the |
|
|
Forward rates \(F_k(t_i)\), k = c+1 to K, by scenario, with \(c = \lfloor i/p \rfloor\) |
Path of the Excel input file |
|
|
LIBOR rate \(L(t_i)\), the simply compounded rate for the tenor from \(t_i\), by scenario |
LIBOR rates \(L(t_i)\) for every scenario and month |
|
Number of monthly bond maturities carried at every month, from the |
|
Initial forward rates \(F_k(0)\), k = 1 to K |
|
|
Initial discount factor \(P^M(0, t_i)\) |
Validated values from the |
|
Scenario IDs 0 to N, where 0 is the CE scenario |
|
Number of stochastic scenarios N, from the |
|
Deflators, returns and LIBOR rates for every scenario and month, in long format |
|
|
Seed of the random number generator, from the |
|
Shift \(\alpha\) of the forward rates, from the |
|
Annually compounded m-month yield at \(t_i\), \(P(t_i, t_{i+m})^{-12/m} - 1\), by scenario |
Annually compounded m-month yields for every scenario and month |
|
Standard normal random numbers for all steps, scenarios and factors |
|
Number of monthly steps n, from the |
|
|
k-year par rate at \(t_i\) with an annual fixed leg, by scenario |
|
Time \(t_i = i/12\) in years of month |
Deflator \(D(T_l)\) at the tenor date \(T_l\), by scenario |
|
Tenor p of the forward rates in months, from the |
|
Number K of forward rates |
|
Volatility vectors \(\lambda(m)\) of the forward rates by months to expiry |
|
Volatility of the forward rates from the |
|
|
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_fileresolved against the folder that contains the model folder, so the defaultlmm_input.xlsxsits next toBasicLMM/. An absoluteinput_fileis used as it is.- Returns:
pathlib.Path
- param_table()[source]#
Validated values from the
ParamssheetReads the
Paramssheet (columnsparameter,valueanddescription) ofinput_path(), converts each value to its type and checks it. RaisesValueErrorlisting every problem: a missing value or one of the wrong type,tenor_mthother than 1, 2, 3, 4, 6 or 12,shiftnegative or not below 12 /tenor_mth,maturity_sizebelowtenor_mth, sizes below 1, a negative seed, an oddscen_sizewithantitheticon, or acompoundingother thanannualorcontinuous.- Returns:
pandas.Series indexed by parameter name, with object dtype (values are float, int, bool or str)
- curve_table()[source]#
Spot rates from the
CurvesheetColumn
maturityholds maturities in years and every other column is a curve, named by its curve ID. A curve ends at its last non-blank row. RaisesValueErrorfor 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
VolsheetColumn
maturityholds 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. RaisesValueErrorfor 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
FundsheetColumn
maturityholds the years to maturity of zero-coupon bonds (a whole number of months), orcashfor the bank account. Every other column is a fund, named by its fund ID, holding its shares; a blank share is 0. RaisesValueErrorfor a maturity that is neithercashnor 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
Paramssheet\(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
ParamssheetThe 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
ParamssheetBonds that mature up to
maturity_sizemonths after a projection month are available at that month, for the fund and for yields:tenor_size()covers them.
- step_size()[source]#
Number of monthly steps n, from the
ParamssheetThe 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()).
- antithetic()[source]#
Whether antithetic variates are used, from the
ParamssheetIf
True, stochastic scenario k + N/2 uses the negated random numbers of scenario k. Seestd_norm_rand().
- tenor_size()[source]#
Number K of forward rates
The smallest K with \(Kp \ge n + \bar{m}\), where p is
tenor_mth(), n isstep_size()and \(\bar{m}\) ismaturity_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
ValueErrorifcurve_id()is not a column of theCurvesheet, 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. RaisesValueErrorfor \(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
ValueErrorif 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.
- 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
ValueErrorif 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. Withantithetic(), 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)\) fromstd_norm_rand()and \(\lambda_k = \lambda((k-1)p - i)\) fromvol_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)ismkt_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
ValueErrorfor a bond that matures after \(T_K\): raisematurity_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_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\)
Share of the selected fund held in the bank account (0 if it has no cash row)
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()andfund_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 columnsdisc_factor,bank_return_mth,fund_return_mthandlibor_rate
- t_(i)#
Time \(t_i = i/12\) in years of month
i