Regulatory capital#

Compute the regulatory capital of credit exposures under the internal ratings-based approach. asset_correlation() and capital_requirement() evaluate the risk-weight functions of the Basel framework and of China’s 2023 capital rules, conditional_pd(), systematic_factor() and vasicek_fit() work with the one-factor model behind them, and most_prudent_pd() bounds the PDs of a portfolio with few defaults.

See Regulatory capital for examples and the parameters of both jurisdictions.

asset_correlation(probability, *, asset_class)

Compute the asset correlation of the IRB risk-weight function.

capital_requirement(probability, lgd, *, ...)

Compute the capital requirement K of the IRB approach, as a share of the exposure.

conditional_pd(probability, *, correlation)

Compute the PD of the one-factor model given the state of the economy.

systematic_factor(default_rate, probability, ...)

Compute the systematic factor that an observed default rate implies.

vasicek_fit(default_rate)

Estimate the long-run PD and the asset correlation from a series of default rates.

most_prudent_pd(event, total, *[, level, ...])

Compute the most prudent upper bounds of Pluto and Tasche for the PD of each grade.

kivi.capital.asset_correlation(probability, *, asset_class, turnover=None, turnover_range=(5.0, 50.0), financial=False)#

Compute the asset correlation of the IRB risk-weight function.

The asset correlation \(R\) is the share of the variance of a borrower’s assets that the economy as a whole explains. The IRB approach fixes it by asset class, falling with the PD for corporate exposures and for other retail exposures.

Parameters:
probabilityarray_like

Probabilities of default, from 0 to 1. Missing values give missing correlations.

asset_class{“corporate”, “hvcre”, “mortgage”, “revolving”, “other_retail”}

"corporate" for corporate, sovereign and bank exposures, "hvcre" for high-volatility commercial real estate, "mortgage" for residential mortgages, "revolving" for qualifying revolving retail exposures and "other_retail" for other retail exposures.

turnoverarray_like, optional

Annual sales of each corporate borrower, in the units of turnover_range, such as millions of euros. Values below the upper bound of the range lower the correlation, as for small and medium-sized enterprises; numpy.inf marks a borrower without that adjustment. Only for asset_class="corporate"; must not be missing.

turnover_rangetuple of float, default (5.0, 50.0)

The lower and upper bound of the turnover adjustment. The default is the Basel range in millions of euros; China’s rules use (3.0, 30.0) in tens of millions of yuan.

financialbool, default False

Whether the borrowers are financial institutions whose correlation is multiplied by 1.25. Only for asset_class="corporate", and not together with a turnover below the upper bound of turnover_range.

Returns:
float, pandas.Series or numpy.ndarray

Correlations with the broadcast shape of probability and turnover. If an input is a Series, the result is a Series with its index, named correlation; scalar inputs give a float.

Raises:
ValueError

If asset_class is not one of the five classes, probability is not real and numeric or is outside [0, 1], or the inputs cannot be broadcast together or have different Series indices. Also if turnover or financial is given for another class than "corporate", turnover is missing, negative or not numeric, turnover_range is not two finite numbers with 0 <= lower < upper, financial is not a boolean, or financial comes with a turnover below the upper bound.

See also

capital_requirement

The capital requirement that uses the correlation.

conditional_pd

The PD of the one-factor model given the state of the economy.

Notes

For corporate exposures, and with weights of 35 instead of 50 and the bounds 0.03 and 0.16 for other retail exposures,

\[w = \frac{1 - e^{-50\,\mathrm{PD}}}{1 - e^{-50}}, \qquad R = 0.12\,w + 0.24\,(1 - w).\]

High-volatility commercial real estate uses 0.30 instead of 0.24, residential mortgages \(R = 0.15\) and qualifying revolving retail exposures \(R = 0.04\). A turnover \(S\) with the range \([l, u]\) lowers a corporate correlation by \(0.04\,(1 - (\min(\max(S, l), u) - l) / (u - l))\), which is 0.04 at \(S \le l\) and 0 at \(S \ge u\), and financial multiplies it by 1.25 (Basel CRE31.5–31.16; China, annex 6 and annex 8).

Examples

>>> from kivi.capital import asset_correlation
>>> asset_correlation([0.0003, 0.01, 0.2], asset_class="corporate").round(4)
array([0.2382, 0.1928, 0.12  ])
>>> print(f"{asset_correlation(0.01, asset_class='corporate', turnover=5.0):.4f}")
0.1528
kivi.capital.capital_requirement(probability, lgd, *, asset_class, maturity=None, turnover=None, turnover_range=(5.0, 50.0), financial=False, correlation=None, level=0.999, scaling=1.0)#

Compute the capital requirement K of the IRB approach, as a share of the exposure.

