eqlx-credit 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- eqlx_credit-0.2.0/LICENSE +176 -0
- eqlx_credit-0.2.0/PKG-INFO +198 -0
- eqlx_credit-0.2.0/README.md +177 -0
- eqlx_credit-0.2.0/pyproject.toml +76 -0
- eqlx_credit-0.2.0/pyproject.toml.orig +57 -0
- eqlx_credit-0.2.0/src/eqlx_credit/__init__.py +87 -0
- eqlx_credit-0.2.0/src/eqlx_credit/_checks.py +52 -0
- eqlx_credit-0.2.0/src/eqlx_credit/_vasicek.py +27 -0
- eqlx_credit-0.2.0/src/eqlx_credit/backtesting.py +212 -0
- eqlx_credit-0.2.0/src/eqlx_credit/calibration.py +158 -0
- eqlx_credit-0.2.0/src/eqlx_credit/cohorts.py +133 -0
- eqlx_credit-0.2.0/src/eqlx_credit/discrimination.py +159 -0
- eqlx_credit-0.2.0/src/eqlx_credit/irb.py +98 -0
- eqlx_credit-0.2.0/src/eqlx_credit/ldp.py +124 -0
- eqlx_credit-0.2.0/src/eqlx_credit/master_scale.py +86 -0
- eqlx_credit-0.2.0/src/eqlx_credit/py.typed +0 -0
- eqlx_credit-0.2.0/src/eqlx_credit/stability.py +52 -0
- eqlx_credit-0.2.0/src/eqlx_credit/validation.py +26 -0
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: eqlx-credit
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Open tools for credit-risk model work: PD validation tests, calibration, master scales and low-default portfolio methods.
|
|
5
|
+
Keywords: credit risk,probability of default,IRB,Basel,model validation,low default portfolio
|
|
6
|
+
Author: Can Demir
|
|
7
|
+
Author-email: Can Demir <can.demir@eqlx.ai>
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Topic :: Office/Business :: Financial
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
16
|
+
Requires-Dist: numpy>=1.26
|
|
17
|
+
Requires-Dist: scipy>=1.11
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Project-URL: Homepage, https://eqlx.org
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
# eqlx-credit
|
|
23
|
+
|
|
24
|
+
Open tools for credit-risk model work: discriminatory power with confidence intervals, PD back-testing
|
|
25
|
+
that allows for correlated defaults, cohort default rates, calibration, master scales, low-default
|
|
26
|
+
portfolio methods and the Basel IRB risk-weight functions.
|
|
27
|
+
|
|
28
|
+
Built by [eqlx](https://eqlx.ai) from public regulation and published research. Part of
|
|
29
|
+
[eqlx.org](https://eqlx.org).
|
|
30
|
+
|
|
31
|
+
> Status: alpha (0.2). Every function is tested against a closed form, a published table or worked
|
|
32
|
+
> example, a brute-force calculation, or a simulation. The API may still change.
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install git+https://github.com/eqlx-ai/eqlx-credit
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Python 3.10+, depends only on NumPy and SciPy.
|
|
41
|
+
|
|
42
|
+
## What is inside
|
|
43
|
+
|
|
44
|
+
| Area | Function | What it answers | Source |
|
|
45
|
+
|---|---|---|---|
|
|
46
|
+
| Discrimination | `auc`, `gini`, `ks`, `auc_from_counts` | Does the model rank defaulters above non-defaulters? | |
|
|
47
|
+
| | `auc_ci`, `auc_ci_from_counts` | How precise is that AUC? (DeLong standard error) | DeLong et al. (1988) |
|
|
48
|
+
| | `auc_decline_test` | Has the AUC fallen significantly since initial validation? | ECB validation reporting instructions (2019) |
|
|
49
|
+
| PD back-testing | `jeffreys_test` | Is each grade's PD consistent with its defaults? | ECB validation reporting instructions (2019) |
|
|
50
|
+
| | `binomial_test(..., rho=)` | The same, optionally allowing for correlated defaults | BCBS WP14 (2005), Vasicek |
|
|
51
|
+
| | `traffic_light` | Green / yellow / red per grade at thresholds you set | Tasche (2003) |
|
|
52
|
+
| | `hosmer_lemeshow` | Are the PDs right across all grades at once? | |
|
|
53
|
+
| | `normal_test` | Are the PDs right across several years? | BCBS WP14 (2005) |
|
|
54
|
+
| | `spiegelhalter` | Are obligor-level PDs right? | Spiegelhalter (1986) |
|
|
55
|
+
| Default rates | `cohort_default_rates`, `long_run_average` | One-year default rates per cohort and their long-run average | EBA/GL/2017/16 |
|
|
56
|
+
| Stability | `psi`, `hhi(..., exposure=)` | Has the portfolio moved? Is it concentrated (by count or exposure)? | Siddiqi (2006) |
|
|
57
|
+
| Calibration | `anchor_to_central_tendency` | Shift PDs to a target average, keeping the ranking | |
|
|
58
|
+
| | `fit_ct_ar`, `grade_positions` | Grade PDs from a central tendency and an accuracy ratio | Tasche (2013) |
|
|
59
|
+
| | `apply_pd_floor` | Regulatory PD floor | Basel II, CRR, Basel III |
|
|
60
|
+
| Low-default portfolios | `pluto_tasche` | Most prudent PD upper bounds, independent or correlated defaults | Pluto & Tasche (2005) |
|
|
61
|
+
| | `van_der_burgt` | Grade PDs from a fitted CAP curve | van der Burgt (2008) |
|
|
62
|
+
| Master scale | `geometric_master_scale`, `master_scale_from_midpoints` | The PD-to-grade ladder, with a separate defaulted grade | |
|
|
63
|
+
| Capital | `risk_weight`, `capital_requirement`, `asset_correlation` | Basel IRB risk weights: corporate (with SME adjustment and maturity), mortgage, QRRE, other retail | Basel II ¶272–330, Annex 5 |
|
|
64
|
+
|
|
65
|
+
Conventions: grades run from lowest to highest risk; by default a higher score means higher risk
|
|
66
|
+
(`higher_is_riskier=False` for scorecards where a high score is safe); `1` in a default flag means
|
|
67
|
+
default; a PD of 1 maps to the master scale's defaulted grade, never to a performing grade.
|
|
68
|
+
|
|
69
|
+
## Agent skill: annual PD validation
|
|
70
|
+
|
|
71
|
+
[`skills/annual-pd-validation`](skills/annual-pd-validation) is an Agent Skill that lets an AI agent prepare the
|
|
72
|
+
evidence for an annual PD validation: it runs every test through eqlx-credit, reads the results, and drafts the
|
|
73
|
+
report in the user's language. The agent never computes a number itself and never gives the validation opinion; the
|
|
74
|
+
conclusion and signature stay with the validator. On the bundled synthetic portfolio it finds the planted problems:
|
|
75
|
+
a significant AUC decline since initial validation and one grade with far more defaults than its PD implies.
|
|
76
|
+
|
|
77
|
+
## An annual validation pass
|
|
78
|
+
|
|
79
|
+
[`examples/validation_report.py`](examples/validation_report.py), on a synthetic grade table:
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
import numpy as np
|
|
83
|
+
import eqlx_credit as ec
|
|
84
|
+
|
|
85
|
+
n = np.array([820, 1450, 1910, 1320, 640, 210]) # obligors per grade at the start of the year
|
|
86
|
+
d = np.array([1, 4, 11, 19, 21, 17]) # defaults during the year
|
|
87
|
+
pd = np.array([0.0012, 0.0035, 0.0070, 0.0140, 0.0300, 0.0700])
|
|
88
|
+
|
|
89
|
+
cur = ec.auc_ci_from_counts(n, d) # AUC with DeLong confidence interval
|
|
90
|
+
ec.auc_decline_test(0.80, cur) # vs the AUC at initial validation
|
|
91
|
+
ec.jeffreys_test(n, d, pd).rows() # one dict per grade, ready for a report table
|
|
92
|
+
ec.traffic_light(n, d, pd, rho=0.12).colours # allowing for correlated defaults
|
|
93
|
+
ec.risk_weight(pd, 0.45) # Basel IRB, corporate, LGD 45%, M 2.5
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
```text
|
|
97
|
+
AUC 0.785 (95% CI 0.734-0.836), Gini 0.570
|
|
98
|
+
Decline vs initial 0.800: S = 0.57, p = 0.285
|
|
99
|
+
grade 1: 1 defaults vs 1.0 expected, Jeffreys p = 0.421, traffic light green
|
|
100
|
+
grade 2: 4 defaults vs 5.1 expected, Jeffreys p = 0.662, traffic light green
|
|
101
|
+
grade 3: 11 defaults vs 13.4 expected, Jeffreys p = 0.734, traffic light green
|
|
102
|
+
grade 4: 19 defaults vs 18.5 expected, Jeffreys p = 0.437, traffic light green
|
|
103
|
+
grade 5: 21 defaults vs 19.2 expected, Jeffreys p = 0.327, traffic light green
|
|
104
|
+
grade 6: 17 defaults vs 14.7 expected, Jeffreys p = 0.259, traffic light green
|
|
105
|
+
Normal test over 5 years: z = 0.89
|
|
106
|
+
Risk weights: 33.0% 58.8% 80.5% 103.4% 128.4% 168.9%
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## A low-default portfolio
|
|
110
|
+
|
|
111
|
+
[`examples/quickstart.py`](examples/quickstart.py):
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
n_obligors = np.array([120, 340, 510, 430, 260, 90])
|
|
115
|
+
n_defaults = np.array([0, 0, 1, 2, 3, 2])
|
|
116
|
+
|
|
117
|
+
ec.pluto_tasche(n_obligors, n_defaults, confidence=0.9, rho=0.12)
|
|
118
|
+
ec.fit_ct_ar(n_obligors, central_tendency=0.015, accuracy_ratio=0.65).pd
|
|
119
|
+
ec.van_der_burgt(n_obligors, central_tendency=0.015, accuracy_ratio=0.65).pd
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
```text
|
|
123
|
+
Pluto-Tasche (90%, rho=0.12): [ 2.511 2.652 3.172 4.263 6.336 10.761] %
|
|
124
|
+
CT/AR curve: [ 0.037 0.135 0.421 1.205 3.383 10.692] %
|
|
125
|
+
van der Burgt: [0.044 0.093 0.366 1.525 4.246 7.134] %
|
|
126
|
+
Master scale grades: [ 2 5 8 11 14 17]
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## How it is tested
|
|
130
|
+
|
|
131
|
+
- **Basel IRB:** all eight columns of Basel II Annex 5 ("Illustrative IRB Risk Weights") reproduced to
|
|
132
|
+
the published two decimals.
|
|
133
|
+
- **Pluto–Tasche:** the paper's worked example (0.29%, 0.33%, 0.76%).
|
|
134
|
+
- **DeLong:** against an explicit obligor-by-obligor placement calculation, and by simulation: the
|
|
135
|
+
standard error matches the spread of simulated AUCs and the 95% interval covers the true AUC about
|
|
136
|
+
95% of the time.
|
|
137
|
+
- **Correlated binomial:** against a Monte Carlo simulation of the one-factor model.
|
|
138
|
+
- **Spiegelhalter:** a hand calculation, and standard normal under correct PDs by simulation.
|
|
139
|
+
- **Cohorts:** hand-built panels, including the horizon boundary and 29 February.
|
|
140
|
+
|
|
141
|
+
## Notes on the methods
|
|
142
|
+
|
|
143
|
+
- Use the obligor-average PD at the start of the period per grade as the grade PD in back-tests.
|
|
144
|
+
- `binomial_test` with `rho=0` assumes independent defaults and rejects too often when defaults are
|
|
145
|
+
correlated; pass an asset correlation, or read it next to `traffic_light(..., rho=)`.
|
|
146
|
+
- Thresholds (test levels, traffic-light quantiles, PSI readings) are policy choices; set your own.
|
|
147
|
+
- `hosmer_lemeshow` uses `K` degrees of freedom for `K` grades (out-of-sample use).
|
|
148
|
+
- `pluto_tasche` is the single-period version; in practice the bounds are often rescaled to the central
|
|
149
|
+
tendency afterwards.
|
|
150
|
+
- `fit_ct_ar` uses Tasche's robust-logit grade positions by default but matches the accuracy ratio
|
|
151
|
+
exactly on the grade distribution rather than through his moment approximation;
|
|
152
|
+
`placement="even"` gives the v0.1 behaviour.
|
|
153
|
+
- `van_der_burgt` returns each grade's PD as the average slope of the CAP curve over that grade, so the
|
|
154
|
+
weighted mean equals the central tendency exactly; grading makes the grade-level AR a little lower.
|
|
155
|
+
- `risk_weight` defaults to no 1.06 scaling factor (Basel III final); pass `scaling=1.06` for Basel II /
|
|
156
|
+
CRR. PD floors differ by framework and are the caller's choice.
|
|
157
|
+
|
|
158
|
+
## References
|
|
159
|
+
|
|
160
|
+
- Basel Committee on Banking Supervision (2006). International Convergence of Capital Measurement and
|
|
161
|
+
Capital Standards, ¶272–330 and Annex 5.
|
|
162
|
+
- Basel Committee on Banking Supervision (2005). An Explanatory Note on the Basel II IRB Risk Weight
|
|
163
|
+
Functions.
|
|
164
|
+
- Basel Committee on Banking Supervision (2005). Studies on the validation of internal rating systems.
|
|
165
|
+
Working Paper No. 14.
|
|
166
|
+
- European Central Bank (2019). Instructions for reporting the validation results of internal models:
|
|
167
|
+
IRB Pillar I models for credit risk.
|
|
168
|
+
- European Banking Authority (2017). Guidelines on PD estimation, LGD estimation and the treatment of
|
|
169
|
+
defaulted exposures (EBA/GL/2017/16).
|
|
170
|
+
- DeLong, E. R., DeLong, D. M. and Clarke-Pearson, D. L. (1988). Comparing the areas under two or more
|
|
171
|
+
correlated receiver operating characteristic curves. *Biometrics* 44(3).
|
|
172
|
+
- Spiegelhalter, D. J. (1986). Probabilistic prediction in patient management and clinical trials.
|
|
173
|
+
*Statistics in Medicine* 5(5).
|
|
174
|
+
- Tasche, D. (2003). A traffic lights approach to PD validation. arXiv:cond-mat/0305038.
|
|
175
|
+
- Tasche, D. (2013). The art of probability-of-default curve calibration. *Journal of Credit Risk*
|
|
176
|
+
9(4). arXiv:1212.3716.
|
|
177
|
+
- Pluto, K. and Tasche, D. (2005). Thinking positively. *Risk*, August 2005. Longer version:
|
|
178
|
+
arXiv:cond-mat/0411699.
|
|
179
|
+
- van der Burgt, M. (2008). Calibrating low-default portfolios, using the cumulative accuracy profile.
|
|
180
|
+
*Journal of Risk Model Validation* 1(4).
|
|
181
|
+
- Vasicek, O. (2002). The distribution of loan portfolio value. *Risk*, December 2002.
|
|
182
|
+
- Siddiqi, N. (2006). *Credit Risk Scorecards*. Wiley.
|
|
183
|
+
|
|
184
|
+
## Development
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
uv sync
|
|
188
|
+
uv run pytest
|
|
189
|
+
uv run ruff check . && uv run ruff format --check . && uv run mypy src
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## Contributing
|
|
193
|
+
|
|
194
|
+
Issues and pull requests are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
195
|
+
|
|
196
|
+
## License
|
|
197
|
+
|
|
198
|
+
Apache-2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
# eqlx-credit
|
|
2
|
+
|
|
3
|
+
Open tools for credit-risk model work: discriminatory power with confidence intervals, PD back-testing
|
|
4
|
+
that allows for correlated defaults, cohort default rates, calibration, master scales, low-default
|
|
5
|
+
portfolio methods and the Basel IRB risk-weight functions.
|
|
6
|
+
|
|
7
|
+
Built by [eqlx](https://eqlx.ai) from public regulation and published research. Part of
|
|
8
|
+
[eqlx.org](https://eqlx.org).
|
|
9
|
+
|
|
10
|
+
> Status: alpha (0.2). Every function is tested against a closed form, a published table or worked
|
|
11
|
+
> example, a brute-force calculation, or a simulation. The API may still change.
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pip install git+https://github.com/eqlx-ai/eqlx-credit
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Python 3.10+, depends only on NumPy and SciPy.
|
|
20
|
+
|
|
21
|
+
## What is inside
|
|
22
|
+
|
|
23
|
+
| Area | Function | What it answers | Source |
|
|
24
|
+
|---|---|---|---|
|
|
25
|
+
| Discrimination | `auc`, `gini`, `ks`, `auc_from_counts` | Does the model rank defaulters above non-defaulters? | |
|
|
26
|
+
| | `auc_ci`, `auc_ci_from_counts` | How precise is that AUC? (DeLong standard error) | DeLong et al. (1988) |
|
|
27
|
+
| | `auc_decline_test` | Has the AUC fallen significantly since initial validation? | ECB validation reporting instructions (2019) |
|
|
28
|
+
| PD back-testing | `jeffreys_test` | Is each grade's PD consistent with its defaults? | ECB validation reporting instructions (2019) |
|
|
29
|
+
| | `binomial_test(..., rho=)` | The same, optionally allowing for correlated defaults | BCBS WP14 (2005), Vasicek |
|
|
30
|
+
| | `traffic_light` | Green / yellow / red per grade at thresholds you set | Tasche (2003) |
|
|
31
|
+
| | `hosmer_lemeshow` | Are the PDs right across all grades at once? | |
|
|
32
|
+
| | `normal_test` | Are the PDs right across several years? | BCBS WP14 (2005) |
|
|
33
|
+
| | `spiegelhalter` | Are obligor-level PDs right? | Spiegelhalter (1986) |
|
|
34
|
+
| Default rates | `cohort_default_rates`, `long_run_average` | One-year default rates per cohort and their long-run average | EBA/GL/2017/16 |
|
|
35
|
+
| Stability | `psi`, `hhi(..., exposure=)` | Has the portfolio moved? Is it concentrated (by count or exposure)? | Siddiqi (2006) |
|
|
36
|
+
| Calibration | `anchor_to_central_tendency` | Shift PDs to a target average, keeping the ranking | |
|
|
37
|
+
| | `fit_ct_ar`, `grade_positions` | Grade PDs from a central tendency and an accuracy ratio | Tasche (2013) |
|
|
38
|
+
| | `apply_pd_floor` | Regulatory PD floor | Basel II, CRR, Basel III |
|
|
39
|
+
| Low-default portfolios | `pluto_tasche` | Most prudent PD upper bounds, independent or correlated defaults | Pluto & Tasche (2005) |
|
|
40
|
+
| | `van_der_burgt` | Grade PDs from a fitted CAP curve | van der Burgt (2008) |
|
|
41
|
+
| Master scale | `geometric_master_scale`, `master_scale_from_midpoints` | The PD-to-grade ladder, with a separate defaulted grade | |
|
|
42
|
+
| Capital | `risk_weight`, `capital_requirement`, `asset_correlation` | Basel IRB risk weights: corporate (with SME adjustment and maturity), mortgage, QRRE, other retail | Basel II ¶272–330, Annex 5 |
|
|
43
|
+
|
|
44
|
+
Conventions: grades run from lowest to highest risk; by default a higher score means higher risk
|
|
45
|
+
(`higher_is_riskier=False` for scorecards where a high score is safe); `1` in a default flag means
|
|
46
|
+
default; a PD of 1 maps to the master scale's defaulted grade, never to a performing grade.
|
|
47
|
+
|
|
48
|
+
## Agent skill: annual PD validation
|
|
49
|
+
|
|
50
|
+
[`skills/annual-pd-validation`](skills/annual-pd-validation) is an Agent Skill that lets an AI agent prepare the
|
|
51
|
+
evidence for an annual PD validation: it runs every test through eqlx-credit, reads the results, and drafts the
|
|
52
|
+
report in the user's language. The agent never computes a number itself and never gives the validation opinion; the
|
|
53
|
+
conclusion and signature stay with the validator. On the bundled synthetic portfolio it finds the planted problems:
|
|
54
|
+
a significant AUC decline since initial validation and one grade with far more defaults than its PD implies.
|
|
55
|
+
|
|
56
|
+
## An annual validation pass
|
|
57
|
+
|
|
58
|
+
[`examples/validation_report.py`](examples/validation_report.py), on a synthetic grade table:
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
import numpy as np
|
|
62
|
+
import eqlx_credit as ec
|
|
63
|
+
|
|
64
|
+
n = np.array([820, 1450, 1910, 1320, 640, 210]) # obligors per grade at the start of the year
|
|
65
|
+
d = np.array([1, 4, 11, 19, 21, 17]) # defaults during the year
|
|
66
|
+
pd = np.array([0.0012, 0.0035, 0.0070, 0.0140, 0.0300, 0.0700])
|
|
67
|
+
|
|
68
|
+
cur = ec.auc_ci_from_counts(n, d) # AUC with DeLong confidence interval
|
|
69
|
+
ec.auc_decline_test(0.80, cur) # vs the AUC at initial validation
|
|
70
|
+
ec.jeffreys_test(n, d, pd).rows() # one dict per grade, ready for a report table
|
|
71
|
+
ec.traffic_light(n, d, pd, rho=0.12).colours # allowing for correlated defaults
|
|
72
|
+
ec.risk_weight(pd, 0.45) # Basel IRB, corporate, LGD 45%, M 2.5
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
```text
|
|
76
|
+
AUC 0.785 (95% CI 0.734-0.836), Gini 0.570
|
|
77
|
+
Decline vs initial 0.800: S = 0.57, p = 0.285
|
|
78
|
+
grade 1: 1 defaults vs 1.0 expected, Jeffreys p = 0.421, traffic light green
|
|
79
|
+
grade 2: 4 defaults vs 5.1 expected, Jeffreys p = 0.662, traffic light green
|
|
80
|
+
grade 3: 11 defaults vs 13.4 expected, Jeffreys p = 0.734, traffic light green
|
|
81
|
+
grade 4: 19 defaults vs 18.5 expected, Jeffreys p = 0.437, traffic light green
|
|
82
|
+
grade 5: 21 defaults vs 19.2 expected, Jeffreys p = 0.327, traffic light green
|
|
83
|
+
grade 6: 17 defaults vs 14.7 expected, Jeffreys p = 0.259, traffic light green
|
|
84
|
+
Normal test over 5 years: z = 0.89
|
|
85
|
+
Risk weights: 33.0% 58.8% 80.5% 103.4% 128.4% 168.9%
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## A low-default portfolio
|
|
89
|
+
|
|
90
|
+
[`examples/quickstart.py`](examples/quickstart.py):
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
n_obligors = np.array([120, 340, 510, 430, 260, 90])
|
|
94
|
+
n_defaults = np.array([0, 0, 1, 2, 3, 2])
|
|
95
|
+
|
|
96
|
+
ec.pluto_tasche(n_obligors, n_defaults, confidence=0.9, rho=0.12)
|
|
97
|
+
ec.fit_ct_ar(n_obligors, central_tendency=0.015, accuracy_ratio=0.65).pd
|
|
98
|
+
ec.van_der_burgt(n_obligors, central_tendency=0.015, accuracy_ratio=0.65).pd
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
```text
|
|
102
|
+
Pluto-Tasche (90%, rho=0.12): [ 2.511 2.652 3.172 4.263 6.336 10.761] %
|
|
103
|
+
CT/AR curve: [ 0.037 0.135 0.421 1.205 3.383 10.692] %
|
|
104
|
+
van der Burgt: [0.044 0.093 0.366 1.525 4.246 7.134] %
|
|
105
|
+
Master scale grades: [ 2 5 8 11 14 17]
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## How it is tested
|
|
109
|
+
|
|
110
|
+
- **Basel IRB:** all eight columns of Basel II Annex 5 ("Illustrative IRB Risk Weights") reproduced to
|
|
111
|
+
the published two decimals.
|
|
112
|
+
- **Pluto–Tasche:** the paper's worked example (0.29%, 0.33%, 0.76%).
|
|
113
|
+
- **DeLong:** against an explicit obligor-by-obligor placement calculation, and by simulation: the
|
|
114
|
+
standard error matches the spread of simulated AUCs and the 95% interval covers the true AUC about
|
|
115
|
+
95% of the time.
|
|
116
|
+
- **Correlated binomial:** against a Monte Carlo simulation of the one-factor model.
|
|
117
|
+
- **Spiegelhalter:** a hand calculation, and standard normal under correct PDs by simulation.
|
|
118
|
+
- **Cohorts:** hand-built panels, including the horizon boundary and 29 February.
|
|
119
|
+
|
|
120
|
+
## Notes on the methods
|
|
121
|
+
|
|
122
|
+
- Use the obligor-average PD at the start of the period per grade as the grade PD in back-tests.
|
|
123
|
+
- `binomial_test` with `rho=0` assumes independent defaults and rejects too often when defaults are
|
|
124
|
+
correlated; pass an asset correlation, or read it next to `traffic_light(..., rho=)`.
|
|
125
|
+
- Thresholds (test levels, traffic-light quantiles, PSI readings) are policy choices; set your own.
|
|
126
|
+
- `hosmer_lemeshow` uses `K` degrees of freedom for `K` grades (out-of-sample use).
|
|
127
|
+
- `pluto_tasche` is the single-period version; in practice the bounds are often rescaled to the central
|
|
128
|
+
tendency afterwards.
|
|
129
|
+
- `fit_ct_ar` uses Tasche's robust-logit grade positions by default but matches the accuracy ratio
|
|
130
|
+
exactly on the grade distribution rather than through his moment approximation;
|
|
131
|
+
`placement="even"` gives the v0.1 behaviour.
|
|
132
|
+
- `van_der_burgt` returns each grade's PD as the average slope of the CAP curve over that grade, so the
|
|
133
|
+
weighted mean equals the central tendency exactly; grading makes the grade-level AR a little lower.
|
|
134
|
+
- `risk_weight` defaults to no 1.06 scaling factor (Basel III final); pass `scaling=1.06` for Basel II /
|
|
135
|
+
CRR. PD floors differ by framework and are the caller's choice.
|
|
136
|
+
|
|
137
|
+
## References
|
|
138
|
+
|
|
139
|
+
- Basel Committee on Banking Supervision (2006). International Convergence of Capital Measurement and
|
|
140
|
+
Capital Standards, ¶272–330 and Annex 5.
|
|
141
|
+
- Basel Committee on Banking Supervision (2005). An Explanatory Note on the Basel II IRB Risk Weight
|
|
142
|
+
Functions.
|
|
143
|
+
- Basel Committee on Banking Supervision (2005). Studies on the validation of internal rating systems.
|
|
144
|
+
Working Paper No. 14.
|
|
145
|
+
- European Central Bank (2019). Instructions for reporting the validation results of internal models:
|
|
146
|
+
IRB Pillar I models for credit risk.
|
|
147
|
+
- European Banking Authority (2017). Guidelines on PD estimation, LGD estimation and the treatment of
|
|
148
|
+
defaulted exposures (EBA/GL/2017/16).
|
|
149
|
+
- DeLong, E. R., DeLong, D. M. and Clarke-Pearson, D. L. (1988). Comparing the areas under two or more
|
|
150
|
+
correlated receiver operating characteristic curves. *Biometrics* 44(3).
|
|
151
|
+
- Spiegelhalter, D. J. (1986). Probabilistic prediction in patient management and clinical trials.
|
|
152
|
+
*Statistics in Medicine* 5(5).
|
|
153
|
+
- Tasche, D. (2003). A traffic lights approach to PD validation. arXiv:cond-mat/0305038.
|
|
154
|
+
- Tasche, D. (2013). The art of probability-of-default curve calibration. *Journal of Credit Risk*
|
|
155
|
+
9(4). arXiv:1212.3716.
|
|
156
|
+
- Pluto, K. and Tasche, D. (2005). Thinking positively. *Risk*, August 2005. Longer version:
|
|
157
|
+
arXiv:cond-mat/0411699.
|
|
158
|
+
- van der Burgt, M. (2008). Calibrating low-default portfolios, using the cumulative accuracy profile.
|
|
159
|
+
*Journal of Risk Model Validation* 1(4).
|
|
160
|
+
- Vasicek, O. (2002). The distribution of loan portfolio value. *Risk*, December 2002.
|
|
161
|
+
- Siddiqi, N. (2006). *Credit Risk Scorecards*. Wiley.
|
|
162
|
+
|
|
163
|
+
## Development
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
uv sync
|
|
167
|
+
uv run pytest
|
|
168
|
+
uv run ruff check . && uv run ruff format --check . && uv run mypy src
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## Contributing
|
|
172
|
+
|
|
173
|
+
Issues and pull requests are welcome. See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
174
|
+
|
|
175
|
+
## License
|
|
176
|
+
|
|
177
|
+
Apache-2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "eqlx-credit"
|
|
3
|
+
version = "0.2.0"
|
|
4
|
+
description = "Open tools for credit-risk model work: PD validation tests, calibration, master scales and low-default portfolio methods."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
|
+
license = "Apache-2.0"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
keywords = [
|
|
10
|
+
"credit risk",
|
|
11
|
+
"probability of default",
|
|
12
|
+
"IRB",
|
|
13
|
+
"Basel",
|
|
14
|
+
"model validation",
|
|
15
|
+
"low default portfolio",
|
|
16
|
+
]
|
|
17
|
+
classifiers = [
|
|
18
|
+
"Development Status :: 3 - Alpha",
|
|
19
|
+
"Intended Audience :: Financial and Insurance Industry",
|
|
20
|
+
"Intended Audience :: Science/Research",
|
|
21
|
+
"Programming Language :: Python :: 3",
|
|
22
|
+
"Topic :: Office/Business :: Financial",
|
|
23
|
+
"Topic :: Scientific/Engineering :: Mathematics",
|
|
24
|
+
]
|
|
25
|
+
dependencies = [
|
|
26
|
+
"numpy>=1.26",
|
|
27
|
+
"scipy>=1.11",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[[project.authors]]
|
|
31
|
+
name = "Can Demir"
|
|
32
|
+
email = "can.demir@eqlx.ai"
|
|
33
|
+
|
|
34
|
+
[project.urls]
|
|
35
|
+
Homepage = "https://eqlx.org"
|
|
36
|
+
|
|
37
|
+
[build-system]
|
|
38
|
+
requires = ["uv_build>=0.12.16,<0.13.0"]
|
|
39
|
+
build-backend = "uv_build"
|
|
40
|
+
|
|
41
|
+
[dependency-groups]
|
|
42
|
+
dev = [
|
|
43
|
+
"mypy>=2.4.1",
|
|
44
|
+
"pytest>=9.2.0",
|
|
45
|
+
"ruff>=0.17.4",
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
[tool.ruff]
|
|
49
|
+
line-length = 110
|
|
50
|
+
target-version = "py310"
|
|
51
|
+
|
|
52
|
+
[tool.ruff.lint]
|
|
53
|
+
select = [
|
|
54
|
+
"E",
|
|
55
|
+
"F",
|
|
56
|
+
"W",
|
|
57
|
+
"I",
|
|
58
|
+
"B",
|
|
59
|
+
"UP",
|
|
60
|
+
"N",
|
|
61
|
+
"SIM",
|
|
62
|
+
"RUF",
|
|
63
|
+
"NPY",
|
|
64
|
+
]
|
|
65
|
+
|
|
66
|
+
[tool.mypy]
|
|
67
|
+
strict = true
|
|
68
|
+
warn_unused_ignores = true
|
|
69
|
+
|
|
70
|
+
[[tool.mypy.overrides]]
|
|
71
|
+
module = ["scipy.*"]
|
|
72
|
+
ignore_missing_imports = true
|
|
73
|
+
|
|
74
|
+
[[tool.mypy.overrides]]
|
|
75
|
+
module = ["tests.*"]
|
|
76
|
+
disallow_untyped_defs = false
|