Lifetime PD and expected credit loss#

Turn PD term structures into the expected credit loss and the stages of IFRS 9. convert_pd() converts a term structure between cumulative, marginal and conditional PDs, transition_pd() projects one from a transition matrix, survival_table() estimates one from loans that are censored, repaid early or observed only from some age on, expected_credit_loss() gives the 12-month and the lifetime expected credit loss of each account, and significant_increase(), assign_stages() and stage_table() allocate the stages and sum the loss allowance of each stage.

See Lifetime PD and expected credit loss for examples on the bundled data.

convert_pd(probability, *, kind, to)

Convert a PD term structure between cumulative, marginal and conditional PDs.

transition_pd(matrix, *, horizons[, ...])

Project the cumulative PD of each state from a transition matrix.

survival_table(duration, event, *[, ...])

Estimate a cumulative PD term structure from censored and truncated accounts.

expected_credit_loss(probability, lgd, ead, ...)

Compute the 12-month or lifetime expected credit loss of each account.

significant_increase(probability, ...)

Flag a significant increase in credit risk since initial recognition.

assign_stages(significant_increase[, ...])

Allocate exposures to the three stages of IFRS 9.

stage_table(stage, exposure, allowance, *[, ...])

Summarize the exposure and the expected credit loss of each stage.

kivi.lifetime.convert_pd(probability, *, kind, to)#

Convert a PD term structure between cumulative, marginal and conditional PDs.

A term structure gives the probability of default in each period after a starting point, such as the origination of a loan. The cumulative PD of period \(k\) is the probability of a default in periods 1 to \(k\), the marginal PD the probability of a default in period \(k\), and the conditional PD, or hazard rate, the probability of a default in period \(k\) given that there was none before.

Parameters:
probabilityarray_like or pandas.DataFrame

PDs from 0 to 1, as one curve, one-dimensional, or one curve per row, two-dimensional, such as the cumulative bad rates of kivi.vintage.vintage_table with one row per cohort and one column per month on book. The periods are the positions along the curve: the first is period 1. Missing values mark the periods that are not observed, such as the months on book that a cohort has not reached. Booleans count as 0 and 1.

kind{“cumulative”, “marginal”, “conditional”}

Kind of the PDs in probability.

to{“cumulative”, “marginal”, “conditional”}

Kind of the PDs to return.

Returns:
pandas.DataFrame, pandas.Series or numpy.ndarray

PDs of kind to in the shape of probability, with its index, columns and name. Missing values stay missing, and so do the PDs that depend on them, as described in the Notes.

Raises:
ValueError

If kind or to is not one of the three kinds, probability is not real and numeric, is not one- or two-dimensional, has no period or has a value outside [0, 1]. Also if cumulative PDs decrease along a curve or the marginal PDs of a curve add up to more than 1.

See also

transition_pd

Cumulative PDs from a transition matrix.

expected_credit_loss

Expected credit loss from marginal PDs.

kivi.vintage.vintage_table

Cumulative bad rates by cohort and month on book.

Notes

With the cumulative PDs \(C_k\), the marginal PDs \(m_k\) and the conditional PDs \(h_k\) of periods \(k = 1, 2, \ldots\), and \(C_0 = 0\),

\[m_k = C_k - C_{k-1}, \qquad h_k = \frac{C_k - C_{k-1}}{1 - C_{k-1}}, \qquad C_k = \sum_{j \le k} m_j = 1 - \prod_{j \le k} (1 - h_j).\]

The conversions are inverses of each other, up to rounding. The labels of the periods are not used: the columns of a vintage table that start at month on book 1 give monthly PDs, and columns of quarterly snapshots give the PDs of the quarters between them.

Missing values are not filled. The marginal and the conditional PD of a period need the cumulative PDs at its end and at the end of the period before, and the cumulative PD of a period needs the marginal or conditional PDs of every period up to it. The months on book that a cohort has not reached therefore stay missing in every kind, also after a round trip. Missing values at the start of a curve, which kivi.vintage.vintage_table gives when the panel starts after origination, leave the marginal and conditional PDs known from the second observed period on, but converting those back cannot restore the cumulative PDs, because the cumulative PD before the panel starts is not known.

Once the cumulative PD of a curve reaches 1, no exposure is left to default, and the conditional PDs of the later periods, 0 / 0, are 0, so that the conversions stay inverses.