K covers the unexpected loss of an exposure that is not in default: the loss at the level quantile of the one-factor model minus the expected loss. The risk-weighted assets are 12.5 * K * EAD and the risk weight 12.5 * K.

Parameters:
probabilityarray_like

Probabilities of default strictly between 0 and 1, after any PD floor. Missing values give missing requirements.

lgdarray_like

Loss given default as a share of the exposure, from 0 to 1. Missing values give missing requirements.

asset_class{“corporate”, “hvcre”, “mortgage”, “revolving”, “other_retail”}

The asset class, as in asset_correlation. It also decides whether the maturity adjustment applies: for "corporate" and "hvcre", not for the three retail classes.

maturityarray_like, optional

Effective maturity in years, positive and finite, for "corporate" and "hvcre" only. The default is 2.5 years. It is not clipped to the range of 1 to 5 years, which has exceptions for short-term exposures, and must not be missing.

turnoverarray_like, optional

Annual sales of corporate borrowers, as in asset_correlation.

turnover_rangetuple of float, default (5.0, 50.0)

The bounds of the turnover adjustment, as in asset_correlation.

financialbool, default False

Whether the 1.25 multiplier for financial institutions applies, as in asset_correlation.

correlationarray_like, optional

Asset correlations from 0 to 1 (exclusive) that replace those of the formula, as for economic capital; then turnover and financial must not be given. Must not be missing.

levelfloat, default 0.999

The confidence level of the one-factor model, strictly between 0 and 1.

scalingfloat, default 1.0

A positive factor applied to K. Only the Basel II framework of 2006 multiplied the risk-weighted assets by 1.06; the current Basel framework and China’s 2023 rules do not.

Returns:
float, pandas.Series or numpy.ndarray

Capital requirements with the broadcast shape of the inputs. If an input is a Series, the result is a Series with its index, named capital_requirement; scalar inputs give a float.

Raises:
ValueError

If an input is not real and numeric, the inputs cannot be broadcast together or have different Series indices, probability is outside the open interval (0, 1), or is at or below about 2.927e-6 for "corporate" or "hvcre", or lgd is outside [0, 1]. Also if maturity is given for a retail class, missing, not positive or not finite, correlation is missing, outside [0, 1) or given together with turnover or financial, level is outside (0, 1), scaling is not positive and finite, or an argument is invalid as in asset_correlation.

See also

asset_correlation

The correlation of each asset class.

conditional_pd

The PD at the level of the one-factor model.

kivi.strategy.expected_loss

The expected loss PD x LGD x EAD that K leaves out.

Notes

With the standard normal distribution function \(\Phi\), its quantile function \(\Phi^{-1}\), the correlation \(R\) of asset_correlation and the level \(q\),

\[K = \mathrm{LGD} \left[ \Phi\!\left( \frac{\Phi^{-1}(\mathrm{PD}) + \sqrt{R}\,\Phi^{-1}(q)}{\sqrt{1 - R}} \right) - \mathrm{PD} \right] \frac{1 + (M - 2.5)\,b}{1 - 1.5\,b}, \qquad b = (0.11852 - 0.05478 \ln \mathrm{PD})^2,\]

where the maturity factor applies to "corporate" and "hvcre" only (Basel CRE31.5–31.16; China, annex 6). Then K is multiplied by scaling.

The maturity factor divides by \(1 - 1.5\,b\), which reaches 0 at a PD of about 2.927e-6, so these PDs raise an error; well before that, below a PD of about 1e-5, the factor grows so fast that the risk weight rises again as the PD falls. The PD floors of 0.05% (Basel CRE32.4, China article 91) stay above both; only sovereign exposures have none.

A defaulted exposure (PD = 1) raises an error too: its requirement is \(\max(0, \mathrm{LGD} - \mathrm{ELBE})\) with the best estimate of its expected loss (Basel CRE31.3; China, annex 6, part II).

Examples

>>> from kivi.capital import capital_requirement
>>> k = capital_requirement(0.01, 0.45, asset_class="corporate")
>>> print(f"K = {k:.6f}, risk weight = {12.5 * k:.4%}")
K = 0.073853, risk weight = 92.3168%
>>> rw = 12.5 * capital_requirement([0.01, 0.01], [0.45, 0.25], asset_class="other_retail")
>>> rw.round(4)
array([0.4577, 0.2543])
kivi.capital.conditional_pd(probability, *, correlation, factor=None, level=None)#

Compute the PD of the one-factor model given the state of the economy.

