creditriskengine 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.
Files changed (229) hide show
  1. creditriskengine-0.2.0/.github/workflows/ci.yml +30 -0
  2. creditriskengine-0.2.0/.github/workflows/release.yml +22 -0
  3. creditriskengine-0.2.0/.gitignore +39 -0
  4. creditriskengine-0.2.0/CHANGELOG.md +148 -0
  5. creditriskengine-0.2.0/CONTRIBUTING.md +64 -0
  6. creditriskengine-0.2.0/LICENSE +201 -0
  7. creditriskengine-0.2.0/PKG-INFO +274 -0
  8. creditriskengine-0.2.0/README.md +221 -0
  9. creditriskengine-0.2.0/benchmarks/bench_portfolio.py +165 -0
  10. creditriskengine-0.2.0/configs/example_portfolio.yml +63 -0
  11. creditriskengine-0.2.0/configs/example_run.yml +55 -0
  12. creditriskengine-0.2.0/docs/api/.gitkeep +0 -0
  13. creditriskengine-0.2.0/docs/api/core.md +6 -0
  14. creditriskengine-0.2.0/docs/api/ecl.md +5 -0
  15. creditriskengine-0.2.0/docs/api/models.md +6 -0
  16. creditriskengine-0.2.0/docs/api/portfolio.md +6 -0
  17. creditriskengine-0.2.0/docs/api/rwa.md +5 -0
  18. creditriskengine-0.2.0/docs/api/validation.md +5 -0
  19. creditriskengine-0.2.0/docs/architecture.md +120 -0
  20. creditriskengine-0.2.0/docs/changelog.md +3 -0
  21. creditriskengine-0.2.0/docs/getting_started.md +153 -0
  22. creditriskengine-0.2.0/docs/guide/ecl.md +35 -0
  23. creditriskengine-0.2.0/docs/guide/irb.md +44 -0
  24. creditriskengine-0.2.0/docs/guide/sa.md +36 -0
  25. creditriskengine-0.2.0/docs/guide/stress.md +33 -0
  26. creditriskengine-0.2.0/docs/guide/validation.md +31 -0
  27. creditriskengine-0.2.0/docs/index.md +38 -0
  28. creditriskengine-0.2.0/docs/regulatory_disclaimers.md +70 -0
  29. creditriskengine-0.2.0/docs/regulatory_mapping.md +101 -0
  30. creditriskengine-0.2.0/docs/regulatory_versioning.md +53 -0
  31. creditriskengine-0.2.0/examples/01_basic_rwa_calculation.py +118 -0
  32. creditriskengine-0.2.0/examples/02_irb_corporate_portfolio.py +71 -0
  33. creditriskengine-0.2.0/examples/03_ifrs9_ecl_pipeline.py +124 -0
  34. creditriskengine-0.2.0/examples/04_scorecard_development.py +85 -0
  35. creditriskengine-0.2.0/examples/05_model_validation.py +150 -0
  36. creditriskengine-0.2.0/examples/06_multi_jurisdiction.py +122 -0
  37. creditriskengine-0.2.0/mkdocs.yml +73 -0
  38. creditriskengine-0.2.0/pyproject.toml +85 -0
  39. creditriskengine-0.2.0/src/creditriskengine/__init__.py +42 -0
  40. creditriskengine-0.2.0/src/creditriskengine/core/__init__.py +46 -0
  41. creditriskengine-0.2.0/src/creditriskengine/core/audit.py +191 -0
  42. creditriskengine-0.2.0/src/creditriskengine/core/config.py +31 -0
  43. creditriskengine-0.2.0/src/creditriskengine/core/exceptions.py +29 -0
  44. creditriskengine-0.2.0/src/creditriskengine/core/exposure.py +117 -0
  45. creditriskengine-0.2.0/src/creditriskengine/core/logging_config.py +88 -0
  46. creditriskengine-0.2.0/src/creditriskengine/core/portfolio.py +48 -0
  47. creditriskengine-0.2.0/src/creditriskengine/core/types.py +151 -0
  48. creditriskengine-0.2.0/src/creditriskengine/ecl/__init__.py +17 -0
  49. creditriskengine-0.2.0/src/creditriskengine/ecl/cecl/__init__.py +24 -0
  50. creditriskengine-0.2.0/src/creditriskengine/ecl/cecl/cecl_calc.py +85 -0
  51. creditriskengine-0.2.0/src/creditriskengine/ecl/cecl/methods.py +104 -0
  52. creditriskengine-0.2.0/src/creditriskengine/ecl/cecl/qualitative.py +70 -0
  53. creditriskengine-0.2.0/src/creditriskengine/ecl/ifrs9/__init__.py +30 -0
  54. creditriskengine-0.2.0/src/creditriskengine/ecl/ifrs9/ecl_calc.py +142 -0
  55. creditriskengine-0.2.0/src/creditriskengine/ecl/ifrs9/forward_looking.py +61 -0
  56. creditriskengine-0.2.0/src/creditriskengine/ecl/ifrs9/lifetime_pd.py +110 -0
  57. creditriskengine-0.2.0/src/creditriskengine/ecl/ifrs9/scenarios.py +70 -0
  58. creditriskengine-0.2.0/src/creditriskengine/ecl/ifrs9/sicr.py +73 -0
  59. creditriskengine-0.2.0/src/creditriskengine/ecl/ifrs9/staging.py +78 -0
  60. creditriskengine-0.2.0/src/creditriskengine/ecl/ifrs9/ttc_to_pit.py +98 -0
  61. creditriskengine-0.2.0/src/creditriskengine/ecl/ind_as109/__init__.py +14 -0
  62. creditriskengine-0.2.0/src/creditriskengine/ecl/ind_as109/ind_as_ecl.py +97 -0
  63. creditriskengine-0.2.0/src/creditriskengine/models/__init__.py +76 -0
  64. creditriskengine-0.2.0/src/creditriskengine/models/concentration/__init__.py +17 -0
  65. creditriskengine-0.2.0/src/creditriskengine/models/concentration/concentration.py +141 -0
  66. creditriskengine-0.2.0/src/creditriskengine/models/concentration/granularity.py +12 -0
  67. creditriskengine-0.2.0/src/creditriskengine/models/concentration/hhi.py +11 -0
  68. creditriskengine-0.2.0/src/creditriskengine/models/concentration/sector.py +11 -0
  69. creditriskengine-0.2.0/src/creditriskengine/models/ead/__init__.py +21 -0
  70. creditriskengine-0.2.0/src/creditriskengine/models/ead/ccf.py +9 -0
  71. creditriskengine-0.2.0/src/creditriskengine/models/ead/ead_estimation.py +9 -0
  72. creditriskengine-0.2.0/src/creditriskengine/models/ead/ead_model.py +195 -0
  73. creditriskengine-0.2.0/src/creditriskengine/models/ead/regulatory_ccf.py +9 -0
  74. creditriskengine-0.2.0/src/creditriskengine/models/lgd/__init__.py +29 -0
  75. creditriskengine-0.2.0/src/creditriskengine/models/lgd/cure_rate.py +261 -0
  76. creditriskengine-0.2.0/src/creditriskengine/models/lgd/downturn_lgd.py +9 -0
  77. creditriskengine-0.2.0/src/creditriskengine/models/lgd/lgd_model.py +210 -0
  78. creditriskengine-0.2.0/src/creditriskengine/models/lgd/regulatory_lgd.py +9 -0
  79. creditriskengine-0.2.0/src/creditriskengine/models/lgd/workout_lgd.py +9 -0
  80. creditriskengine-0.2.0/src/creditriskengine/models/pd/__init__.py +81 -0
  81. creditriskengine-0.2.0/src/creditriskengine/models/pd/binning.py +474 -0
  82. creditriskengine-0.2.0/src/creditriskengine/models/pd/calibration.py +12 -0
  83. creditriskengine-0.2.0/src/creditriskengine/models/pd/logistic.py +9 -0
  84. creditriskengine-0.2.0/src/creditriskengine/models/pd/margin_of_conservatism.py +270 -0
  85. creditriskengine-0.2.0/src/creditriskengine/models/pd/rating_scale.py +13 -0
  86. creditriskengine-0.2.0/src/creditriskengine/models/pd/scorecard.py +346 -0
  87. creditriskengine-0.2.0/src/creditriskengine/models/pd/structural.py +213 -0
  88. creditriskengine-0.2.0/src/creditriskengine/models/pd/term_structure.py +162 -0
  89. creditriskengine-0.2.0/src/creditriskengine/models/pd/transition_matrix.py +183 -0
  90. creditriskengine-0.2.0/src/creditriskengine/models/pd/ttc_calibration.py +10 -0
  91. creditriskengine-0.2.0/src/creditriskengine/models/pd/zscore.py +262 -0
  92. creditriskengine-0.2.0/src/creditriskengine/portfolio/__init__.py +43 -0
  93. creditriskengine-0.2.0/src/creditriskengine/portfolio/copula.py +194 -0
  94. creditriskengine-0.2.0/src/creditriskengine/portfolio/economic_capital.py +55 -0
  95. creditriskengine-0.2.0/src/creditriskengine/portfolio/stress_testing.py +1323 -0
  96. creditriskengine-0.2.0/src/creditriskengine/portfolio/var.py +369 -0
  97. creditriskengine-0.2.0/src/creditriskengine/portfolio/vasicek.py +198 -0
  98. creditriskengine-0.2.0/src/creditriskengine/py.typed +0 -0
  99. creditriskengine-0.2.0/src/creditriskengine/regulatory/__init__.py +11 -0
  100. creditriskengine-0.2.0/src/creditriskengine/regulatory/australia/apra.yml +137 -0
  101. creditriskengine-0.2.0/src/creditriskengine/regulatory/bcbs/bcbs_d424.yml +111 -0
  102. creditriskengine-0.2.0/src/creditriskengine/regulatory/brazil/bcb.yml +143 -0
  103. creditriskengine-0.2.0/src/creditriskengine/regulatory/canada/osfi.yml +139 -0
  104. creditriskengine-0.2.0/src/creditriskengine/regulatory/china/nfra.yml +142 -0
  105. creditriskengine-0.2.0/src/creditriskengine/regulatory/eu/crr3.yml +188 -0
  106. creditriskengine-0.2.0/src/creditriskengine/regulatory/hongkong/hkma.yml +121 -0
  107. creditriskengine-0.2.0/src/creditriskengine/regulatory/india/rbi.yml +123 -0
  108. creditriskengine-0.2.0/src/creditriskengine/regulatory/japan/jfsa.yml +131 -0
  109. creditriskengine-0.2.0/src/creditriskengine/regulatory/loader.py +72 -0
  110. creditriskengine-0.2.0/src/creditriskengine/regulatory/malaysia/bnm.yml +147 -0
  111. creditriskengine-0.2.0/src/creditriskengine/regulatory/saudi/sama.yml +114 -0
  112. creditriskengine-0.2.0/src/creditriskengine/regulatory/schema.py +352 -0
  113. creditriskengine-0.2.0/src/creditriskengine/regulatory/singapore/mas_637.yml +114 -0
  114. creditriskengine-0.2.0/src/creditriskengine/regulatory/southafrica/sarb.yml +132 -0
  115. creditriskengine-0.2.0/src/creditriskengine/regulatory/southkorea/fss.yml +134 -0
  116. creditriskengine-0.2.0/src/creditriskengine/regulatory/uae/cbuae.yml +113 -0
  117. creditriskengine-0.2.0/src/creditriskengine/regulatory/uk/pra_basel31.yml +143 -0
  118. creditriskengine-0.2.0/src/creditriskengine/regulatory/us/us_endgame.yml +108 -0
  119. creditriskengine-0.2.0/src/creditriskengine/reporting/__init__.py +27 -0
  120. creditriskengine-0.2.0/src/creditriskengine/reporting/corep.py +453 -0
  121. creditriskengine-0.2.0/src/creditriskengine/reporting/fr_y14.py +485 -0
  122. creditriskengine-0.2.0/src/creditriskengine/reporting/model_doc.py +627 -0
  123. creditriskengine-0.2.0/src/creditriskengine/reporting/pillar3.py +285 -0
  124. creditriskengine-0.2.0/src/creditriskengine/reporting/reports.py +147 -0
  125. creditriskengine-0.2.0/src/creditriskengine/reporting/templates/.gitkeep +0 -0
  126. creditriskengine-0.2.0/src/creditriskengine/reporting/templates/model_doc.html.j2 +298 -0
  127. creditriskengine-0.2.0/src/creditriskengine/rwa/__init__.py +15 -0
  128. creditriskengine-0.2.0/src/creditriskengine/rwa/base.py +95 -0
  129. creditriskengine-0.2.0/src/creditriskengine/rwa/capital_buffers.py +519 -0
  130. creditriskengine-0.2.0/src/creditriskengine/rwa/crm.py +411 -0
  131. creditriskengine-0.2.0/src/creditriskengine/rwa/cva.py +403 -0
  132. creditriskengine-0.2.0/src/creditriskengine/rwa/irb/__init__.py +21 -0
  133. creditriskengine-0.2.0/src/creditriskengine/rwa/irb/advanced.py +358 -0
  134. creditriskengine-0.2.0/src/creditriskengine/rwa/irb/asset_classes.py +207 -0
  135. creditriskengine-0.2.0/src/creditriskengine/rwa/irb/correlation.py +98 -0
  136. creditriskengine-0.2.0/src/creditriskengine/rwa/irb/formulas.py +425 -0
  137. creditriskengine-0.2.0/src/creditriskengine/rwa/irb/foundation.py +336 -0
  138. creditriskengine-0.2.0/src/creditriskengine/rwa/irb/maturity.py +88 -0
  139. creditriskengine-0.2.0/src/creditriskengine/rwa/irb/slotting.py +208 -0
  140. creditriskengine-0.2.0/src/creditriskengine/rwa/leverage_ratio.py +256 -0
  141. creditriskengine-0.2.0/src/creditriskengine/rwa/market_risk.py +294 -0
  142. creditriskengine-0.2.0/src/creditriskengine/rwa/operational_risk.py +229 -0
  143. creditriskengine-0.2.0/src/creditriskengine/rwa/output_floor.py +216 -0
  144. creditriskengine-0.2.0/src/creditriskengine/rwa/securitisation.py +576 -0
  145. creditriskengine-0.2.0/src/creditriskengine/rwa/standardized/__init__.py +25 -0
  146. creditriskengine-0.2.0/src/creditriskengine/rwa/standardized/cre.py +194 -0
  147. creditriskengine-0.2.0/src/creditriskengine/rwa/standardized/credit_risk_sa.py +661 -0
  148. creditriskengine-0.2.0/src/creditriskengine/rwa/standardized/risk_weights.py +267 -0
  149. creditriskengine-0.2.0/src/creditriskengine/validation/__init__.py +32 -0
  150. creditriskengine-0.2.0/src/creditriskengine/validation/backtesting.py +338 -0
  151. creditriskengine-0.2.0/src/creditriskengine/validation/benchmarking.py +316 -0
  152. creditriskengine-0.2.0/src/creditriskengine/validation/calibration.py +233 -0
  153. creditriskengine-0.2.0/src/creditriskengine/validation/discrimination.py +244 -0
  154. creditriskengine-0.2.0/src/creditriskengine/validation/reporting.py +427 -0
  155. creditriskengine-0.2.0/src/creditriskengine/validation/stability.py +123 -0
  156. creditriskengine-0.2.0/tests/conftest.py +33 -0
  157. creditriskengine-0.2.0/tests/test_core/__init__.py +0 -0
  158. creditriskengine-0.2.0/tests/test_core/test_audit.py +315 -0
  159. creditriskengine-0.2.0/tests/test_core/test_logging_config.py +101 -0
  160. creditriskengine-0.2.0/tests/test_core/test_models.py +170 -0
  161. creditriskengine-0.2.0/tests/test_ecl/__init__.py +0 -0
  162. creditriskengine-0.2.0/tests/test_ecl/test_cecl.py +122 -0
  163. creditriskengine-0.2.0/tests/test_ecl/test_ifrs9_ecl.py +124 -0
  164. creditriskengine-0.2.0/tests/test_ecl/test_ind_as109.py +54 -0
  165. creditriskengine-0.2.0/tests/test_ecl/test_lifetime_pd.py +77 -0
  166. creditriskengine-0.2.0/tests/test_ecl/test_scenarios.py +39 -0
  167. creditriskengine-0.2.0/tests/test_ecl/test_staging.py +73 -0
  168. creditriskengine-0.2.0/tests/test_ecl/test_ttc_pit_fli.py +114 -0
  169. creditriskengine-0.2.0/tests/test_gaps.py +556 -0
  170. creditriskengine-0.2.0/tests/test_integration.py +227 -0
  171. creditriskengine-0.2.0/tests/test_pd_lgd_ead/__init__.py +0 -0
  172. creditriskengine-0.2.0/tests/test_pd_lgd_ead/test_binning.py +450 -0
  173. creditriskengine-0.2.0/tests/test_pd_lgd_ead/test_concentration.py +91 -0
  174. creditriskengine-0.2.0/tests/test_pd_lgd_ead/test_cure_rate.py +209 -0
  175. creditriskengine-0.2.0/tests/test_pd_lgd_ead/test_ead_model.py +144 -0
  176. creditriskengine-0.2.0/tests/test_pd_lgd_ead/test_lgd_model.py +219 -0
  177. creditriskengine-0.2.0/tests/test_pd_lgd_ead/test_margin_of_conservatism.py +186 -0
  178. creditriskengine-0.2.0/tests/test_pd_lgd_ead/test_pd_scorecard.py +328 -0
  179. creditriskengine-0.2.0/tests/test_pd_lgd_ead/test_pd_term_structure.py +162 -0
  180. creditriskengine-0.2.0/tests/test_pd_lgd_ead/test_structural.py +147 -0
  181. creditriskengine-0.2.0/tests/test_pd_lgd_ead/test_transition_matrix.py +263 -0
  182. creditriskengine-0.2.0/tests/test_pd_lgd_ead/test_zscore.py +154 -0
  183. creditriskengine-0.2.0/tests/test_portfolio/__init__.py +0 -0
  184. creditriskengine-0.2.0/tests/test_portfolio/test_copula.py +94 -0
  185. creditriskengine-0.2.0/tests/test_portfolio/test_reverse_stress.py +139 -0
  186. creditriskengine-0.2.0/tests/test_portfolio/test_risk_utils.py +140 -0
  187. creditriskengine-0.2.0/tests/test_portfolio/test_stress_testing.py +383 -0
  188. creditriskengine-0.2.0/tests/test_portfolio/test_var.py +189 -0
  189. creditriskengine-0.2.0/tests/test_portfolio/test_vasicek.py +127 -0
  190. creditriskengine-0.2.0/tests/test_regulatory/__init__.py +0 -0
  191. creditriskengine-0.2.0/tests/test_regulatory/test_loader.py +77 -0
  192. creditriskengine-0.2.0/tests/test_regulatory/test_schema.py +540 -0
  193. creditriskengine-0.2.0/tests/test_reporting/__init__.py +0 -0
  194. creditriskengine-0.2.0/tests/test_reporting/test_corep.py +194 -0
  195. creditriskengine-0.2.0/tests/test_reporting/test_fr_y14.py +214 -0
  196. creditriskengine-0.2.0/tests/test_reporting/test_model_doc.py +415 -0
  197. creditriskengine-0.2.0/tests/test_reporting/test_pillar3.py +195 -0
  198. creditriskengine-0.2.0/tests/test_reporting/test_reports.py +90 -0
  199. creditriskengine-0.2.0/tests/test_rwa/__init__.py +0 -0
  200. creditriskengine-0.2.0/tests/test_rwa/test_advanced_irb.py +283 -0
  201. creditriskengine-0.2.0/tests/test_rwa/test_asset_classes.py +182 -0
  202. creditriskengine-0.2.0/tests/test_rwa/test_base.py +144 -0
  203. creditriskengine-0.2.0/tests/test_rwa/test_capital_buffers.py +586 -0
  204. creditriskengine-0.2.0/tests/test_rwa/test_correlation.py +131 -0
  205. creditriskengine-0.2.0/tests/test_rwa/test_cre.py +230 -0
  206. creditriskengine-0.2.0/tests/test_rwa/test_credit_risk_sa.py +434 -0
  207. creditriskengine-0.2.0/tests/test_rwa/test_crm.py +514 -0
  208. creditriskengine-0.2.0/tests/test_rwa/test_cross_validation.py +203 -0
  209. creditriskengine-0.2.0/tests/test_rwa/test_cva.py +275 -0
  210. creditriskengine-0.2.0/tests/test_rwa/test_double_default.py +227 -0
  211. creditriskengine-0.2.0/tests/test_rwa/test_foundation_irb.py +251 -0
  212. creditriskengine-0.2.0/tests/test_rwa/test_irb_formulas.py +181 -0
  213. creditriskengine-0.2.0/tests/test_rwa/test_jurisdictions.py +195 -0
  214. creditriskengine-0.2.0/tests/test_rwa/test_leverage_ratio.py +267 -0
  215. creditriskengine-0.2.0/tests/test_rwa/test_market_risk.py +324 -0
  216. creditriskengine-0.2.0/tests/test_rwa/test_operational_risk.py +296 -0
  217. creditriskengine-0.2.0/tests/test_rwa/test_output_floor.py +70 -0
  218. creditriskengine-0.2.0/tests/test_rwa/test_regulatory_backtesting.py +350 -0
  219. creditriskengine-0.2.0/tests/test_rwa/test_risk_weights.py +251 -0
  220. creditriskengine-0.2.0/tests/test_rwa/test_sa_extended.py +225 -0
  221. creditriskengine-0.2.0/tests/test_rwa/test_securitisation.py +247 -0
  222. creditriskengine-0.2.0/tests/test_rwa/test_slotting.py +171 -0
  223. creditriskengine-0.2.0/tests/test_validation/__init__.py +0 -0
  224. creditriskengine-0.2.0/tests/test_validation/test_backtesting.py +280 -0
  225. creditriskengine-0.2.0/tests/test_validation/test_benchmarking.py +231 -0
  226. creditriskengine-0.2.0/tests/test_validation/test_calibration.py +129 -0
  227. creditriskengine-0.2.0/tests/test_validation/test_discrimination.py +143 -0
  228. creditriskengine-0.2.0/tests/test_validation/test_reporting.py +530 -0
  229. creditriskengine-0.2.0/tests/test_validation/test_stability.py +76 -0