The cumulative bad rates of kivi.vintage.vintage_table count every loan of a cohort, also the loans that were repaid early and can no longer default. Its marginal PDs therefore already allow for early repayment, and its conditional PDs are conditional on no default, not on the loan still being on book.

Examples

>>> from kivi.lifetime import convert_pd
>>> cumulative = [0.02, 0.05, 0.08]
>>> convert_pd(cumulative, kind="cumulative", to="marginal")
array([0.02, 0.03, 0.03])
>>> conditional = convert_pd(cumulative, kind="cumulative", to="conditional")
>>> conditional.round(4)
array([0.02  , 0.0306, 0.0316])
>>> convert_pd(conditional, kind="conditional", to="cumulative")
array([0.02, 0.05, 0.08])

A vintage table has one curve per cohort, and the months on book that a cohort has not reached stay missing:

>>> from kivi.vintage import vintage_table
>>> loan = [1, 1, 1, 2, 2, 2, 3, 3, 4, 4]
>>> cohort = ["2024-01"] * 6 + ["2024-02"] * 4
>>> month_on_book = [1, 2, 3, 1, 2, 3, 1, 2, 1, 2]
>>> bad = [0, 1, 1, 0, 0, 0, 1, 1, 0, 0]
>>> table = vintage_table(loan, cohort, month_on_book, bad)
>>> convert_pd(table, kind="cumulative", to="conditional")
month_on_book    1    2    3
cohort
2024-01        0.0  0.5  0.0
2024-02        0.5  0.0  NaN
kivi.lifetime.transition_pd(matrix, *, horizons, default_state=None)#

Project the cumulative PD of each state from a transition matrix.

Row \(i\) of a transition matrix holds the probabilities of moving from state \(i\), such as a rating grade or a delinquency bucket, to each state over one period. If the movements follow a time-homogeneous Markov chain, the \(h\)-th power of the matrix holds the probabilities over \(h\) periods, and its default column the cumulative PD of each starting state.

Parameters:
matrixarray_like or pandas.DataFrame

Square matrix of the probabilities of moving between the states over one period, such as a year or a month, for example the result of kivi.vintage.transition_matrix with normalize=True. Each row holds probabilities from 0 to 1 that add up to 1, except that the row of the default state is not used. The states of a DataFrame are its index, which must equal its columns; the states of an array are the positions 0, 1, and so on.

horizonsint or array_like

Numbers of periods after which to report the cumulative PD: a positive integer \(n\) for every horizon from 1 to \(n\), or increasing positive integers, such as [12, 24, 36].

default_stateoptional

Label of the default state. By default the last state, the worst one when the states are ordered from the best to the worst, as for kivi.vintage.transition_matrix.

Returns:
pandas.DataFrame

Cumulative PD with one row per starting state, indexed by state or, for states with several levels, by the levels of the index of matrix, and one column per horizon, labelled horizon. The row of the default state is 1.

Raises:
ValueError

If matrix is not a square, two-dimensional matrix of real numbers, a DataFrame’s index and columns differ or have duplicates, default_state is not one of the states, or a row of another state has a missing value or a value outside [0, 1] or does not add up to 1. Also if horizons is not a positive integer or a sequence of increasing positive integers.

See also

kivi.vintage.transition_matrix

Transition matrix of observed movements.

convert_pd

Marginal and conditional PDs from the cumulative PDs.

expected_credit_loss

Expected credit loss from marginal PDs.

Notes

The default state is made absorbing: its row is replaced by one that stays in default with probability 1. Exposures that cure from default in the data therefore still count as defaulted, as in the ever-bad rates of kivi.vintage.vintage_table. With this matrix \(P\) and the default state \(d\), the cumulative PD of state \(i\) at horizon \(h\) is

\[\mathrm{PD}_i(h) = (P^h)_{id}.\]

It never decreases with the horizon and never exceeds 1. Because \(P^{a+b} = P^a P^b\), the PD at \(a + b\) periods is the PD at \(b\) periods of the states reached after \(a\) periods, weighted by the probabilities of reaching them.

The projection assumes that the probabilities of moving between states are the same in every period and do not depend on how long an exposure has been in its state or on book. A matrix estimated over one year gives annual PDs, and a monthly one monthly PDs. Rows must add up to 1 within 1e-9; divide a published matrix that was rounded by its row sums first.

