LGD and EAD#
Measure and model the loss given default and the credit conversion factor of defaulted loans. workout_lgd() discounts the recoveries and costs of each workout to the date of default, conversion_factor() gives the realized CCF of a credit line, lgd_table() summarizes realized LGDs by group and fractional_regression() fits the fractional logit of an LGD on its drivers.
See LGD and EAD for examples and the rules of the Basel framework, the EBA and China’s capital rules.
|
Compute the realized LGD of defaulted loans from their workout cash flows. |
|
Compute the realized credit conversion factor of each credit line. |
|
Summarize realized LGDs by group. |
|
Fit a fractional logit regression of a response between 0 and 1. |
- kivi.lgd.workout_lgd(loan, default_date, ead, flow_loan, flow_date, flow_amount, *, rate)#
Compute the realized LGD of defaulted loans from their workout cash flows.
The economic loss of a defaulted loan is its exposure at default plus the costs of the workout, minus the recoveries, all discounted to the date of default. Its ratio to the exposure at default is the realized loss given default of the workout approach.
- Parameters:
- loanarray_like
Defaulted loans, each once. The result has one row per loan, in this order.
- default_datearray_like
Date of default of each loan, as dates or as strings that pandas.to_datetime reads. A time of day is ignored.
- eadarray_like
Exposure at default of each loan, positive and finite: the amount outstanding at default, including accrued interest and fees, plus any amount written off at or before default.
- flow_loanarray_like
Loan of each cash flow of the workouts. Every one must be a loan of loan, and a loan without flows has recovered nothing. The flows need not be sorted, and their Series may have any index.
- flow_datearray_like
Date of each cash flow, read like default_date.
- flow_amountarray_like
Amount of each cash flow, finite: positive for a recovery, such as a repayment, the proceeds of collateral or a cure, and negative for a cost of the workout or a drawing after default. Costs may come before the date of default; recoveries may not.
- ratefloat or array_like
Annual discount rate, greater than -1, as one rate for every loan or one per loan, matched to loan like ead, such as the 3-month interbank rate at the date of default plus 5 percentage points.
- Returns:
- pandas.DataFrame
One row per loan, indexed by loan in an index named
loan, withead;recovery, the present value of the positive flows;cost, the present value of the negative flows as a positive amount; andlgd, which is(ead + cost - recovery) / ead.
- Raises:
- ValueError
If the inputs of the loans, or those of the flows, are not one-dimensional, have different lengths or are Series with different indices, or if loan is empty. Also if a loan or a date is missing or repeats a loan, a date cannot be read, ead is missing or not positive and finite, an amount is missing, infinite or not a number, a flow belongs to a loan that is not in loan, a recovery comes before the date of default of its loan, or rate is missing, not finite, at most -1 or not one rate or one per loan. Booleans are not amounts or rates.
See also
lgd_tableLong-run average LGDs by group.
fractional_regressionModel the LGD on its drivers.
kivi.calibration.backtest_tableBack-test LGD estimates against realized LGDs.
kivi.vintage.delinquency_panelReads dates in the same way.
Notes
A flow of amount \(a_j\) on the date \(t_j\) of a loan that defaulted on the date \(t_D\) with the annual rate \(r\) has the present value
\[\mathrm{PV}_j = a_j \, (1 + r)^{-(t_j - t_D) / 365},\]with the days counted ACT/365. A cost before the date of default has a negative exponent and is compounded to the date of default. With the sums \(R\) of the present values of the positive flows and \(C\) of those of the negative flows, as a positive amount,
\[\mathrm{LGD} = \frac{\mathrm{EAD} + C - R}{\mathrm{EAD}}.\]This is the economic loss of paragraphs 131 to 146 of [1] and of CRE36.76 of the Basel framework. The LGD is not clipped to [0, 1]: it is negative when the recoveries exceed the exposure and the costs, and above 1 when the costs exceed the recoveries. lgd_table floors it at 0 for long-run averages (paragraph 160 of [1]).
The function does not know whether a workout has ended, and gives the loss of the flows so far: a loan without flows has an LGD of 1. A realized LGD exists only for a closed workout (paragraph 154 of [1]; section 2.6.1 of [2]), so select the loans whose recovery process has closed, by the bank’s definition of its end, before averaging or back-testing.
The flows are the caller’s to choose:
A drawing after default is a negative flow, like a cost, so that it counts in the loss (paragraph 142 of [1]). Where the conversion factor includes the drawings, paragraph 140 of [1] counts them in the exposure as well: add their present value to ead instead of passing them as flows, since ead counts in the loss too. The
costof a call with the drawings alone, negated, is that present value.An amount written off at or before default belongs in ead, so that it counts in the loss and in the exposure (paragraph 134 of [1]).
A cure is a recovery of the amount outstanding on the date of the cure (paragraph 135 of [1]).
Interest and fees capitalized after default are not flows (paragraphs 137 and 138 of [1]); their recoveries are.
References
[1] (1,2,3,4,5,6,7,8)European Banking Authority, “Guidelines on PD estimation, LGD estimation and the treatment of defaulted exposures”, EBA/GL/2017/16, 20 November 2017, paragraphs 131 to 163.
[2]European Central Bank, “Instructions for reporting the validation results of internal models: IRB Pillar I models for credit risk”, February 2019, section 2.6.1.
Examples
Three loans defaulted on 1 January 2023. Loan A recovers 55 and costs 11 a year later, loan B recovers its exposure on the day of default after a legal cost of 5 a year before, and loan C has no flows yet:
>>> from kivi.lgd import workout_lgd >>> workout_lgd( ... ["A", "B", "C"], ... ["2023-01-01"] * 3, ... [100.0, 200.0, 50.0], ... ["A", "A", "B", "B"], ... ["2024-01-01", "2024-01-01", "2022-01-01", "2023-01-01"], ... [55.0, -11.0, -5.0, 200.0], ... rate=0.1, ... ).round(4) ead recovery cost lgd loan A 100.0 50.0 10.0 0.6000 B 200.0 200.0 5.5 0.0275 C 50.0 0.0 0.0 1.0000
At 10% a year, the flows of A a year after default are worth 55 / 1.1 = 50 and 11 / 1.1 = 10, and the cost of B a year before default is worth 5 × 1.1 = 5.5 at default.
- kivi.lgd.conversion_factor(ead, drawn, limit)#
Compute the realized credit conversion factor of each credit line.
The credit conversion factor (CCF) is the share of the undrawn part of a credit line at a reference date that the borrower has drawn by the time of default.
- Parameters:
- eadarray_like
Amount drawn at default, the realized exposure at default.
- drawnarray_like
Amount drawn at the reference date.
- limitarray_like
Limit of the credit line at the reference date. Series inputs must have identical indices; otherwise the inputs are broadcast together.
- Returns:
- float, pandas.Series or numpy.ndarray
Realized CCFs, with the broadcast shape of the inputs: NaN where the line was fully drawn at the reference date (limit at most drawn) or an input is missing. If an input is a Series, the result is a Series with its index, named
ccf; scalar inputs give a float.
- Raises:
- ValueError
If an input is not real and numeric or has an infinite value, the inputs cannot be broadcast together, or Series inputs have different indices. Booleans are not amounts.
See also
workout_lgdRealized LGDs of the same defaults.
lgd_tableSummarize realized CCFs by group, with
floor=None.kivi.calibration.backtest_tableBack-test CCF estimates against realized CCFs.
Notes
With the amount \(E\) drawn at default, and the amount \(D\) drawn and the limit \(L\) at the reference date,
\[\mathrm{CCF} = \frac{E - D}{L - D}, \qquad L > D.\]This is the realized CCF of CRE36.95 of the Basel framework and of paragraph 61(a) of the EBA’s consultation on CCF estimation [1]. The reference date of the fixed-horizon approach lies 12 months before default (CRE36.93; article 182(1)(g) of the CRR3), and the limit is the larger of the advised and the unadvised limit at that date: a later increase of the limit stays out of the denominator, so the CCF can exceed 1.
A line that is fully drawn or overdrawn at the reference date has no undrawn part, and its CCF is NaN instead of the sign-reversed ratio of an overdrawn line. The consultation measures such lines by
ead / limit(paragraph 61(b)), and the ECB’s validation report back-tests their EAD instead of a CCF.The CCFs are not clipped. Negative values, from lines repaid after the reference date, still rank the risk, but the quantification sets them to 0 (article 182(1) of the CRR3), as
numpy.maximum(ccf, 0)does; values above 1 are kept, since the CCF must not be capped (CRE36.95-96).References
[1]European Banking Authority, “Consultation paper on draft guidelines on CCF estimation”, EBA/CP/2025/10, 2 July 2025.
Examples
>>> from kivi.lgd import conversion_factor >>> conversion_factor([600.0, 800.0, 300.0, 900.0], [400.0, 400.0, 500.0, 1000.0], 1000.0) array([ 0.33333333, 0.66666667, -0.4 , nan])
The first line drew 200 of its 600 undrawn; the third repaid 200 of its 500 undrawn, and the fourth was fully drawn at the reference date.
- kivi.lgd.lgd_table(groups, lgd, *, floor=0.0, weights=None)#
Summarize realized LGDs by group.
The table gives the number of defaults, the average LGD, its spread and the shares of defaults without loss and with a total loss in each group, such as a segment, a facility grade or a bin of a driver: the long-run average LGD of each group and the bimodal shape of the LGDs within it.
- Parameters:
- groupsarray_like
Group labels, such as facility grades or the bins of a driver from kivi.binning.cut. Missing values form a group.
- lgdarray_like
Realized LGD of each default, such as the
lgdcolumn of workout_lgd, finite and without missing values. If groups and lgd are Series, they must have identical indices; otherwise they are matched by position.- floorfloat or None, default 0.0
Lower bound applied to the LGDs before anything is computed: negative LGDs count as 0 by default, as the regulations ask for long-run averages. None keeps the LGDs as they are, which suits an analysis of the drivers.
- weightsarray_like, optional
Non-negative frequency weight of each default, matched like lgd: integer weights give the same table as repeating rows, and groups whose weights sum to zero are left out. See the Notes on weighting by exposure.
- Returns:
- pandas.DataFrame
One row per group, in an index named
bin, with the columns described in the Notes.
- Raises:
- ValueError
If the inputs are not one-dimensional, are empty, or their indices or lengths do not match, lgd is not real and numeric or has a missing or infinite value, or floor is neither None nor a finite number. Also if weights is not numeric, does not give each default one finite, non-negative weight with a positive total, or has an index other than that of groups.
See also
workout_lgdRealized LGDs from workout cash flows.
fractional_regressionModel the LGD on several drivers at once.
kivi.woe.woe_tableThe table of a binary target.
kivi.calibration.backtest_tableBack-test LGD estimates by group.
Notes
For the defaults \(i\) of a group, with weights \(w_i\) (1 without weights) and LGDs \(x_i = \max(\mathrm{LGD}_i, f)\) at the floor \(f\), the columns are:
total: the number of defaults, \(n = \sum_i w_i\);total_share:totaldivided by the number of all defaults;mean: the average LGD, \(\bar x = \sum_i w_i x_i / n\);std: the sample standard deviation, \(\sqrt{\sum_i w_i (x_i - \bar x)^2 / (n - 1)}\), NaN for a group with a total weight of 1 or less;minandmax: the smallest and largest LGD with a positive weight;zero_share: the share of defaults with \(x_i \le 0\), without loss;full_share: the share of defaults with \(x_i \ge 1\), a total loss.
The average counts every default once, the default-weighted average of paragraph 150 of [1], CRE36.83 of the Basel framework and part VI(4) of annex 5 of China’s 2023 capital rules, which also set negative LGDs to 0 (paragraph 160 of [1]; part VI(4) 15 of the annex). Weighting by the exposure at default gives an exposure-weighted average instead, which is not the long-run average of the regulations; use weights that count defaults, such as the inverse of a sampling rate.
Groups are counted as in kivi.woe.woe_table: categorical groups, such as the result of
pandas.cut, follow the order of their categories, with missing values last, and other groups the order in which they first appear. Categories that are never observed are omitted.References
Examples
>>> from kivi.lgd import lgd_table >>> grade = ["F1"] * 4 + ["F2"] * 3 >>> lgd = [-0.05, 0.0, 0.10, 0.35, 0.80, 1.0, 1.2] >>> lgd_table(grade, lgd).round(4) total total_share mean std min max zero_share full_share bin F1 4 0.5714 0.1125 0.1652 0.0 0.35 0.5 0.0000 F2 3 0.4286 1.0000 0.2000 0.8 1.20 0.0 0.6667
The LGD of -0.05 in grade F1, from recoveries above the exposure, counts as 0, so half of the defaults of F1 lost nothing, and two of the three defaults of F2 lost all of their exposure or more.
- kivi.lgd.fractional_regression(X, response, *, weights=None)#
Fit a fractional logit regression of a response between 0 and 1.
The model of Papke and Wooldridge [1] gives the mean of a response between 0 and 1, such as a realized LGD or a recovery rate, as the logistic function of a linear combination of the columns of X. Its coefficients maximize the Bernoulli quasi-likelihood, and their standard errors are robust, so the model needs no assumption about the distribution of the response around its mean.
- Parameters:
- Xpandas.DataFrame or array_like
Two-dimensional numeric values with one column per driver, such as the loan-to-value ratio or a segment dummy.
- responsearray_like
Response of each row, from 0 to 1, with exact 0 and 1 allowed, such as realized LGDs floored at 0 and capped at 1. If X is a DataFrame and response a Series, they must have identical indices; otherwise they are matched by position.
- weightsarray_like, optional
Non-negative frequency weight of each row, matched like response: integer weights give the same estimates, standard errors and quasi-log-likelihood as repeating rows. Rows with zero weight are left out of the fit.
- Returns:
- pandas.DataFrame
One row for the intercept, labelled
intercept, and one for each column of X, with the coefficientcoef, its robust standard errorse, the z statisticzand its two-sided p-valuep_value, in an index namedvariable, as kivi.selection.logistic_regression gives them.attrs["log_likelihood"]holds the maximized quasi-log-likelihood andattrs["converged"]whether the fit converged.
- Raises:
- kivi.selection.SeparationError
If the columns separate the responses of 0 from those of 1, while no response between them stops the coefficients from growing without bound, so that the estimates do not exist.
- ValueError
If X is not two-dimensional, has fewer than 2 rows or no columns, repeats a column label, has a column labelled
intercept, or has a column that is not numeric, contains missing or infinite values, is constant or is a linear combination of the intercept and the columns before it, or so close to one that its coefficient cannot be estimated; if response is not one-dimensional, its index or length does not match X, it is not real and numeric, has a missing value or a value outside [0, 1], or is 0 for every row or 1 for every row; or if weights is not numeric or does not give each row one finite, non-negative weight with a positive total. With weights, the checks for constant columns, linear combinations and a response of 0 or 1 for every row are limited to the rows with positive weight.
- Warns:
- RuntimeWarning
If the fit does not converge for a reason other than separation.
See also
kivi.selection.logistic_regressionThe same model for a binary target.
lgd_tableRealized LGDs by the groups of one driver.
workout_lgdRealized LGDs from workout cash flows.
Notes
The model is
\[E(y \mid x) = \frac{1}{1 + e^{-\eta}}, \qquad \eta = \beta_0 + \sum_j \beta_j x_j,\]and the estimates maximize the quasi-log-likelihood
\[\ell(\beta) = \sum_i w_i \left[ y_i \ln p_i + (1 - y_i) \ln(1 - p_i) \right],\]which is the log-likelihood of kivi.selection.logistic_regression for a binary response, so a response of only 0 and 1 gives its coefficients. The fit uses the same iteratively reweighted least squares. The mean is consistently estimated whenever the model of the mean is right, but the Fisher information understates the variance of a fractional response, so the covariance is the HC0 sandwich
\[\hat V = A^{-1} B A^{-1}, \qquad A = \sum_i w_i p_i (1 - p_i) x_i x_i^\top, \qquad B = \sum_i w_i (y_i - p_i)^2 x_i x_i^\top,\]with \(x_i\) including the 1 of the intercept, as statsmodels’
GLM(family=Binomial(), freq_weights=w).fit(cov_type="HC0")gives it. The z statistic is \(\hat\beta / \mathrm{se}\) and the p-value \(P(|Z| > |z|)\) for a standard normal \(Z\). For a binary response, the robust standard errors differ from the model-based ones of kivi.selection.logistic_regression.A fractional response bounds the linear predictor in both directions, so the estimates exist unless a combination of the columns separates the responses of exactly 0 from those of exactly 1 and leaves the linear predictor of every response between them unchanged.
References
[1]L. E. Papke and J. M. Wooldridge, “Econometric methods for fractional response variables with an application to 401(k) plan participation rates”, Journal of Applied Econometrics, 11(6), pp. 619-632, 1996.
Examples
With one dummy, the fitted means are the mean responses of its two groups, 0.2 for the secured and 0.65 for the unsecured loans:
>>> import pandas as pd >>> from kivi.lgd import fractional_regression >>> X = pd.DataFrame({"unsecured": [0, 0, 0, 0, 1, 1, 1, 1]}) >>> lgd = pd.Series([0.0, 0.1, 0.5, 0.2, 0.3, 0.9, 0.4, 1.0]) >>> fractional_regression(X, lgd).round(4) coef se z p_value variable intercept -1.3863 0.5846 -2.3712 0.0177 unsecured 2.0053 0.8880 2.2582 0.0239
The intercept is \(\ln(0.2 / 0.8)\), the log odds of the secured mean, and its robust variance is \(\sum_i (y_i - 0.2)^2 / (4 \cdot 0.2 \cdot 0.8)^2 = 0.14 / 0.4096\) over the four secured rows.