In the one-factor model of Vasicek, behind the IRB risk-weight functions, a borrower defaults when its assets fall below a threshold set by its long-run PD, and the assets of all borrowers share one systematic factor. Given that factor, defaults are independent and occur with the conditional PD. It turns a through-the-cycle PD into a point-in-time PD for a scenario of the economy, and gives the stressed PD of capital_requirement at its level.

Parameters:
probabilityarray_like

Long-run (unconditional) probabilities of default, strictly between 0 and 1. Missing values give missing PDs.

correlationarray_like

Asset correlations from 0 to 1 (exclusive), such as those of asset_correlation. Must not be missing.

factorarray_like, optional

Values of the standard normal systematic factor, finite; positive values stand for a better economy than on average and give PDs below the long-run PD. Missing values give missing PDs.

levelarray_like, optional

Instead of factor, the probability strictly between 0 and 1 that the economy is better than the scenario: the factor is the lower 1 - level quantile, -Phi^-1(level). Missing values give missing PDs. Exactly one of factor and level must be given.

Returns:
float, pandas.Series or numpy.ndarray

Conditional PDs with the broadcast shape of the inputs. If an input is a Series, the result is a Series with its index, named conditional_pd; scalar inputs give a float.

Raises:
ValueError

If not exactly one of factor and level is given, an input is not real and numeric, the inputs cannot be broadcast together or have different Series indices, probability or level is outside the open interval (0, 1), correlation is missing or outside [0, 1), or factor is infinite.

See also

systematic_factor

The factor that a default rate implies, the inverse of this function.

vasicek_fit

Estimate the long-run PD and the correlation from default rates.

capital_requirement

The capital requirement, which uses the PD at the level 0.999.

Notes

With the standard normal distribution function \(\Phi\), the correlation \(\rho\) and the factor \(z\),

\[\mathrm{PD}(z) = \Phi\!\left( \frac{\Phi^{-1}(\mathrm{PD}) - \sqrt{\rho}\,z}{\sqrt{1 - \rho}} \right),\]

and level \(q\) stands for \(z = -\Phi^{-1}(q)\), so that level=0.999 gives the PD of the IRB formula. Averaged over the standard normal \(z\), the conditional PD is the long-run PD.

Examples

>>> from kivi.capital import conditional_pd
>>> conditional_pd(0.01, correlation=0.12, factor=[2.0, 0.0, -2.0]).round(5)
array([0.00064, 0.00657, 0.04081])
>>> print(f"{conditional_pd(0.01, correlation=0.12, level=0.999):.4%}")
9.0326%
kivi.capital.systematic_factor(default_rate, probability, *, correlation)#

Compute the systematic factor that an observed default rate implies.

This inverts conditional_pd: it gives the value of the systematic factor under which the conditional PD equals the default rate, such as the default rate of a portfolio in each year. A negative factor marks a year worse than on average.

Parameters:
default_ratearray_like

Observed default rates, strictly between 0 and 1. Missing values give missing factors.

probabilityarray_like

Long-run probabilities of default, strictly between 0 and 1, such as the first result of vasicek_fit. Missing values give missing factors.

correlationarray_like

Asset correlations strictly between 0 and 1, such as the second result of vasicek_fit. Must not be missing.

Returns:
float, pandas.Series or numpy.ndarray

Factors with the broadcast shape of the inputs. If an input is a Series, the result is a Series with its index, named factor; scalar inputs give a float.

Raises:
ValueError

If an input is not real and numeric, the inputs cannot be broadcast together or have different Series indices, default_rate or probability is outside the open interval (0, 1), or correlation is missing or outside (0, 1). A default rate of 0 or 1 has no finite factor.

See also

conditional_pd

The PD given the factor, the inverse of this function.

vasicek_fit

Estimate the long-run PD and the correlation from default rates.

Notes

With the default rate \(\mathrm{DR}\),

\[z = \frac{\Phi^{-1}(\mathrm{PD}) - \sqrt{1 - \rho}\,\Phi^{-1}(\mathrm{DR})}{\sqrt{\rho}}.\]

Examples

>>> from kivi.capital import conditional_pd, systematic_factor
>>> systematic_factor([0.004, 0.01, 0.03], 0.01, correlation=0.12).round(4)
array([ 0.4663, -0.4158, -1.6224])
>>> print(f"{conditional_pd(0.01, correlation=0.12, factor=-1.6224):.4f}")
0.0300
kivi.capital.vasicek_fit(default_rate)#

Estimate the long-run PD and the asset correlation from a series of default rates.

In the one-factor model, the default rate of a large portfolio varies from year to year with the systematic factor, and its variance grows with the asset correlation. The method of moments matches the mean and the variance of the observed default rates. Default rates of 0 count, as in years without defaults.

Parameters:
default_ratearray_like

Default rates of a portfolio in successive periods, such as years, from 0 to 1, at least two and without missing values.