Examples

>>> import pandas as pd
>>> from kivi.lifetime import transition_pd
>>> states = ["A", "B", "D"]
>>> matrix = pd.DataFrame(
...     [[0.90, 0.08, 0.02], [0.10, 0.70, 0.20], [0.00, 0.00, 1.00]],
...     index=states,
...     columns=states,
... )
>>> transition_pd(matrix, horizons=3)
horizon     1      2        3
state
A        0.02  0.054  0.09596
B        0.20  0.342  0.44480
D        1.00  1.000  1.00000

After two periods, state A has defaulted with probability 0.90 × 0.02 + 0.08 × 0.20 + 0.02 = 0.054.

kivi.lifetime.survival_table(duration, event, *, competing=None, entry=None, weights=None)#

Estimate a cumulative PD term structure from censored and truncated accounts.

Each account, such as a loan, is followed period by period from a starting point, such as its origination, until it defaults, leaves for another reason, such as an early repayment, or is last observed, when it is censored. The table gives the number of accounts at risk in each period, the hazard rate of default and, without competing, the Kaplan–Meier estimate of the cumulative PD or, with it, the Aalen–Johansen estimate of the cumulative incidence of default.

Parameters:
durationarray_like

Period of each account’s default, exit or last observation, a positive whole number, such as the month on book of its last row in a monthly panel.

eventarray_like

Whether the account defaulted in period duration, as booleans or 0 and 1.

competingarray_like, optional

Whether the account left in period duration for another reason that ends its risk of default, such as an early repayment, as booleans or 0 and 1. It must not be 1 on a row where event is 1. Without it, every account that did not default is censored.

entryarray_like, optional

Number of periods that had passed when each account came under observation, a whole number from 0 to its duration − 1, by default 0. An account is at risk from period entry + 1 on, so a loan first observed at month on book 7 has an entry of 6. This handles left truncation, such as a panel that starts after the loans were originated.

weightsarray_like, optional

Non-negative frequency weight of each account. Counts become sums of weights, so integer weights give the same table as repeated accounts, and accounts with weight 0 are left out. Series inputs must have identical indices; otherwise the inputs are matched by position.

Returns:
pandas.DataFrame

One row per period from 1 to the largest duration, indexed by period, with the columns at_risk, event, competing (only with competing), censored, hazard, survival and cumulative_pd described in the Notes. The counts are integers without weights and sums of weights with them.

Raises:
ValueError

If the inputs are empty, not one-dimensional, of different lengths or Series with different indices. Also if duration is not real and numeric or has a value that is not a positive whole number, event or competing has a value other than 0 and 1, both are 1 on a row, entry is not real and numeric or has a value that is not a whole number from 0 to the account’s duration − 1, or weights is not numeric or does not give each account one finite, non-negative weight with a positive total.

See also

convert_pd

Marginal and conditional PDs from cumulative_pd.

expected_credit_loss

Expected credit loss from marginal PDs.

kivi.vintage.vintage_table

Cumulative bad rates by cohort and month on book.

kivi.datasets.make_loan_panel

Synthetic loan panel with early repayments.

Notes

For an account \(i\) with the duration \(T_i\), the entry \(e_i\) and the weight \(w_i\), 1 without weights, the columns of period \(t\) are:

  • at_risk: \(n_t = \sum_i w_i \, [e_i < t \le T_i]\), the accounts at risk of default in the period;

  • event: \(d_t\), the weight of the accounts that defaulted in the period;

  • competing: \(c_t\), that of the accounts that left for another reason;

  • censored: that of the accounts last observed in the period without a default or an exit;

  • hazard: \(h_t = d_t / n_t\), the share of the accounts at risk that defaulted;

  • survival: \(S(t) = \prod_{s \le t} (1 - (d_s + c_s) / n_s)\), the probability of neither a default nor an exit by the end of the period, with \(S(0) = 1\);

  • cumulative_pd: the probability of a default by the end of the period.

Without competing, \(c_t = 0\), and cumulative_pd is the Kaplan–Meier estimate

\[F(t) = 1 - \prod_{s \le t} (1 - h_s) = 1 - S(t).\]

With competing, it is the Aalen–Johansen estimate of the cumulative incidence of default, which adds up the defaults of the accounts that have neither defaulted nor left before:

\[F(t) = \sum_{s \le t} S(s - 1) \, h_s.\]

The accounts censored in a period are at risk in that period: their censoring comes after the defaults and the exits of the period. A period without accounts at risk has a NaN hazard, and survival and cumulative_pd are NaN from that period on, because the share of accounts that get through it is not known. With entry this also happens in the first periods if no account is observed in them; the hazards of the later periods then give the PDs conditional on reaching them.

An account that leaves early can no longer default. Counting it as censored, as 1 − Kaplan–Meier does, estimates the PD of an account that stays on book until its default, and overstates the share of the accounts that default: pass the early exits as competing instead. If every account is observed from period 1 until it defaults or leaves, or until a last period common to all of them, the cumulative incidence is the share of the accounts that defaulted by each period, the cumulative bad rate of kivi.vintage.vintage_table.

cumulative_pd is a cumulative term structure for convert_pd. Without competing, its conditional PDs are the hazards. With competing, they are conditional on no default before, also counting the accounts that left, as in a vintage table, while the hazards are conditional on the account being still on book.

References

[1]

E. L. Kaplan and P. Meier, “Nonparametric estimation from incomplete observations”, Journal of the American Statistical Association, 53(282), pp. 457-481, 1958.

[2]

O. O. Aalen and S. Johansen, “An empirical transition matrix for non-homogeneous Markov chains based on censored observations”, Scandinavian Journal of Statistics, 5(3), pp. 141-150, 1978.

Examples

Eight loans over three months: three default, two repay early and three are still on book when the observation ends.

>>> from kivi.lifetime import survival_table
>>> duration = [1, 1, 2, 2, 2, 3, 3, 3]
>>> event = [1, 0, 1, 0, 0, 1, 0, 0]
>>> repaid = [0, 1, 0, 1, 0, 0, 0, 0]
>>> survival_table(duration, event, competing=repaid).round(4)
        at_risk  event  competing  censored  hazard  survival  cumulative_pd
period
1             8      1          1         0  0.1250    0.7500         0.1250
2             6      1          1         1  0.1667    0.5000         0.2500
3             3      1          0         2  0.3333    0.3333         0.4167

In the third month, half of the loans are still on book, and a third of them default: 0.25 + 0.5 × 1/3 = 0.4167. Counting the early repayments as censored gives the Kaplan–Meier estimate 1 − (7/8)(5/6)(2/3), which is higher:

>>> survival_table(duration, event)["cumulative_pd"].round(4)
period
1    0.1250
2    0.2708
3    0.5139
Name: cumulative_pd, dtype: float64
kivi.lifetime.expected_credit_loss(probability, lgd, ead, *, rate, horizon=None)#

Compute the 12-month or lifetime expected credit loss of each account.

The expected credit loss of IFRS 9 adds up, over the periods after the reporting date, the probability of a default in each period times the loss given default and the exposure at default in that period, discounted to the reporting date at the effective interest rate. Pass the number of periods in 12 months as horizon for the 12-month expected credit loss of stage 1, and leave it out for the lifetime expected credit loss of stages 2 and 3.

Parameters:
probabilityarray_like or pandas.DataFrame

Marginal PDs with one row per account and one column per period after the reporting date: column \(t\) holds the probability, seen at the reporting date, that the account defaults in period \(t\). Each row adds up to at most 1. convert_pd gives the marginal PDs of a cumulative or conditional term structure. Booleans count as 0 and 1.

lgdfloat, array_like or pandas.DataFrame

Loss given default as a share of the exposure at default, from 0 to 1: one value for all accounts and periods, a one-dimensional array_like with one value per account, or a two-dimensional schedule with one value per account and period. A two-dimensional array may also have one row for all accounts or one column for all periods.

eadfloat, array_like or pandas.DataFrame

Exposure at default, finite and non-negative, in the same forms as lgd: one value, one value per account, such as the balance at the reporting date, or a schedule, such as the balance expected in each period. Give the periods after the maturity of an account an exposure of 0. Series and DataFrames with one row per account must have identical indices, and DataFrames with one column per period identical columns. A single row or column is broadcast, so with one account or one period only the labels of probability are used.

ratefloat or array_like

