# transprob

Estimate transition probabilities from credit ratings data

## Syntax

`[transMat, sampleTotals, idTotals] = transprob(data)[transMat, sampleTotals, idTotals] = transprob(data,Name, Value)`

## Description

`[transMat, sampleTotals, idTotals] = transprob(data)` constructs a transition matrix from historical data of credit ratings.

`[transMat, sampleTotals, idTotals] = transprob(data,Name, Value)` constructs a transition matrix from historical data of credit ratings with additional options specified by one or more `Name, Value` pair arguments.

## Input Arguments

 `data` Using `transprob` to estimate transition probabilities given credit ratings historical data (that is, credit migration data), the `data` input can be either of the following:A preprocessed data structure obtained using `transprobprep`. This data structure contains the fields`'idStart'`, `'numericDates'`, `'numericRatings'`, and `'ratingsLabels'`.orAn `nRecords`-by-3 cell array containing the historical credit ratings data of the form:```'00010283' '10-Nov-1984' 'CCC' '00010283' '12-May-1986' 'B' '00010283' '29-Jun-1988' 'CCC' '00010283' '12-Dec-1991' 'D' '00013326' '09-Feb-1985' 'A' '00013326' '24-Feb-1994' 'AA' '00013326' '10-Nov-2000' 'BBB' '00014413' '23-Dec-1982' 'B'```where each row contains an ID (column 1), a date (column 2), and a credit rating (column 3). Column 3 is the rating assigned to the corresponding ID on the corresponding date. All information corresponding to the same ID must be stored in contiguous rows. Sorting this information by date is not required, but recommended for efficiency. IDs, dates, and ratings are usually stored in string format, but they can also be entered in numeric format.

### Name-Value Pair Arguments

Specify optional comma-separated pairs of `Name,Value` arguments. `Name` is the argument name and `Value` is the corresponding value. `Name` must appear inside single quotes (`' '`). You can specify several name and value pair arguments in any order as `Name1,Value1,...,NameN,ValueN`.

 `'algorithm'` Estimation algorithm, in string format. Valid values are `duration` or `cohort`. Default: `duration` `'endDate'` End date of the estimation time window, in string or numeric format. The `endDate` cannot be a date before the `startDate`. Default: Latest date in `data` `'labels'` Cell array of size `nRatings`-by-`1`, or `1`-by-`nRatings`, containing the credit-rating scale. It must be consistent with the ratings labels used in the third column of `data`. Default: `{'AAA','AA','A','BBB','BB','B','CCC','D'}` `'snapsPerYear'` Integer indicating the number of credit-rating snapshots per year to be considered for the estimation. Valid values are 1, 2, 3, 4, 6, 12. This parameter is only used with the `cohort` algorithm. Default: `1` — One snapshot per year `'startDate'` Start date of the estimation time window, in string or numeric format. Default: Earliest date in `data` `'transInterval'` Length of the transition interval, in years. Default: `1` — One year transition probabilities

## Output Arguments

 `transMat` Matrix of transition probabilities in percent. The size of the transition matrix is `nRatings`-by-`nRatings`. `sampleTotals` Structure with fields:`totalsVec` — A vector of size `1`-by-`nRatings`.`totalsMat` — A matrix of size `nRatings`-by-`nRatings`.`algorithm` — A string with values `'duration'` or `'cohort'`. For the `'duration'` algorithm, `totalsMat`(i,j) contains the total transitions observed out of rating i into ratingj (all the diagonal elements are zero). The total time spent on rating i is stored in `totalsVec`(i). For example, if there are three rating categories, Investment Grade (`IG`), Speculative Grade (`SG`), and Default (`D`), and the following information:```Total time spent IG SG D in rating: 4859.09 1503.36 1162.05 Transitions IG SG D out of (row) IG 0 89 7 into (column): SG 202 0 32 D 0 0 0```Then```totals.totalsVec = [4859.09 1503.36 1162.05] totals.totalsMat = [ 0 89 7 202 0 32 0 0 0] totals.algorithm = 'duration'``` For the `'cohort'` algorithm, `totalsMat`(i,j) contains the total transitions observed from rating i to rating j, and `totalsVec`(i) is the initial count in rating i. For example, given the following information:```Initial count IG SG D in rating: 4808 1572 1145 Transitions IG SG D from (row) IG 4721 80 7 to (column): SG 193 1347 32 D 0 0 1145``` Then ```totals.totalsVec = [4808 1572 1145] totals.totalsMat = [4721 80 7 193 1347 32 0 0 1145 totals.algorithm = 'cohort'``` `idTotals` Struct array of size `nIDs`-by-`1`, where nIDs is the number of distinct IDs in column 1 of `data` when this is a cell array or, equivalently, equal to the length of the `idStart` field minus 1 when `data` is a preprocessed data structure. For each ID in the sample, `idTotals` contains one structure with the following fields:`totalsVec` — A sparse vector of size `1`-by-`nRatings`.`totalsMat` — A sparse matrix of size `nRatings`-by-`nRatings`.`algorithm` — A string with values `'duration'` or `'cohort'`. These fields contain the same information described for the output `sampleTotals`, but at an ID level. For example, for `'duration'`, `idTotals`(k).`totalsVec` contains the total time that the k-th company spent on each rating.

