eqlx-ifrs9 0.1.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.
@@ -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,236 @@
1
+ Metadata-Version: 2.4
2
+ Name: eqlx-ifrs9
3
+ Version: 0.1.0
4
+ Summary: Deterministic IFRS 9 expected credit loss: PD term structures, staging, 12-month and lifetime ECL, scenario weighting, provision matrix. Checked against published examples. Read-only MCP server for AI agents.
5
+ Keywords: ifrs9,ifrs 9,expected credit loss,ecl,staging,sicr,credit risk,provisioning,tfrs 9,mcp
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 :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Topic :: Office/Business :: Financial
15
+ Requires-Dist: numpy>=1.26
16
+ Requires-Dist: scipy>=1.11
17
+ Requires-Dist: mcp>=2.3.0 ; extra == 'mcp'
18
+ Requires-Python: >=3.10
19
+ Project-URL: Homepage, https://eqlx.org
20
+ Project-URL: Source, https://github.com/eqlx-ai/eqlx-ifrs9
21
+ Provides-Extra: mcp
22
+ Description-Content-Type: text/markdown
23
+
24
+ # eqlx-ifrs9
25
+
26
+ Deterministic IFRS 9 expected credit loss: PD term structures, stage allocation, 12-month and
27
+ lifetime ECL, scenario weighting, the provision matrix, and a rule profile for Turkey (BDDK).
28
+ A Python library, a command line tool and a read-only MCP server for AI agents.
29
+
30
+ It computes. It does not estimate PD or LGD models and it does not forecast the economy: PDs, LGDs,
31
+ scenario paths and thresholds are inputs. Same input, same output, and every figure can be traced
32
+ back to the loan, the rule and the setting that produced it.
33
+
34
+ - **Explicit choices.** IFRS 9 leaves a lot to the entity: what "significant" means, how many
35
+ scenarios, when inside a period default happens. Each of those is a named setting, never a hidden
36
+ default, and settings that supervisors have publicly criticised produce a warning.
37
+ - **Checked against published numbers.** The IASB's own illustrative examples, the transition
38
+ resource group's scenario example and a published rating matrix are reproduced in the test-suite;
39
+ everything else is checked against closed forms, direct enumeration and simulation.
40
+ - **Built for agents.** The agent decides what to look at; the tool returns the number and the
41
+ reason. The MCP server only reads files in one folder and writes nothing.
42
+
43
+ ## Who it is for
44
+
45
+ Credit risk and finance teams who want an independent recalculation of their allowance, auditors and
46
+ model validators who need a transparent benchmark, teams in smaller lenders who do not run a vendor
47
+ engine, and people building AI agents for credit work.
48
+
49
+ ## Install
50
+
51
+ ```bash
52
+ pip install eqlx-ifrs9 # library and command line
53
+ pip install "eqlx-ifrs9[mcp]" # with the MCP server
54
+ ```
55
+
56
+ Python 3.10 or later. Dependencies: NumPy and SciPy.
57
+
58
+ ## A first look
59
+
60
+ ```bash
61
+ ifrs9 sample demo # a made-up portfolio of 2,011 loans, settings, and known answers
62
+ ifrs9 run demo/loans.csv --config demo/settings.json
63
+ ```
64
+
65
+ ```text
66
+ loans 2,011 exposure 2,828,567,386.34 ECL 102,343,016.39 coverage 3.62%
67
+
68
+ stage loans exposure share ECL coverage
69
+ 1 1,607 2,249,809,211.77 79.5% 12,456,032.90 0.55%
70
+ 2 348 441,415,469.37 15.6% 12,878,196.38 2.92%
71
+ 3 56 137,342,705.20 4.9% 77,008,787.11 56.07%
72
+
73
+ stage 2 by primary reason
74
+ pd_relative 235 309,819,436.40 10,489,482.54
75
+ days_past_due_backstop 56 67,610,588.76 1,669,616.00
76
+ forborne 29 37,901,342.97 530,776.72
77
+ watchlist 27 25,984,101.23 186,525.26
78
+ probation 1 100,000.00 1,795.86
79
+
80
+ scenarios (ECL if one scenario alone had full weight)
81
+ base weight 60% same stages 94,135,368.37 restaged 92,655,649.27 (53 loans change stage)
82
+ downside weight 25% same stages 132,299,414.92 restaged 142,398,307.48 (336 loans change stage)
83
+ upside weight 15% same stages 85,246,277.60 restaged 83,600,059.51 (149 loans change stage)
84
+ weighted / base: 1.105
85
+
86
+ checks
87
+ stage 1 loans whose PD has tripled since origination: 0
88
+ stage 2 only because of days past due: 56 (15.3% of stage 2 exposure)
89
+ stage 1 kept by the low credit risk exemption: 1
90
+ loans without origination PD: 0
91
+ ```
92
+
93
+ Then ask about one loan, or about a different policy:
94
+
95
+ ```bash
96
+ ifrs9 loan demo/loans.csv CASE-GROUP-X-CURRENT --config demo/settings.json
97
+ ifrs9 compare demo/loans.csv --config demo/settings.json --set staging.relative_threshold=3
98
+ ifrs9 list demo/loans.csv --config demo/settings.json --stage 2 --reason days_past_due_backstop
99
+ ```
100
+
101
+ The first command explains a loan that is not past due itself and still sits in stage 3:
102
+
103
+ ```json
104
+ {
105
+ "loan_id": "CASE-GROUP-X-CURRENT",
106
+ "stage": 3,
107
+ "reasons": ["profile_default"],
108
+ "regulatory_group": 4,
109
+ "regulatory_reasons": [
110
+ "another loan of the borrower is non-performing: same group 4 (Art. 5(5))"
111
+ ],
112
+ "exposure": 5000000.0,
113
+ "ecl": 2750000.0,
114
+ "measurement": "exposure x loss rate in default"
115
+ }
116
+ ```
117
+
118
+ ## As a library
119
+
120
+ ```python
121
+ from eqlx_ifrs9 import PDCurve, cycle, expected_credit_loss, schedule
122
+ from eqlx_ifrs9.staging import StagingPolicy, assess
123
+
124
+ # A 36-month instalment loan, 12-month PD 3%, LGD 60%, effective interest rate 31%.
125
+ loan = schedule.annuity(100_000, 0.30, 36)
126
+ curve = PDCurve.flat(0.03, 36)
127
+ res = expected_credit_loss(curve, loan.ead(), lgd=0.60, effective_interest_rate=0.31)
128
+ res.twelve_month, res.lifetime # 1406.99, 2351.36
129
+
130
+ # The same loan in a downturn: long-run PD shifted year by year (z < 0 is a bad year).
131
+ down = cycle.pit_curve(curve, rho=0.06, z_by_year=[-1.6, -1.0, -0.4])
132
+ expected_credit_loss(down, loan.ead(), 0.60, 0.31).lifetime # 4226.37
133
+
134
+ # Has credit risk increased significantly? Compare with the PD that was expected at origination
135
+ # for the SAME remaining window: two years into a five-year loan, that is years 3 to 5.
136
+ at_origination = PDCurve.from_cumulative([0.01, 0.025, 0.045, 0.07, 0.10], periods_per_year=1)
137
+ expected_then = at_origination.forward(2).pd_over() # 0.0769, not the five-year 0.10
138
+ r = assess(StagingPolicy(relative_threshold=2.0), pd_now=[0.16], pd_origination=[expected_then])
139
+ r.stage[0], r.reason_names(0), r.pd_ratio[0] # 2, ['pd_relative'], 2.08
140
+ ```
141
+
142
+ Modules: `curves` (PD term structures), `transitions` (rating matrices, generators, cycle shift),
143
+ `cycle` (one-factor point-in-time adjustment), `schedule` (repayment and exposure), `lgd`
144
+ (collateral, workout, credit-impaired assets), `ecl`, `staging`, `scenarios`, `simplified`
145
+ (provision matrix), `profiles.tr_bddk`, and for whole portfolios `data`, `config`, `engine`,
146
+ `report`.
147
+
148
+ ## For AI agents (MCP)
149
+
150
+ ```bash
151
+ ifrs9 mcp --root /path/to/folder
152
+ ```
153
+
154
+ Claude Code, Claude Desktop or any other MCP client can then use these tools. All are read-only and
155
+ confined to that folder; nothing is written and nothing leaves the machine.
156
+
157
+ | Tool | What it returns |
158
+ |---|---|
159
+ | `list_files` | loan files (.csv) and settings files (.json) in the folder |
160
+ | `describe_loans` | what a loan file contains, and what is missing, before any calculation |
161
+ | `run_portfolio` | stage and ECL for every loan: tables by stage, segment, reason and scenario, checks, warnings |
162
+ | `list_loans` | loans matching a filter, with every rule that fired |
163
+ | `explain_loan` | one loan step by step: staging test, PD and ECL per scenario and year |
164
+ | `compare_settings` | what a different threshold, weight or scenario would change |
165
+ | `calculate_ecl` | 12-month and lifetime ECL of one instrument from plain numbers |
166
+ | `pd_term_structure` | cumulative PD by grade from a transition matrix, with generator diagnostics |
167
+ | `provision_matrix` | simplified approach for trade receivables |
168
+ | `turkey_reclassification_check` | BDDK conditions for moving a loan back up, with article numbers |
169
+
170
+ ## Input
171
+
172
+ **Loan file** (CSV, one row per instrument). Required: `loan_id`, `balance`, `eir`,
173
+ `remaining_months`, `lgd`, and `pd_12m` or `grade`. Optional columns cover the borrower, segment,
174
+ repayment type, undrawn limits, origination risk, days past due and status flags; the full list is
175
+ in [`eqlx_ifrs9/data.py`](src/eqlx_ifrs9/data.py). Rates and PDs are fractions (`0.05` for 5%).
176
+
177
+ **Settings** (JSON). Staging thresholds, scenarios with weights and a z path per forecast year,
178
+ reversion after the forecast horizon, segment parameters (asset correlation, prepayment, a
179
+ transition matrix), calculation conventions and an optional profile. `ifrs9 sample` writes a
180
+ complete example; [`eqlx_ifrs9/config.py`](src/eqlx_ifrs9/config.py) documents every key.
181
+ Unknown keys and out-of-range values are rejected.
182
+
183
+ ## How it is verified
184
+
185
+ | What | Checked against |
186
+ |---|---|
187
+ | 12-month ECL, explicit PD | IFRS 9 Illustrative Example 8: CU1,250 |
188
+ | Loss rate approach | Illustrative Example 9: CU750 and CU675 |
189
+ | Exposure of revolving facilities | Illustrative Example 10: CU25,000 and CU45,000 |
190
+ | Provision matrix | Illustrative Example 12: CU580,000; IFRS 7 IG20D: CU114 and CU145 thousand |
191
+ | Probability weighting | Transition resource group, December 2015: CU92 against CU70 for one scenario |
192
+ | Generators of rating matrices | Israel, Rosenthal and Wei (2001): error norms 0.002736 and 0.002686 |
193
+ | Lifetime ECL with discounting | closed form for a bullet loan; continuous-time limit; direct enumeration |
194
+ | The same, amortising loan | simulation of two million default times |
195
+ | One-factor shift | the average over the cycle returns the long-run PD and matrix (numerical integration) |
196
+ | Portfolio run | every loan recomputed with the scalar functions; independence of row order and chunking |
197
+ | Turkey profile | article by article against the regulation text; contagion against direct enumeration |
198
+
199
+ The illustrative examples do not cover multi-period discounting, several scenarios or a numeric
200
+ staging threshold. Those parts rest on the closed forms, the enumeration and the simulation.
201
+ Tests also pin down frequent mistakes: summing conditional PDs without survival weighting, using a
202
+ 12-month PD on a six-month loan, dividing an annual PD by twelve, giving a bullet loan no exposure
203
+ in its last period, and comparing today's remaining-life PD with the full-life PD at origination.
204
+
205
+ ## Limits
206
+
207
+ This is a calculation tool, not an accounting opinion and not a validated model. It covers the
208
+ impairment arithmetic of IFRS 9 Section 5.5 for loans, undrawn commitments and trade receivables.
209
+ It does not cover classification and measurement, hedge accounting, purchased or originated
210
+ credit-impaired assets, or the allowance movement table. See [LIMITS.md](LIMITS.md) before relying
211
+ on a number.
212
+
213
+ ## References
214
+
215
+ - IFRS 9 *Financial Instruments*, Section 5.5 and Application Guidance B5.5; Illustrative Examples
216
+ (IFRS Foundation). TFRS 9 is the Turkish equivalent with the same paragraph numbers (KGK).
217
+ - IFRS 7 *Financial Instruments: Disclosures*, paragraphs 35A-35N and Implementation Guidance IG20D.
218
+ - IFRS Transition Resource Group for Impairment of Financial Instruments, meeting summaries 2015.
219
+ - Basel Committee on Banking Supervision (2015), *Guidance on credit risk and accounting for expected
220
+ credit losses*.
221
+ - European Banking Authority (2021, 2023), *IFRS 9 implementation by EU institutions*, monitoring
222
+ reports; ECB Banking Supervision, letter of 4 December 2020 on credit risk identification.
223
+ - BDDK, *Kredilerin Sınıflandırılması ve Bunlar İçin Ayrılacak Karşılıklara İlişkin Usul ve Esaslar
224
+ Hakkında Yönetmelik*, Official Gazette 22 June 2016, no. 29750, as amended.
225
+ - Vasicek, O. (2002), "The distribution of loan portfolio value", *Risk*.
226
+ - Belkin, B., Suchower, S. and Forest, L. (1998), "A one-parameter representation of credit risk and
227
+ transition matrices", *CreditMetrics Monitor*.
228
+ - Israel, R., Rosenthal, J. and Wei, J. (2001), "Finding generators for Markov chains via empirical
229
+ transition matrices, with applications to credit ratings", *Mathematical Finance* 11(2).
230
+ - Jarrow, R., Lando, D. and Turnbull, S. (1997), "A Markov model for the term structure of credit
231
+ risk spreads", *Review of Financial Studies* 10(2).
232
+
233
+ ## License
234
+
235
+ Apache-2.0. Part of [eqlx.org](https://eqlx.org): deterministic tools for AI agents in credit and
236
+ finance. Questions: research@eqlx.ai.
@@ -0,0 +1,213 @@
1
+ # eqlx-ifrs9
2
+
3
+ Deterministic IFRS 9 expected credit loss: PD term structures, stage allocation, 12-month and
4
+ lifetime ECL, scenario weighting, the provision matrix, and a rule profile for Turkey (BDDK).
5
+ A Python library, a command line tool and a read-only MCP server for AI agents.
6
+
7
+ It computes. It does not estimate PD or LGD models and it does not forecast the economy: PDs, LGDs,
8
+ scenario paths and thresholds are inputs. Same input, same output, and every figure can be traced
9
+ back to the loan, the rule and the setting that produced it.
10
+
11
+ - **Explicit choices.** IFRS 9 leaves a lot to the entity: what "significant" means, how many
12
+ scenarios, when inside a period default happens. Each of those is a named setting, never a hidden
13
+ default, and settings that supervisors have publicly criticised produce a warning.
14
+ - **Checked against published numbers.** The IASB's own illustrative examples, the transition
15
+ resource group's scenario example and a published rating matrix are reproduced in the test-suite;
16
+ everything else is checked against closed forms, direct enumeration and simulation.
17
+ - **Built for agents.** The agent decides what to look at; the tool returns the number and the
18
+ reason. The MCP server only reads files in one folder and writes nothing.
19
+
20
+ ## Who it is for
21
+
22
+ Credit risk and finance teams who want an independent recalculation of their allowance, auditors and
23
+ model validators who need a transparent benchmark, teams in smaller lenders who do not run a vendor
24
+ engine, and people building AI agents for credit work.
25
+
26
+ ## Install
27
+
28
+ ```bash
29
+ pip install eqlx-ifrs9 # library and command line
30
+ pip install "eqlx-ifrs9[mcp]" # with the MCP server
31
+ ```
32
+
33
+ Python 3.10 or later. Dependencies: NumPy and SciPy.
34
+
35
+ ## A first look
36
+
37
+ ```bash
38
+ ifrs9 sample demo # a made-up portfolio of 2,011 loans, settings, and known answers
39
+ ifrs9 run demo/loans.csv --config demo/settings.json
40
+ ```
41
+
42
+ ```text
43
+ loans 2,011 exposure 2,828,567,386.34 ECL 102,343,016.39 coverage 3.62%
44
+
45
+ stage loans exposure share ECL coverage
46
+ 1 1,607 2,249,809,211.77 79.5% 12,456,032.90 0.55%
47
+ 2 348 441,415,469.37 15.6% 12,878,196.38 2.92%
48
+ 3 56 137,342,705.20 4.9% 77,008,787.11 56.07%
49
+
50
+ stage 2 by primary reason
51
+ pd_relative 235 309,819,436.40 10,489,482.54
52
+ days_past_due_backstop 56 67,610,588.76 1,669,616.00
53
+ forborne 29 37,901,342.97 530,776.72
54
+ watchlist 27 25,984,101.23 186,525.26
55
+ probation 1 100,000.00 1,795.86
56
+
57
+ scenarios (ECL if one scenario alone had full weight)
58
+ base weight 60% same stages 94,135,368.37 restaged 92,655,649.27 (53 loans change stage)
59
+ downside weight 25% same stages 132,299,414.92 restaged 142,398,307.48 (336 loans change stage)
60
+ upside weight 15% same stages 85,246,277.60 restaged 83,600,059.51 (149 loans change stage)
61
+ weighted / base: 1.105
62
+
63
+ checks
64
+ stage 1 loans whose PD has tripled since origination: 0
65
+ stage 2 only because of days past due: 56 (15.3% of stage 2 exposure)
66
+ stage 1 kept by the low credit risk exemption: 1
67
+ loans without origination PD: 0
68
+ ```
69
+
70
+ Then ask about one loan, or about a different policy:
71
+
72
+ ```bash
73
+ ifrs9 loan demo/loans.csv CASE-GROUP-X-CURRENT --config demo/settings.json
74
+ ifrs9 compare demo/loans.csv --config demo/settings.json --set staging.relative_threshold=3
75
+ ifrs9 list demo/loans.csv --config demo/settings.json --stage 2 --reason days_past_due_backstop
76
+ ```
77
+
78
+ The first command explains a loan that is not past due itself and still sits in stage 3:
79
+
80
+ ```json
81
+ {
82
+ "loan_id": "CASE-GROUP-X-CURRENT",
83
+ "stage": 3,
84
+ "reasons": ["profile_default"],
85
+ "regulatory_group": 4,
86
+ "regulatory_reasons": [
87
+ "another loan of the borrower is non-performing: same group 4 (Art. 5(5))"
88
+ ],
89
+ "exposure": 5000000.0,
90
+ "ecl": 2750000.0,
91
+ "measurement": "exposure x loss rate in default"
92
+ }
93
+ ```
94
+
95
+ ## As a library
96
+
97
+ ```python
98
+ from eqlx_ifrs9 import PDCurve, cycle, expected_credit_loss, schedule
99
+ from eqlx_ifrs9.staging import StagingPolicy, assess
100
+
101
+ # A 36-month instalment loan, 12-month PD 3%, LGD 60%, effective interest rate 31%.
102
+ loan = schedule.annuity(100_000, 0.30, 36)
103
+ curve = PDCurve.flat(0.03, 36)
104
+ res = expected_credit_loss(curve, loan.ead(), lgd=0.60, effective_interest_rate=0.31)
105
+ res.twelve_month, res.lifetime # 1406.99, 2351.36
106
+
107
+ # The same loan in a downturn: long-run PD shifted year by year (z < 0 is a bad year).
108
+ down = cycle.pit_curve(curve, rho=0.06, z_by_year=[-1.6, -1.0, -0.4])
109
+ expected_credit_loss(down, loan.ead(), 0.60, 0.31).lifetime # 4226.37
110
+
111
+ # Has credit risk increased significantly? Compare with the PD that was expected at origination
112
+ # for the SAME remaining window: two years into a five-year loan, that is years 3 to 5.
113
+ at_origination = PDCurve.from_cumulative([0.01, 0.025, 0.045, 0.07, 0.10], periods_per_year=1)
114
+ expected_then = at_origination.forward(2).pd_over() # 0.0769, not the five-year 0.10
115
+ r = assess(StagingPolicy(relative_threshold=2.0), pd_now=[0.16], pd_origination=[expected_then])
116
+ r.stage[0], r.reason_names(0), r.pd_ratio[0] # 2, ['pd_relative'], 2.08
117
+ ```
118
+
119
+ Modules: `curves` (PD term structures), `transitions` (rating matrices, generators, cycle shift),
120
+ `cycle` (one-factor point-in-time adjustment), `schedule` (repayment and exposure), `lgd`
121
+ (collateral, workout, credit-impaired assets), `ecl`, `staging`, `scenarios`, `simplified`
122
+ (provision matrix), `profiles.tr_bddk`, and for whole portfolios `data`, `config`, `engine`,
123
+ `report`.
124
+
125
+ ## For AI agents (MCP)
126
+
127
+ ```bash
128
+ ifrs9 mcp --root /path/to/folder
129
+ ```
130
+
131
+ Claude Code, Claude Desktop or any other MCP client can then use these tools. All are read-only and
132
+ confined to that folder; nothing is written and nothing leaves the machine.
133
+
134
+ | Tool | What it returns |
135
+ |---|---|
136
+ | `list_files` | loan files (.csv) and settings files (.json) in the folder |
137
+ | `describe_loans` | what a loan file contains, and what is missing, before any calculation |
138
+ | `run_portfolio` | stage and ECL for every loan: tables by stage, segment, reason and scenario, checks, warnings |
139
+ | `list_loans` | loans matching a filter, with every rule that fired |
140
+ | `explain_loan` | one loan step by step: staging test, PD and ECL per scenario and year |
141
+ | `compare_settings` | what a different threshold, weight or scenario would change |
142
+ | `calculate_ecl` | 12-month and lifetime ECL of one instrument from plain numbers |
143
+ | `pd_term_structure` | cumulative PD by grade from a transition matrix, with generator diagnostics |
144
+ | `provision_matrix` | simplified approach for trade receivables |
145
+ | `turkey_reclassification_check` | BDDK conditions for moving a loan back up, with article numbers |
146
+
147
+ ## Input
148
+
149
+ **Loan file** (CSV, one row per instrument). Required: `loan_id`, `balance`, `eir`,
150
+ `remaining_months`, `lgd`, and `pd_12m` or `grade`. Optional columns cover the borrower, segment,
151
+ repayment type, undrawn limits, origination risk, days past due and status flags; the full list is
152
+ in [`eqlx_ifrs9/data.py`](src/eqlx_ifrs9/data.py). Rates and PDs are fractions (`0.05` for 5%).
153
+
154
+ **Settings** (JSON). Staging thresholds, scenarios with weights and a z path per forecast year,
155
+ reversion after the forecast horizon, segment parameters (asset correlation, prepayment, a
156
+ transition matrix), calculation conventions and an optional profile. `ifrs9 sample` writes a
157
+ complete example; [`eqlx_ifrs9/config.py`](src/eqlx_ifrs9/config.py) documents every key.
158
+ Unknown keys and out-of-range values are rejected.
159
+
160
+ ## How it is verified
161
+
162
+ | What | Checked against |
163
+ |---|---|
164
+ | 12-month ECL, explicit PD | IFRS 9 Illustrative Example 8: CU1,250 |
165
+ | Loss rate approach | Illustrative Example 9: CU750 and CU675 |
166
+ | Exposure of revolving facilities | Illustrative Example 10: CU25,000 and CU45,000 |
167
+ | Provision matrix | Illustrative Example 12: CU580,000; IFRS 7 IG20D: CU114 and CU145 thousand |
168
+ | Probability weighting | Transition resource group, December 2015: CU92 against CU70 for one scenario |
169
+ | Generators of rating matrices | Israel, Rosenthal and Wei (2001): error norms 0.002736 and 0.002686 |
170
+ | Lifetime ECL with discounting | closed form for a bullet loan; continuous-time limit; direct enumeration |
171
+ | The same, amortising loan | simulation of two million default times |
172
+ | One-factor shift | the average over the cycle returns the long-run PD and matrix (numerical integration) |
173
+ | Portfolio run | every loan recomputed with the scalar functions; independence of row order and chunking |
174
+ | Turkey profile | article by article against the regulation text; contagion against direct enumeration |
175
+
176
+ The illustrative examples do not cover multi-period discounting, several scenarios or a numeric
177
+ staging threshold. Those parts rest on the closed forms, the enumeration and the simulation.
178
+ Tests also pin down frequent mistakes: summing conditional PDs without survival weighting, using a
179
+ 12-month PD on a six-month loan, dividing an annual PD by twelve, giving a bullet loan no exposure
180
+ in its last period, and comparing today's remaining-life PD with the full-life PD at origination.
181
+
182
+ ## Limits
183
+
184
+ This is a calculation tool, not an accounting opinion and not a validated model. It covers the
185
+ impairment arithmetic of IFRS 9 Section 5.5 for loans, undrawn commitments and trade receivables.
186
+ It does not cover classification and measurement, hedge accounting, purchased or originated
187
+ credit-impaired assets, or the allowance movement table. See [LIMITS.md](LIMITS.md) before relying
188
+ on a number.
189
+
190
+ ## References
191
+
192
+ - IFRS 9 *Financial Instruments*, Section 5.5 and Application Guidance B5.5; Illustrative Examples
193
+ (IFRS Foundation). TFRS 9 is the Turkish equivalent with the same paragraph numbers (KGK).
194
+ - IFRS 7 *Financial Instruments: Disclosures*, paragraphs 35A-35N and Implementation Guidance IG20D.
195
+ - IFRS Transition Resource Group for Impairment of Financial Instruments, meeting summaries 2015.
196
+ - Basel Committee on Banking Supervision (2015), *Guidance on credit risk and accounting for expected
197
+ credit losses*.
198
+ - European Banking Authority (2021, 2023), *IFRS 9 implementation by EU institutions*, monitoring
199
+ reports; ECB Banking Supervision, letter of 4 December 2020 on credit risk identification.
200
+ - BDDK, *Kredilerin Sınıflandırılması ve Bunlar İçin Ayrılacak Karşılıklara İlişkin Usul ve Esaslar
201
+ Hakkında Yönetmelik*, Official Gazette 22 June 2016, no. 29750, as amended.
202
+ - Vasicek, O. (2002), "The distribution of loan portfolio value", *Risk*.
203
+ - Belkin, B., Suchower, S. and Forest, L. (1998), "A one-parameter representation of credit risk and
204
+ transition matrices", *CreditMetrics Monitor*.
205
+ - Israel, R., Rosenthal, J. and Wei, J. (2001), "Finding generators for Markov chains via empirical
206
+ transition matrices, with applications to credit ratings", *Mathematical Finance* 11(2).
207
+ - Jarrow, R., Lando, D. and Turnbull, S. (1997), "A Markov model for the term structure of credit
208
+ risk spreads", *Review of Financial Studies* 10(2).
209
+
210
+ ## License
211
+
212
+ Apache-2.0. Part of [eqlx.org](https://eqlx.org): deterministic tools for AI agents in credit and
213
+ finance. Questions: research@eqlx.ai.