Effective interest rate per period at which the losses are discounted, greater than -1, as one value or one value per account. For monthly periods and an annual rate \(r\), pass \((1 + r)^{1/12} - 1\). Pass 0 to leave the losses undiscounted.

horizonint, optional

Number of periods to add up, starting from period 1: 12 for monthly periods, or 1 for annual ones, gives the 12-month expected credit loss. By default all the periods of probability, which give the lifetime expected credit loss.

Returns:
pandas.Series or numpy.ndarray

Expected credit loss of each account, in the units of ead. If probability is a DataFrame, or another input with one row per account of several is a pandas object, a Series named expected_credit_loss with its index; otherwise an array.

Raises:
ValueError

If probability is not two-dimensional with at least one account and one period, an input is not real and numeric or does not have one of the shapes described, or pandas inputs have different indices or columns. Also if probability or lgd has a value outside [0, 1], a row of probability adds up to more than 1, ead has a negative or infinite value, rate is infinite, not greater than -1 or makes a discount factor overflow, or horizon is not a positive integer up to the number of periods.

See also

convert_pd

Marginal PDs from cumulative or conditional ones.

transition_pd

Cumulative PDs from a transition matrix.

assign_stages

Stage of each account, which decides the horizon.

stage_table

Exposure and expected credit loss by stage.

kivi.strategy.expected_loss

Expected loss over a single horizon.

Notes

For an account with the marginal PD \(m_t\), the loss given default \(\mathrm{LGD}_t\) and the exposure at default \(\mathrm{EAD}_t\) of period \(t\), and the effective interest rate \(r\) per period,

\[\mathrm{ECL} = \sum_{t=1}^{H} m_t \, \mathrm{LGD}_t \, \mathrm{EAD}_t \, (1 + r)^{-t},\]

where \(H\) is horizon or the number of periods. The conventions are:

  • Period 1 starts at the reporting date and ends one period later; period \(t\) ends \(t\) periods after the reporting date.

  • A default in period \(t\) is taken to occur at the end of the period, so its loss is discounted over \(t\) periods.

  • The marginal PDs are not conditional on survival: they are seen from the reporting date and add up to the cumulative PD. For an account that has not defaulted by the reporting date, convert the conditional PDs of its term structure from its age at the reporting date on, with kind="conditional" and to="marginal".

  • The columns must cover the remaining life of the longest account. An account that matures within the horizon has an exposure of 0 after maturity, so its 12-month and lifetime expected credit losses are equal.

An exposure already in default at the reporting date has defaulted at that date, not at the end of a period. Give it a marginal PD of 1 in period 1 and a rate of 0, so that its expected credit loss is its LGD times its EAD: the LGD of a defaulted exposure usually discounts the recoveries already.

A missing PD, LGD or EAD in a period that is added up, or a missing rate, gives the account a missing expected credit loss, as in kivi.strategy.expected_loss. Missing values in the periods after horizon are not used.

Examples

>>> from kivi.lifetime import expected_credit_loss
>>> marginal = [[0.02, 0.03, 0.03], [0.10, 0.08, 0.06]]
>>> schedule = [[1000.0, 700.0, 400.0], [500.0, 250.0, 0.0]]
>>> expected_credit_loss(marginal, 0.5, schedule, rate=0.05).round(2)
array([24.23, 32.88])
>>> expected_credit_loss(marginal, 0.5, schedule, rate=0.05, horizon=1).round(2)
array([ 9.52, 23.81])

The first account loses 0.02 × 0.5 × 1000 / 1.05 = 9.52 in period 1, 0.03 × 0.5 × 700 / 1.05² = 9.52 in period 2 and 0.03 × 0.5 × 400 / 1.05³ = 5.18 in period 3.

kivi.lifetime.significant_increase(probability, origination_probability, *, relative, absolute)#

Flag a significant increase in credit risk since initial recognition.

IFRS 9 moves an exposure to stage 2 when its credit risk has increased significantly since initial recognition. A common quantitative test compares the PD at the reporting date with the PD expected at origination, as a ratio, a difference or both. The thresholds are the policy of the reporting entity, not values set by the standard, so they have no defaults.

Parameters:
probabilityarray_like

PD of each exposure at the reporting date, from 0 to 1.

origination_probabilityarray_like

PD of each exposure expected at initial recognition for the same period, from 0 to 1. If both inputs are Series, they must have identical indices; otherwise they are matched by position.