@@ -0,0 +1,30 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ python-version: ["3.11", "3.12"]
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ - name: Set up Python ${{ matrix.python-version }}
18
+ uses: actions/setup-python@v5
19
+ with:
20
+ python-version: ${{ matrix.python-version }}
21
+ - name: Install dependencies
22
+ run: |
23
+ python -m pip install --upgrade pip
24
+ pip install -e ".[dev]"
25
+ - name: Lint with ruff
26
+ run: ruff check src/ tests/
27
+ - name: Type check with mypy
28
+ run: mypy src/creditriskengine/
29
+ - name: Test with pytest
30
+ run: pytest
@@ -0,0 +1,22 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ tags: ["v*"]
6
+
7
+ jobs:
8
+ publish:
9
+ runs-on: ubuntu-latest
10
+ permissions:
11
+ id-token: write
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+ - uses: actions/setup-python@v5
15
+ with:
16
+ python-version: "3.12"
17
+ - name: Build
18
+ run: |
19
+ pip install build
20
+ python -m build
21
+ - name: Publish to PyPI
22
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,39 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ build/
11
+ dist/
12
+ *.egg-info/
13
+ *.egg
14
+
15
+ # Virtual environments
16
+ .venv/
17
+ venv/
18
+ ENV/
19
+
20
+ # Environment variables
21
+ .env
22
+
23
+ # Type checking
24
+ .mypy_cache/
25
+
26
+ # Testing
27
+ .pytest_cache/
28
+ .coverage
29
+ htmlcov/
30
+
31
+ # IDE
32
+ .idea/
33
+ .vscode/
34
+ *.swp
35
+ *.swo
36
+
37
+ # OS
38
+ .DS_Store
39
+ Thumbs.db
@@ -0,0 +1,148 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ ## [0.2.0] - 2026-03-24
6
+
7
+ ### Added
8
+
9
+ **Spec Compliance (8 Gap Fixes)**
10
+ - QRRE transactor 0.75× RW scalar (BCBS CRE31.9 footnote 15)
11
+ - UK PRA loan-splitting for residential RE (`uk_pra_loan_splitting_rre()`)
12
+ - BoE ACS stress testing class with 5-year horizon and CET1 hurdle tracking
13
+ - 13 spec-aligned re-export modules for file granularity compliance
14
+ - SA Bank SCRA grade routing fix through `assign_sa_risk_weight()` dispatcher
15
+ - `is_short_term` parameter wired through SA bank risk weight dispatcher
16
+
17
+ **New Modules**
18
+ - Credit Risk Mitigation engine (`rwa/crm.py`): comprehensive approach,
19
+ simple approach, guarantee substitution, supervisory haircuts, maturity
20
+ mismatch (CRE22)
21
+ - Operational Risk SMA (`rwa/operational_risk.py`): Business Indicator
22
+ Component, Internal Loss Multiplier (OPE25)
23
+ - Market Risk FRTB integration (`rwa/market_risk.py`): SbM credit spread,
24
+ Default Risk Charge, Residual Risk Add-on (MAR)
25
+ - Audit trail (`core/audit.py`): `CalculationRecord`, `AuditTrail` with
26
+ JSON export and DataFrame output
27
+ - YAML schema validation (`regulatory/schema.py`): config validation,
28
+ input sanitization, range checks
29
+ - Structured logging (`core/logging_config.py`): JSON formatter for
30
+ production log aggregation
31
+
32
+ **Documentation**
33
+ - MkDocs site with Material theme (`mkdocs.yml`)
34
+ - API reference for all modules
35
+ - User guides: IRB, SA, ECL, stress testing, model validation
36
+ - Regulatory disclaimers with interpretation choices table
37
+ - Regulatory config versioning strategy
38
+ - Performance benchmarks (`benchmarks/bench_portfolio.py`)
39
+
40
+ **Packaging**
41
+ - `py.typed` PEP 561 marker for typed package
42
+ - Upper-bounded dependency versions (numpy<3.0, scipy<2.0, etc.)
43
+ - Project URLs (homepage, docs, issues, changelog)
44
+ - Python 3.13 classifier added
45
+
46
+ ### Changed
47
+ - EU CRR3 YAML: full 7-bucket LTV tables for residential and commercial RE,
48
+ detailed AIRB restrictions with revenue threshold, infrastructure supporting
49
+ factor
50
+ - EU CRR3 YAML: LGD supervisory values corrected (secured: 0.20→0.10,
51
+ other: 0.25→0.15) per CRE32.22-24
52
+ - EU CRR3 YAML: PD floor corrected from 5 bps to 3 bps per CRE32.13
53
+ - UK PRA YAML: LGD supervisory values corrected, loan-splitting config added
54
+
55
+ ### Tests
56
+ - 1,200+ tests with 100% line coverage
57
+ - Regulatory back-testing against Basel Committee worked examples
58
+ - Integration tests with 10,000+ exposure portfolios
59
+ - Cross-validation against known vendor reference ranges
60
+ - 0 ruff lint errors, 0 mypy type errors
61
+
62
+ ## [0.1.0] - 2026-03-22
63
+
64
+ ### Added
65
+
66
+ **Core**
67
+ - `Exposure` and `Collateral` Pydantic data models with field validation
68
+ - `Portfolio` container with filtering (by approach, default status)
69
+ - 17-value `Jurisdiction` enum (BCBS, EU, UK, US, India, + 12 more)
70
+ - Full enum set: `IRBAssetClass`, `SAExposureClass`, `CreditQualityStep`,
71
+ `IFRS9Stage`, `CollateralType`, `CRMApproach`, `DefaultDefinition`
72
+ - Custom exception hierarchy (`ConfigurationError`, `JurisdictionError`, etc.)
73
+
74
+ **RWA Calculation**
75
+ - Standardized Approach (CRE20): sovereign, bank (ECRA/SCRA), corporate,
76
+ retail, RRE/CRE LTV-based tables, ADC, equity, defaulted exposure classes
77
+ - Jurisdiction overrides: UK PRA 65% unrated IG, EU SME supporting factor,
78
+ India RBI residential mortgage thresholds
79
+ - IRB formulas (CRE31): asset correlations for all 5 classes, SME firm-size
80
+ adjustment, maturity adjustment, capital requirement K, risk weight dispatcher
81
+ - Output floor (RBC25): phase-in schedules for 10 jurisdictions including
82
+ EU transitional 25% cap (CRR3 Art. 92a(3))
83
+
84
+ **ECL Engines**
85
+ - IFRS 9: 12-month and lifetime ECL, 3-stage assignment with DPD backstop,
86
+ SICR assessment (relative/absolute PD change), lifetime PD term structures
87
+ (from annual PDs or transition matrices), TTC-to-PIT conversion (Z-factor),
88
+ macro overlay adjustments, probability-weighted scenario ECL
89
+ - CECL (ASC 326): PD/LGD lifetime method, loss-rate method, WARM, vintage
90
+ analysis, DCF, qualitative Q-factor adjustments (8 interagency categories)
91
+ - Ind AS 109: RBI 90 DPD NPA threshold, delegates to IFRS 9 calculation
92
+
93
+ **PD/LGD/EAD Modeling**
94
+ - PD scorecard: logistic score, score-to-PD, PD-to-scorecard-points,
95
+ master scale construction, rating grade assignment
96
+ - PD calibration: anchor-point method, Bayesian calibration,
97
+ Vasicek conditional (stressed) PD
98
+ - LGD model: workout LGD with discounting, downturn LGD (additive/haircut/
99
+ regulatory methods), LGD term structure, A-IRB LGD floors (CRE32.25)
100
+ - EAD model: EAD calculation, realized CCF estimation, supervisory CCFs
101
+ (CRE32.29-32), A-IRB CCF floor, EAD term structure with amortization
102
+
103
+ **Concentration Risk**
104
+ - Single-name concentration (HHI, top-N shares)
105
+ - Sector concentration via HHI
106
+ - Gordy (2003) Granularity Adjustment for Pillar 2
107
+
108
+ **Model Validation**
109
+ - Discrimination: AUROC (Mann-Whitney), Gini, KS, CAP curve, IV, Somers' D
110
+ - Calibration: binomial test, Hosmer-Lemeshow, Spiegelhalter, Basel traffic
111
+ light (green/yellow/red), Jeffreys Bayesian test, Brier score
112
+ - Stability: PSI, CSI, HHI, migration matrix stability (Frobenius norm)
113
+ - Backtesting: PD backtest summary statistics
114
+ - Benchmarking: model-vs-benchmark metric comparison
115
+ - Reporting: validation summary with traffic-light assessment
116
+
117
+ **Portfolio Risk**
118
+ - Vasicek ASRF: conditional default rate, loss quantile, EL/UL/EC,
119
+ full loss distribution PDF
120
+ - Gaussian copula: single-factor and multi-factor Monte Carlo with
121
+ antithetic variates, credit VaR, expected shortfall
122
+ - Economic capital via single-factor simulation
123
+ - Parametric credit VaR and marginal VaR contribution
124
+ - Stress testing: PD/LGD stress application, RWA impact calculation
125
+
126
+ **Regulatory Reporting**
127
+ - COREP credit risk summary (8% capital requirement, floor binding)
128
+ - Pillar 3 credit risk disclosure template
129
+ - Model inventory entry with RAG assessment
130
+
131
+ **Multi-Jurisdiction**
132
+ - 17 jurisdiction YAML configs with risk weights, PD/LGD floors, output
133
+ floor schedules, default definitions, capital requirements
134
+ - Jurisdictions: BCBS, EU, UK, US, India, Singapore, Hong Kong, Japan,
135
+ Australia, Canada, China, South Korea, UAE, Saudi Arabia, South Africa,
136
+ Brazil, Malaysia
137
+ - YAML config loader with jurisdiction-to-file mapping
138
+
139
+ **Infrastructure**
140
+ - GitHub Actions CI: Python 3.11/3.12, ruff, mypy, pytest with coverage
141
+ - GitHub Actions release workflow
142
+ - Example portfolio and run configuration files
143
+ - Documentation: architecture, getting started, regulatory mapping
144
+
145
+ ### Tests
146
+ - 384+ tests covering all modules
147
+ - Test coverage: 89%+
148
+ - 0 ruff lint errors, 0 mypy type errors
@@ -0,0 +1,64 @@
1
+ # Contributing to CreditRiskEngine
2
+
3
+ Thank you for your interest in contributing! This document explains how to get
4
+ started.
5
+
6
+ ## Development Setup
7
+
8
+ ```bash
9
+ git clone https://github.com/ankitjha67/baselkit.git
10
+ cd baselkit
11
+ pip install -e ".[dev]"
12
+ ```
13
+
14
+ Requires **Python 3.11+**.
15
+
16
+ ## Running Checks
17
+
18
+ All three must pass before submitting a PR:
19
+
20
+ ```bash
21
+ pytest # Tests (100% line coverage required)
22
+ ruff check src/ tests/ # Linting
23
+ mypy src/creditriskengine/ # Type checking (strict mode)
24
+ ```
25
+
26
+ ## Pull Request Process
27
+
28
+ 1. Fork the repo and create a feature branch from `main`.
29
+ 2. Make your changes. Add or update tests to maintain 100% coverage.
30
+ 3. Ensure `pytest`, `ruff check`, and `mypy` all pass locally.
31
+ 4. Write a clear commit message describing **why** the change is needed.
32
+ 5. Open a PR against `main`. The CI pipeline will re-run all checks.
33
+
34
+ ## Code Style
35
+
36
+ - Follow existing patterns in the codebase.
37
+ - All public functions must have docstrings with parameter documentation.
38
+ - Regulatory functions must cite the relevant BCBS/CRR/IFRS paragraph
39
+ (e.g., "BCBS CRE31.5").
40
+ - Type annotations are mandatory (`mypy --strict`).
41
+
42
+ ## Regulatory Contributions
43
+
44
+ If your change affects a regulatory calculation:
45
+
46
+ - Reference the specific regulatory paragraph in the docstring.
47
+ - Document any interpretation choices in the PR description.
48
+ - Add backtesting or reference-value tests where possible.
49
+ - Review [docs/regulatory_disclaimers.md](docs/regulatory_disclaimers.md) to
50
+ ensure disclaimers remain accurate.
51
+
52
+ ## Reporting Issues
53
+
54
+ Open an issue on [GitHub Issues](https://github.com/ankitjha67/baselkit/issues)
55
+ with:
56
+
57
+ - A clear description of the bug or feature request.
58
+ - For bugs: steps to reproduce, expected vs. actual behavior.
59
+ - For regulatory issues: cite the paragraph and your interpretation.
60
+
61
+ ## License
62
+
63
+ By contributing you agree that your contributions will be licensed under the
64
+ Apache 2.0 license (see [LICENSE](LICENSE)).
@@ -0,0 +1,201 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to the Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by the Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding any notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. Please also get an approval
186
+ from your organization's legal department before applying the
187
+ license.
188
+
189
+ Copyright 2024 Ankit Jha
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.