## Examples

collapse all

### Construct a Transition Matrix From Historical Data of Credit Ratings

Using the historical credit rating input data from `Data_TransProb.mat` display the first ten rows and compute the transition matrix:

```load Data_TransProb data(1:10,:) % Estimate transition probabilities with default settings transMat = transprob(data) ```
```ans = '00010283' '10-Nov-1984' 'CCC' '00010283' '12-May-1986' 'B' '00010283' '29-Jun-1988' 'CCC' '00010283' '12-Dec-1991' 'D' '00013326' '09-Feb-1985' 'A' '00013326' '24-Feb-1994' 'AA' '00013326' '10-Nov-2000' 'BBB' '00014413' '23-Dec-1982' 'B' '00014413' '20-Apr-1988' 'BB' '00014413' '16-Jan-1998' 'B' transMat = Columns 1 through 7 93.1170 5.8428 0.8232 0.1763 0.0376 0.0012 0.0001 1.6166 93.1518 4.3632 0.6602 0.1626 0.0055 0.0004 0.1237 2.9003 92.2197 4.0756 0.5365 0.0661 0.0028 0.0236 0.2312 5.0059 90.1846 3.7979 0.4733 0.0642 0.0216 0.1134 0.6357 5.7960 88.9866 3.4497 0.2919 0.0010 0.0062 0.1081 0.8697 7.3366 86.7215 2.5169 0.0002 0.0011 0.0120 0.2582 1.4294 4.2898 81.2927 0 0 0 0 0 0 0 Column 8 0.0017 0.0396 0.0753 0.2193 0.7050 2.4399 12.7167 100.0000 ```

Using the historical credit rating input data from `Data_TransProb.mat`, compute the transition matrix using the `cohort` algorithm:

```%Estimate transition probabilities with 'cohort' algorithm transMatCoh = transprob(data,'algorithm','cohort') ```
```transMatCoh = Columns 1 through 7 93.1345 5.9335 0.7456 0.1553 0.0311 0 0 1.7359 92.9198 4.5446 0.6046 0.1560 0 0 0.1268 2.9716 91.9913 4.3124 0.4711 0.0544 0 0.0210 0.3785 5.0683 89.7792 4.0379 0.4627 0.0421 0.0221 0.1105 0.6851 6.2320 88.3757 3.6464 0.2873 0 0 0.0761 0.7230 7.9909 86.1872 2.7397 0 0 0 0.3094 1.8561 4.5630 80.8971 0 0 0 0 0 0 0 Column 8 0 0.0390 0.0725 0.2103 0.6409 2.2831 12.3743 100.0000 ```

Using the historical credit rating data with ratings investment grade (`'IG'`), speculative grade (`'SG'`), and default (`'D'`), from `Data_TransProb.mat` display the first ten rows and compute the transition matrix:

```dataIGSG(1:10,:) transMatIGSG = transprob(dataIGSG,'labels',{'IG','SG','D'}) ```
```ans = '00011253' '04-Apr-1983' 'IG' '00012751' '17-Feb-1985' 'SG' '00012751' '19-May-1986' 'D' '00014690' '17-Jan-1983' 'IG' '00012144' '21-Nov-1984' 'IG' '00012144' '25-Mar-1992' 'SG' '00012144' '07-May-1994' 'IG' '00012144' '23-Jan-2000' 'SG' '00012144' '20-Aug-2001' 'IG' '00012937' '07-Feb-1984' 'IG' transMatIGSG = 98.6719 1.2020 0.1261 3.5781 93.3318 3.0901 0 0 100.0000 ```

Using the historical credit rating data with numeric ratings for investment grade (`1`), speculative grade (`2`), and default (`3`), from `Data_TransProb.mat` display the first ten rows and compute the transition matrix:

```dataIGSGnum(1:10,:) transMatIGSGnum = transprob(dataIGSGnum,'labels',{1,2,3}) ```
```ans = '00011253' '04-Apr-1983' [1] '00012751' '17-Feb-1985' [2] '00012751' '19-May-1986' [3] '00014690' '17-Jan-1983' [1] '00012144' '21-Nov-1984' [1] '00012144' '25-Mar-1992' [2] '00012144' '07-May-1994' [1] '00012144' '23-Jan-2000' [2] '00012144' '20-Aug-2001' [1] '00012937' '07-Feb-1984' [1] transMatIGSGnum = 98.6719 1.2020 0.1261 3.5781 93.3318 3.0901 0 0 100.0000 ```

collapse all

### Cohort Estimation

The cohort algorithm estimates the transition probabilities based on a sequence of snapshots of credit ratings at regularly spaced points in time. If the credit rating of a company changes twice between two snapshot dates, the intermediate rating is overlooked and only the initial and final ratings influence the estimates.