relativefloat or None

The increase is significant if probability is more than relative times origination_probability, so 2 flags the PDs that more than doubled. It must be greater than 1. None leaves out this test.

absolutefloat or None

The increase is significant if probability exceeds origination_probability by more than absolute, in units of PD, so 0.01 flags the PDs that rose by more than one percentage point. It must be between 0 and 1. None leaves out this test.

Returns:
pandas.Series or numpy.ndarray

Booleans that are True for a significant increase. If an input is a Series, a Series named significant_increase with its index; otherwise an array.

Raises:
ValueError

If the inputs are empty, not one-dimensional, of different lengths, Series with different indices, not real and numeric, or have a missing value or a value outside [0, 1]. Also if relative is not None or a number greater than 1, absolute is not None or a number between 0 and 1, or both are None.

See also

assign_stages

Stages from the flags and the days past due.

convert_pd

Cumulative PDs over the remaining life from a term structure.

transition_pd

Cumulative PDs from a transition matrix.

Notes

With the PD \(p\) at the reporting date and the PD \(p_0\) expected at origination, the tests are

\[p > \mathrm{relative} \cdot p_0 \qquad \text{and} \qquad p - p_0 > \mathrm{absolute}.\]

Both comparisons are strict, and a PD that meets a threshold up to the rounding of floating-point numbers, within a few units in the last place of the PD, meets it exactly: in floating point, 0.04 - 0.03 exceeds 0.01 and 1.5 * 0.30 is below 0.45, but neither pair is flagged.

With both thresholds, an increase is significant only if it passes both tests, so that the absolute threshold keeps small changes of low PDs from counting. For a rule under which either test suffices, combine two calls with |, each with one threshold. Qualitative criteria, such as a watch list or forbearance, combine with the flags in the same way.

IFRS 9 assesses the change in the risk of a default over the expected life of the exposure, and allows the risk over the next 12 months where it gives a reasonable approximation. Compare PDs of the same horizon: for a lifetime PD, the PD over the same remaining life that was expected at origination.

Examples

>>> from kivi.lifetime import significant_increase
>>> probability = [0.004, 0.012, 0.03, 0.09]
>>> origination_probability = [0.001, 0.010, 0.01, 0.05]
>>> significant_increase(
...     probability, origination_probability, relative=2.0, absolute=None
... )
array([ True, False,  True, False])
>>> significant_increase(
...     probability, origination_probability, relative=2.0, absolute=0.01
... )
array([False, False,  True, False])

The first PD quadrupled but rose by only 0.3 percentage points, and the last one rose by 4 points without doubling.

kivi.lifetime.assign_stages(significant_increase, days_past_due=None, defaulted=None, *, stage_2_days=30, stage_3_days=90)#

Allocate exposures to the three stages of IFRS 9.

Stage 1 holds the exposures whose credit risk has not increased significantly since initial recognition, stage 2 those whose credit risk has, and stage 3 the credit-impaired exposures. The days past due act as backstops: an exposure more than stage_2_days past due is at least in stage 2, and one at least stage_3_days past due, or flagged as defaulted, is in stage 3.

Parameters:
significant_increasearray_like

Whether the credit risk of each exposure has increased significantly since initial recognition, as booleans or 0 and 1, such as the result of the function significant_increase, possibly combined with qualitative criteria.

days_past_duearray_like, optional

Days past due of each exposure at the reporting date, finite and non-negative. Without it, the backstops do not apply.

defaultedarray_like, optional

Whether each exposure is credit-impaired, usually because it is in default under the entity’s definition of default, as booleans or 0 and 1. These exposures are in stage 3.

stage_2_daysfloat, default 30

Exposures more than this many days past due are at least in stage 2. The default follows the rebuttable presumption of IFRS 9, paragraph 5.5.11, that credit risk has increased significantly when contractual payments are more than 30 days past due.

stage_3_daysfloat, default 90

Exposures this many days past due or more are in stage 3. The default follows the rebuttable presumption of IFRS 9, paragraph B5.5.37, that default occurs no later than when a financial asset is 90 days past due. It must be greater than stage_2_days.

Returns:
pandas.Series or numpy.ndarray

Stage of each exposure, 1, 2 or 3, as integers. If an input is a Series, a Series named stage with its index; otherwise an array.

Raises:
ValueError