Returns:
probabilityfloat

The long-run PD, the mean of the default rates.

correlationfloat

The asset correlation, from 0 to 1. A constant series gives 0.

Raises:
ValueError

If default_rate is not real and numeric, not one-dimensional, has fewer than two values, missing values or values outside [0, 1], its mean is 0 or 1, or its variance is at least mean * (1 - mean), the variance of a correlation of 1.

See also

conditional_pd

The PD given the factor, with the fitted parameters.

systematic_factor

The factor of each period, with the fitted parameters.

Notes

With the mean \(m\) and the variance \(s^2\) of the default rates (with ddof=1), the correlation \(\rho\) solves

\[\Phi_2\!\left(\Phi^{-1}(m), \Phi^{-1}(m); \rho\right) - m^2 = s^2,\]

where \(\Phi_2\) is the bivariate standard normal distribution function: two borrowers of the portfolio default together with probability \(\Phi_2\). Its left side rises with \(\rho\), from 0 to \(m (1 - m)\), and is solved by bisection. The moments describe a portfolio large enough for its default rate to equal the conditional PD, so the binomial noise of a small portfolio raises the estimate.

Examples

>>> from kivi.capital import vasicek_fit
>>> probability, correlation = vasicek_fit([0.004, 0.012, 0.0, 0.031, 0.008, 0.015])
>>> print(f"PD = {probability:.4f}, correlation = {correlation:.4f}")
PD = 0.0117, correlation = 0.0994
kivi.capital.most_prudent_pd(event, total, *, level=0.95, correlation=0.0)#

Compute the most prudent upper bounds of Pluto and Tasche for the PD of each grade.

A portfolio with few or no defaults, such as banks or large corporates, gives default rates too small to calibrate a PD on. The most prudent estimate of a grade is the largest PD that the defaults observed in it and in all riskier grades do not reject at the confidence level, assuming that the PDs do not fall from one grade to the next riskier one.

Parameters:
eventarray_like

Number of defaults in each grade, a non-negative whole number, with the grades from the least to the most risky. Must not be missing.

totalarray_like

Number of obligors in each grade, a whole number not below event, matched by position or, for two Series, by identical indices.

levelfloat, default 0.95

The confidence level, strictly between 0 and 1.

correlationfloat, default 0.0

The asset correlation of the one-factor model, from 0 to 1 (exclusive). With 0, defaults are independent; a positive correlation makes the same defaults compatible with higher PDs.

Returns:
pandas.Series or numpy.ndarray

The upper bound of the PD of each grade. If an input is a Series, the result is a Series with its index, named most_prudent_pd.

Raises:
ValueError

If event or total is not real and numeric, not one-dimensional, empty or of different lengths, their Series indices differ, a count is missing or not a non-negative whole number, event exceeds total, level is outside (0, 1) or correlation is outside [0, 1).

See also

kivi.calibration.binomial_test

Test the PD of each grade against its default count.

conditional_pd

The PD of the one-factor model given the factor.

Notes

Grade \(k\) pools the obligors \(n_k = \sum_{i \ge k} N_i\) and the defaults \(d_k = \sum_{i \ge k} D_i\) of itself and all riskier grades. Its bound \(p_k\) is the largest PD for which \(P(D \le d_k) \ge 1 - q\) at the level \(q\). With independent defaults, \(D\) is binomial with \(n_k\) and \(p_k\), so \(p_k\) is the \(q\) quantile of the beta distribution with \(d_k + 1\) and \(n_k - d_k\), and without defaults \(p_k = 1 - (1 - q)^{1/n_k}\). With a correlation \(\rho\), the defaults are binomial given the factor,

\[P(D \le d_k) = \int P\left(\mathrm{Bin}(n_k, \mathrm{PD}(z)) \le d_k\right) \varphi(z) \, dz,\]

with the conditional PD of conditional_pd, integrated by composite Gauss-Legendre quadrature over the factor from -9 to 9 (64 panels of 8 nodes) and solved by bisection. A grade whose pooled obligors all defaulted, or which pools none, gets 1. The bounds are those of one period; with factors correlated over several years they need simulation, which kivi leaves out. Pluto and Tasche [1] compute the same bounds for their examples, with a correlation of 0.12 for the correlated one.

References

[1]

K. Pluto and D. Tasche, “Estimating probabilities of default for low default portfolios”, arXiv:cond-mat/0411699, 2004; also “Thinking positively”, Risk 18 (8), 2005, pp. 72-78.

Examples

>>> from kivi.capital import most_prudent_pd
>>> (100 * most_prudent_pd([0, 0, 0], [100, 400, 300], level=0.9)).round(2)
array([0.29, 0.33, 0.76])