### Duration Estimation

Unlike the cohort method, the duration algorithm estimates the transition probabilities based on the full credit ratings history, looking at the exact dates on which the credit rating migrations occur. There is no concept of snapshots in this method, and all credit rating migrations influence the estimates, even when a company's rating changes twice within a short time.

### Cohort Estimation

The algorithm first determines a sequence t0,...,tK of snapshot dates. The elapsed time, in years, between two consecutive snapshot dates tk-1 and tk is equal to `1` / ns, where ns is the number of snapshots per year. These K +`1` dates determine K transition periods.

The algorithm computes ${N}_{i}^{n}$, the number of transition periods in which obligor n starts at rating i. These are added up over all obligors to get Ni, the number of obligors in the sample that start a period at rating i. The number periods in which obligor n starts at rating i and ends at rating j, or migrates from i to j, denoted by${N}_{ij}^{n}$, is also computed. These are also added up to get ${N}_{ij}^{}$, the total number of migrations from i to j in the sample.

The estimate of the transition probability from i to j in one period, denoted by${P}_{ij}^{}$, is given by:

${P}_{ij}^{}=\frac{Nij}{Ni}$

These probabilities are arranged in a one-period transition matrix P0, where the i,j entry in P0 is Pij.

If the number of snapshots per year ns is 4 (quarterly snapshots), the probabilities in P0 are 3-month (or 0.25-year) transition probabilities. You may, however, be interested in 1-year or 2-year transition probabilities. The latter time interval is called the transition interval, Δt , and it is used to convert P0 into the final transition matrix, P, according to the formula:

$P={P}_{0}^{ns△t}$

For example, if ns = `4` and Δt = `2`, P contains the 2-year transition probabilities estimated from quarterly snapshots.

 Note:   For the cohort algorithm, optional output arguments `idTotals` and `sampleTotals` from `transprob` contain the following information:`idTotals(n).totalsVec` = $\left({N}_{i}^{n}\right)\forall i$`idTotals(n).totalsMat` = $\left({N}_{i,j}^{n}\right)\forall ij$`idTotals(n).algoritm` = `'cohort'``sampleTotals.totalsVec` = $\left({N}_{i}^{}\right)\forall i$`sampleTotals.totalsMat` = $\left({N}_{i,j}^{}\right)\forall ij$`sampleTotals.algoritm` = `'cohort'` For efficiency, the vectors and matrices in `idTotals` are stored as sparse arrays.

### Duration Estimation

The algorithm computes ${T}_{i}^{n}$, the total time that obligor n spends in rating i within the estimation time window. These quantities are added up over all obligors to get ${T}_{i}^{}$, the total time spent in rating i, collectively, by all obligors in the sample. The algorithm also computes ${T}_{ij}^{n}$, the number times that obligor n migrates from rating i to rating j, with i not equal to j, within the estimation time window. And it also adds them up to get ${T}_{ij}^{}$, the total number of migrations, by all obligors in the sample, from the rating i to j, with i not equal to j.

To estimate the transition probabilities, the duration algorithm first needs to compute a generator matrix $\Lambda$. Each off-diagonal entry of this matrix is an estimate of the transition rate out of rating i into rating j, and is given by:

${\lambda }_{ij}^{}=\frac{{T}_{ij}^{}}{{T}_{i}^{}},i\ne j$

The diagonal entries are computed as:

${\lambda }_{ii}^{}=-\sum _{j\ne i}^{}{\lambda }_{ij}^{}$

With the generator matrix and the transition interval Δt (e.g., Δt = `2` corresponds to 2-year transition probabilities), the transition matrix is obtained as $P=\mathrm{exp}\left(\Delta t\Lambda \right)$, where exp denotes matrix exponentiation (`expm` in MATLAB®).

 Note:   For the duration algorithm, optional output arguments `idTotals` and `sampleTotals` from `transprob` contain the following information: `idTotals(n).totalsVec` = $\left({T}_{i}^{n}\right)\forall i$ `idTotals(n).totalsMat` = $\left({T}_{i,j}^{n}\right)\forall ij$`idTotals(n).algoritm` = `'duration'``sampleTotals.totalsVec` = $\left({T}_{i}^{}\right)\forall i$`sampleTotals.totalsMat` = $\left({T}_{i,j}^{}\right)\forall ij$`sampleTotals.algoritm` = `'duration'`For efficiency, the vectors and matrices in `idTotals` are stored as sparse arrays.

## References

Hanson, S., T. Schuermann, "Confidence Intervals for Probabilities of Default," Journal of Banking & Finance, Elsevier, vol. 30(8), pages 2281–2301, August 2006.

Löffler, G., P. N. Posch, Credit Risk Modeling Using Excel and VBA, West Sussex, England: Wiley Finance, 2007.

Schuermann, T., "Credit Migration Matrices," in E. Melnick, B. Everitt (eds.), Encyclopedia of Quantitative Risk Analysis and Assessment, Wiley, 2008.