If the inputs are empty, not one-dimensional, of different lengths or Series with different indices, significant_increase or defaulted has a value other than 0 and 1, or days_past_due is not real and numeric or has a missing, negative or infinite value. Also if stage_2_days or stage_3_days is not a finite, non-negative number, or stage_3_days is not greater than stage_2_days.

See also

significant_increase

Quantitative test of a significant increase.

stage_table

Exposure and expected credit loss by stage.

expected_credit_loss

12-month and lifetime expected credit losses.

Notes

The stage of an exposure is 3 if it is defaulted or at least stage_3_days past due, otherwise 2 if significant_increase is true or it is more than stage_2_days past due, and otherwise 1. With the defaults, an exposure exactly 30 days past due therefore stays in stage 1, and one exactly 90 days past due is in stage 3, as the wording of the two presumptions says.

IFRS 9 defines credit-impaired exposures by events that hurt their expected cash flows, such as a default or the significant financial difficulty of the borrower. In practice, entities usually align them with their definition of default. The thresholds, the definition of default and the treatment of cures are the policy of the reporting entity. Probation periods, during which an exposure that no longer meets a criterion stays in its stage, need the history of each exposure and are not applied.

Examples

>>> from kivi.lifetime import assign_stages
>>> increase = [False, True, False, False, False]
>>> days_past_due = [0, 0, 45, 90, 0]
>>> defaulted = [False, False, False, False, True]
>>> assign_stages(increase, days_past_due, defaulted)
array([1, 2, 2, 3, 3])
kivi.lifetime.stage_table(stage, exposure, allowance, *, weights=None)#

Summarize the exposure and the expected credit loss of each stage.

Each row adds up the exposures and the loss allowances of one stage and gives their ratio, the coverage ratio that banks report by stage.

Parameters:
stagearray_like

Stage of each exposure, 1, 2 or 3, such as the result of assign_stages.

exposurearray_like

Exposure of each account at the reporting date, such as its gross carrying amount, finite and non-negative.

allowancearray_like

Loss allowance of each account, finite and non-negative: its 12-month expected credit loss in stage 1 and its lifetime expected credit loss in stages 2 and 3. Series inputs must have identical indices; otherwise the inputs are matched by position.

weightsarray_like, optional

Non-negative weight of each exposure, such as the inverse of its sampling rate, matched like exposure. Counts, exposures and allowances become sums of weights, so integer weights give the same table as repeating rows.

Returns:
pandas.DataFrame

One row for each of the stages 1, 2 and 3, indexed by stage, also for a stage without exposures, with the columns described in the Notes.

Raises:
ValueError

If the inputs are empty, not one-dimensional, of different lengths or Series with different indices, or not real and numeric. Also if stage has a value other than 1, 2 and 3, exposure or allowance has a missing, negative or infinite value, or weights is not numeric or does not give each exposure one finite, non-negative weight with a positive total.

See also

assign_stages

Stage of each exposure.

expected_credit_loss

12-month and lifetime expected credit losses.

kivi.strategy.expected_loss_table

Exposure and expected loss by grade.

Notes

For the exposures \(i\) of a stage, with weights \(w_i\), 1 without weights, the columns are:

  • total: the number of exposures, \(\sum_i w_i\);

  • exposure: \(\sum_i w_i E_i\), with the exposures \(E_i\);

  • exposure_share: the stage’s share of the exposure of all stages, NaN for every stage when the total exposure is 0;

  • expected_credit_loss: \(\sum_i w_i L_i\), with the loss allowances \(L_i\);

  • coverage: expected_credit_loss divided by exposure, NaN for a stage without exposure.

The portfolio’s exposure and loss allowance are the sums of the exposure and expected_credit_loss columns, and its coverage ratio is the second sum divided by the first.

Examples

>>> from kivi.lifetime import stage_table
>>> stage = [1, 1, 1, 2, 3]
>>> exposure = [1000.0, 2000.0, 1000.0, 800.0, 200.0]
>>> allowance = [5.0, 8.0, 3.0, 40.0, 90.0]
>>> stage_table(stage, exposure, allowance)
       total  exposure  exposure_share  expected_credit_loss  coverage
stage
1          3    4000.0            0.80                  16.0     0.004
2          1     800.0            0.16                  40.0     0.050
3          1     200.0            0.04                  90.0     0.450