riskvalidation 0.8.0__py3-none-any.whl
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.
- riskvalidation/__init__.py +30 -0
- riskvalidation/aggregation/__init__.py +11 -0
- riskvalidation/aggregation/band.py +151 -0
- riskvalidation/aggregation/bounds.py +191 -0
- riskvalidation/aggregation/copulas.py +241 -0
- riskvalidation/aggregation/model_risk.py +133 -0
- riskvalidation/aggregation/simple.py +147 -0
- riskvalidation/ccr/__init__.py +13 -0
- riskvalidation/ccr/collateral.py +175 -0
- riskvalidation/ccr/cva.py +193 -0
- riskvalidation/ccr/exposure.py +192 -0
- riskvalidation/ccr/hw1f.py +426 -0
- riskvalidation/ccr/swaps.py +172 -0
- riskvalidation/core/__init__.py +1 -0
- riskvalidation/core/build.py +57 -0
- riskvalidation/core/hashing.py +48 -0
- riskvalidation/core/policy.py +130 -0
- riskvalidation/core/registry.py +65 -0
- riskvalidation/core/result.py +117 -0
- riskvalidation/core/suite.py +78 -0
- riskvalidation/engines/__init__.py +2 -0
- riskvalidation/engines/low_default.py +170 -0
- riskvalidation/engines/pd_curve.py +529 -0
- riskvalidation/engines/vasicek.py +72 -0
- riskvalidation/fairness/__init__.py +10 -0
- riskvalidation/fairness/_checks.py +115 -0
- riskvalidation/fairness/conditional.py +201 -0
- riskvalidation/fairness/inference.py +64 -0
- riskvalidation/fairness/metrics.py +261 -0
- riskvalidation/fairness/plants.py +240 -0
- riskvalidation/fairness/policy.py +97 -0
- riskvalidation/fairness/replication.py +39 -0
- riskvalidation/fairness/situation.py +307 -0
- riskvalidation/generators/__init__.py +68 -0
- riskvalidation/generators/_base.py +145 -0
- riskvalidation/generators/counts.py +232 -0
- riskvalidation/generators/drift.py +107 -0
- riskvalidation/generators/framingham.py +124 -0
- riskvalidation/generators/paths.py +349 -0
- riskvalidation/generators/ratings.py +186 -0
- riskvalidation/generators/scores.py +347 -0
- riskvalidation/harness/__init__.py +46 -0
- riskvalidation/harness/exact.py +137 -0
- riskvalidation/harness/performance.py +74 -0
- riskvalidation/harness/rates.py +103 -0
- riskvalidation/harness/run.py +197 -0
- riskvalidation/irrbb/__init__.py +9 -0
- riskvalidation/irrbb/behavioural.py +206 -0
- riskvalidation/irrbb/curves.py +286 -0
- riskvalidation/irrbb/eve_nii.py +245 -0
- riskvalidation/irrbb/shocks.py +171 -0
- riskvalidation/irrbb/simulation.py +203 -0
- riskvalidation/irrbb/slotting.py +184 -0
- riskvalidation/lgd_ead/__init__.py +8 -0
- riskvalidation/lgd_ead/_checks.py +50 -0
- riskvalidation/lgd_ead/ccf.py +228 -0
- riskvalidation/lgd_ead/downturn.py +64 -0
- riskvalidation/lgd_ead/floors.py +114 -0
- riskvalidation/lgd_ead/lgd_models.py +297 -0
- riskvalidation/lgd_ead/workout.py +162 -0
- riskvalidation/liquidity/__init__.py +9 -0
- riskvalidation/liquidity/_checks.py +78 -0
- riskvalidation/liquidity/cbc.py +158 -0
- riskvalidation/liquidity/deposits.py +151 -0
- riskvalidation/liquidity/ladder.py +119 -0
- riskvalidation/liquidity/reverse.py +141 -0
- riskvalidation/liquidity/runoff.py +220 -0
- riskvalidation/liquidity/scenarios.py +272 -0
- riskvalidation/market/__init__.py +8 -0
- riskvalidation/market/caviar.py +239 -0
- riskvalidation/market/conventions.py +83 -0
- riskvalidation/market/evt.py +111 -0
- riskvalidation/market/frtb.py +175 -0
- riskvalidation/market/garch.py +204 -0
- riskvalidation/market/gas_fz.py +219 -0
- riskvalidation/market/historical.py +96 -0
- riskvalidation/market/parametric.py +78 -0
- riskvalidation/market/scoring.py +145 -0
- riskvalidation/ml/__init__.py +11 -0
- riskvalidation/ml/_checks.py +67 -0
- riskvalidation/ml/_logistic.py +82 -0
- riskvalidation/ml/cbpe.py +91 -0
- riskvalidation/ml/challenger.py +73 -0
- riskvalidation/ml/conformal.py +116 -0
- riskvalidation/ml/dataquality.py +130 -0
- riskvalidation/ml/effects.py +67 -0
- riskvalidation/ml/explanations.py +125 -0
- riskvalidation/ml/generalisation.py +79 -0
- riskvalidation/ml/leakage.py +99 -0
- riskvalidation/ml/plants.py +425 -0
- riskvalidation/ml/policy.py +182 -0
- riskvalidation/ml/robustness.py +286 -0
- riskvalidation/ml/seeds.py +106 -0
- riskvalidation/oprisk/__init__.py +18 -0
- riskvalidation/oprisk/_checks.py +60 -0
- riskvalidation/oprisk/aggregate.py +375 -0
- riskvalidation/oprisk/distributions.py +758 -0
- riskvalidation/oprisk/scenarios.py +342 -0
- riskvalidation/oprisk/sla.py +80 -0
- riskvalidation/oprisk/sma.py +169 -0
- riskvalidation/policies/__init__.py +4 -0
- riskvalidation/policies/default.json +273 -0
- riskvalidation/portfolio/__init__.py +16 -0
- riskvalidation/portfolio/asrf_fit.py +283 -0
- riskvalidation/portfolio/copula.py +129 -0
- riskvalidation/portfolio/creditrisk_plus.py +232 -0
- riskvalidation/portfolio/euler.py +126 -0
- riskvalidation/portfolio/granularity.py +135 -0
- riskvalidation/portfolio/importance.py +277 -0
- riskvalidation/portfolio/portfolio.py +309 -0
- riskvalidation/provisions/__init__.py +8 -0
- riskvalidation/provisions/_checks.py +100 -0
- riskvalidation/provisions/ecl.py +233 -0
- riskvalidation/provisions/local_cl.py +360 -0
- riskvalidation/provisions/local_es.py +157 -0
- riskvalidation/provisions/overlays.py +102 -0
- riskvalidation/provisions/reconciliation.py +157 -0
- riskvalidation/provisions/staging.py +211 -0
- riskvalidation/provisions/term_structure.py +199 -0
- riskvalidation/regulatory/__init__.py +14 -0
- riskvalidation/regulatory/ba_cva.py +138 -0
- riskvalidation/regulatory/frtb.py +345 -0
- riskvalidation/regulatory/irb.py +314 -0
- riskvalidation/regulatory/lcr_nsfr.py +369 -0
- riskvalidation/regulatory/output_floor.py +45 -0
- riskvalidation/regulatory/sa_ccr.py +486 -0
- riskvalidation/regulatory/standardised.py +348 -0
- riskvalidation/stress/__init__.py +9 -0
- riskvalidation/stress/capital.py +476 -0
- riskvalidation/stress/paths.py +108 -0
- riskvalidation/stress/reverse.py +179 -0
- riskvalidation/stress/satellites.py +268 -0
- riskvalidation/stress/scenario_models.py +274 -0
- riskvalidation/transitions/__init__.py +0 -0
- riskvalidation/transitions/em.py +120 -0
- riskvalidation/transitions/embedding.py +221 -0
- riskvalidation/transitions/estimators.py +213 -0
- riskvalidation/transitions/intervals.py +306 -0
- riskvalidation/transitions/mobility.py +57 -0
- riskvalidation/transitions/ttc.py +171 -0
- riskvalidation/validation/__init__.py +103 -0
- riskvalidation/validation/_common.py +57 -0
- riskvalidation/validation/aggregation.py +425 -0
- riskvalidation/validation/calibration.py +757 -0
- riskvalidation/validation/ccr.py +530 -0
- riskvalidation/validation/discrimination.py +314 -0
- riskvalidation/validation/fairness.py +632 -0
- riskvalidation/validation/ifrs9.py +693 -0
- riskvalidation/validation/irrbb.py +389 -0
- riskvalidation/validation/lgd_ead.py +469 -0
- riskvalidation/validation/liquidity.py +647 -0
- riskvalidation/validation/market.py +807 -0
- riskvalidation/validation/ml.py +958 -0
- riskvalidation/validation/oprisk.py +357 -0
- riskvalidation/validation/portfolio.py +353 -0
- riskvalidation/validation/rating_system.py +245 -0
- riskvalidation/validation/stability.py +256 -0
- riskvalidation/validation/stress.py +552 -0
- riskvalidation/validation/transitions.py +386 -0
- riskvalidation-0.8.0.dist-info/METADATA +136 -0
- riskvalidation-0.8.0.dist-info/RECORD +164 -0
- riskvalidation-0.8.0.dist-info/WHEEL +5 -0
- riskvalidation-0.8.0.dist-info/licenses/LICENSE +21 -0
- riskvalidation-0.8.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
"""The Basel standardised credit risk weights (CRE20, in force 2023-01-01, published 2025-06-10) as data with their
|
|
2
|
+
paragraph.
|
|
3
|
+
|
|
4
|
+
Every function returns a `RegulatoryParameter`: the value (a risk weight, a credit conversion factor, a phase-in
|
|
5
|
+
factor or a multiplier, as a decimal) with its paragraph, its table and the in-force date of the chapter version, so a
|
|
6
|
+
view can show where each number comes from (dossier 01 M.3 item 8). A key outside a table raises `ValueError` naming
|
|
7
|
+
the table and the paragraph; the engine never returns a placeholder weight. The tables are transcribed from dossier 01
|
|
8
|
+
section C (CRE20.7 Table 1, CRE20.9 Table 2, CRE20.18 Table 6, CRE20.21 Table 7, CRE20.43 Table 10, CRE20.44 to
|
|
9
|
+
CRE20.47, CRE20.57 to CRE20.60, CRE20.68, CRE20.82 to CRE20.87 Tables 11 to 14, CRE20.92, CRE20.94 to CRE20.101,
|
|
10
|
+
CRE20.104 to CRE20.107). The engine computes and states no compliance claim. Rating buckets are the labels of the
|
|
11
|
+
tables; mapping an external rating to a bucket is the caller's (CRE21). A further CRE20 version in force 2028-01-01 is
|
|
12
|
+
not compared.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import math
|
|
18
|
+
import numbers
|
|
19
|
+
from dataclasses import dataclass
|
|
20
|
+
|
|
21
|
+
#: the in-force date of the CRE20 version transcribed here (published 2025-06-10)
|
|
22
|
+
CRE20_IN_FORCE = "2023-01-01"
|
|
23
|
+
|
|
24
|
+
SOVEREIGN_BUCKETS = ("AAA to AA-", "A+ to A-", "BBB+ to BBB-", "BB+ to B-", "below B-", "unrated")
|
|
25
|
+
BANK_BUCKETS = SOVEREIGN_BUCKETS[:5]
|
|
26
|
+
CORPORATE_BUCKETS = ("AAA to AA-", "A+ to A-", "BBB+ to BBB-", "BB+ to BB-", "below BB-", "unrated")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass(frozen=True)
|
|
30
|
+
class RegulatoryParameter:
|
|
31
|
+
"""A regulatory number with where it comes from."""
|
|
32
|
+
|
|
33
|
+
value: float # a risk weight, a credit conversion factor, a phase-in factor or a multiplier, as a decimal
|
|
34
|
+
paragraph: str # for example "CRE20.7"
|
|
35
|
+
table: str # for example "CRE20 Table 1"
|
|
36
|
+
in_force: str # ISO date of the chapter version
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
RiskWeight = RegulatoryParameter # alias: the class also carries the CCF (CRE20.94) and the phase-in factor (RBC90.1)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _p(value: float, paragraph: str, table: str, in_force: str = CRE20_IN_FORCE) -> RegulatoryParameter:
|
|
43
|
+
return RegulatoryParameter(float(value), paragraph, table, in_force)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _refuse(name: str, got: object, table: str, paragraph: str) -> ValueError:
|
|
47
|
+
return ValueError(f"{name} {got!r} is not a key of {table} ({paragraph})")
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _finite(name: str, x: object) -> float:
|
|
51
|
+
"""A finite real number, or `ValueError` naming the field (booleans, strings and None are refused)."""
|
|
52
|
+
if isinstance(x, (bool, str)) or x is None:
|
|
53
|
+
raise ValueError(f"{name} must be a finite number, got {x!r}")
|
|
54
|
+
try:
|
|
55
|
+
v = float(x) # type: ignore[arg-type]
|
|
56
|
+
except (TypeError, ValueError):
|
|
57
|
+
raise ValueError(f"{name} must be a finite number, got {x!r}") from None
|
|
58
|
+
if not math.isfinite(v):
|
|
59
|
+
raise ValueError(f"{name} must be finite, got {x!r}")
|
|
60
|
+
return v
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _nonnegative(name: str, x: object) -> float:
|
|
64
|
+
v = _finite(name, x)
|
|
65
|
+
if v < 0.0:
|
|
66
|
+
raise ValueError(f"{name} must be at least 0, got {x!r}")
|
|
67
|
+
return v
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
# CRE20.7 Table 1
|
|
71
|
+
_SOVEREIGN = dict(zip(SOVEREIGN_BUCKETS, (0.0, 0.2, 0.5, 1.0, 1.5, 1.0), strict=True))
|
|
72
|
+
# CRE20.9 Table 2 (export credit agency scores 0 to 7)
|
|
73
|
+
_ECA = dict(zip(range(8), (0.0, 0.0, 0.2, 0.5, 1.0, 1.0, 1.0, 1.5), strict=True))
|
|
74
|
+
# CRE20.18 Table 6: ECRA base and short-term claims (the unrated column is the SCRA, so it is not here)
|
|
75
|
+
_ECRA = dict(zip(BANK_BUCKETS, (0.2, 0.3, 0.5, 1.0, 1.5), strict=True))
|
|
76
|
+
_ECRA_SHORT = dict(zip(BANK_BUCKETS, (0.2, 0.2, 0.2, 0.5, 1.5), strict=True))
|
|
77
|
+
# CRE20.21 Table 7: SCRA grades A, B and C, base and short-term
|
|
78
|
+
_SCRA = {"A": 0.4, "B": 0.75, "C": 1.5}
|
|
79
|
+
_SCRA_SHORT = {"A": 0.2, "B": 0.5, "C": 1.5}
|
|
80
|
+
# CRE20.43 Table 10
|
|
81
|
+
_CORPORATE = dict(zip(CORPORATE_BUCKETS, (0.2, 0.5, 0.75, 1.0, 1.5, 1.0), strict=True))
|
|
82
|
+
# CRE20.68
|
|
83
|
+
_RETAIL = {"regulatory": 0.75, "transactor": 0.45, "other": 1.0}
|
|
84
|
+
# CRE20.57 to CRE20.60
|
|
85
|
+
_EQUITY = {"equity": 2.5, "speculative-unlisted": 4.0, "legislated-programme": 1.0, "subordinated-debt": 1.5}
|
|
86
|
+
# CRE20.82 Table 11 and CRE20.84 Table 12: upper edge of the LTV band (inclusive) and the weight; the last band is open
|
|
87
|
+
_LTV_EDGES = (0.5, 0.6, 0.8, 0.9, 1.0)
|
|
88
|
+
_RESIDENTIAL = (0.2, 0.25, 0.3, 0.4, 0.5, 0.7)
|
|
89
|
+
_RESIDENTIAL_CFD = (0.3, 0.35, 0.45, 0.6, 0.75, 1.05)
|
|
90
|
+
# CRE20.87 Table 14 (cash-flow dependent commercial real estate): edges 0.6 and 0.8
|
|
91
|
+
_COMMERCIAL_CFD = ((0.6, 0.7), (0.8, 0.9), (math.inf, 1.1))
|
|
92
|
+
# CRE20.94 to CRE20.101
|
|
93
|
+
_CCF = {
|
|
94
|
+
"direct-credit-substitute": 1.0,
|
|
95
|
+
"repo": 1.0,
|
|
96
|
+
"securities-lending": 1.0,
|
|
97
|
+
"forward-purchase": 1.0,
|
|
98
|
+
"nif-ruf": 0.5,
|
|
99
|
+
"transaction-related-contingent": 0.5,
|
|
100
|
+
"commitment": 0.4,
|
|
101
|
+
"trade-letter-of-credit": 0.2,
|
|
102
|
+
"unconditionally-cancellable": 0.1,
|
|
103
|
+
}
|
|
104
|
+
CURRENCY_MISMATCH_MULTIPLIER = 1.5 # CRE20.92
|
|
105
|
+
CURRENCY_MISMATCH_CAP = 1.5 # CRE20.92: the adjusted weight is at most 150 percent
|
|
106
|
+
LOAN_SPLITTING_WEIGHT = 0.2 # CRE20.83: up to 55 percent of the property value
|
|
107
|
+
LOAN_SPLITTING_SHARE = 0.55
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def sovereign_risk_weight(rating: str) -> RegulatoryParameter:
|
|
111
|
+
"""CRE20.7 Table 1: sovereigns and central banks by rating bucket."""
|
|
112
|
+
if rating not in _SOVEREIGN:
|
|
113
|
+
raise _refuse("rating", rating, "CRE20 Table 1", "CRE20.7")
|
|
114
|
+
return _p(_SOVEREIGN[rating], "CRE20.7", "CRE20 Table 1")
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def eca_risk_weight(score: int) -> RegulatoryParameter:
|
|
118
|
+
"""CRE20.9 Table 2: sovereigns scored by an export credit agency, scores 0 to 7."""
|
|
119
|
+
if isinstance(score, bool) or not isinstance(score, numbers.Integral) or int(score) not in _ECA:
|
|
120
|
+
raise ValueError(f"score {score!r} must be an integer 0 to 7 (CRE20 Table 2, CRE20.9)")
|
|
121
|
+
return _p(_ECA[int(score)], "CRE20.9", "CRE20 Table 2")
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def bank_risk_weight_ecra(rating: str, short_term: bool = False) -> RegulatoryParameter:
|
|
125
|
+
"""CRE20.18 Table 6: banks under the external credit risk assessment approach; `unrated` belongs to the SCRA."""
|
|
126
|
+
if rating == "unrated":
|
|
127
|
+
raise ValueError(
|
|
128
|
+
"rating 'unrated' is not in CRE20 Table 6 (CRE20.18): the SCRA applies (bank_risk_weight_scra)"
|
|
129
|
+
)
|
|
130
|
+
table = _ECRA_SHORT if short_term else _ECRA
|
|
131
|
+
if rating not in table:
|
|
132
|
+
raise _refuse("rating", rating, "CRE20 Table 6", "CRE20.18")
|
|
133
|
+
return _p(table[rating], "CRE20.18", "CRE20 Table 6")
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def bank_risk_weight_scra(grade: str, short_term: bool = False) -> RegulatoryParameter:
|
|
137
|
+
"""CRE20.21 Table 7: banks under the standardised credit risk assessment approach, grades A, B and C."""
|
|
138
|
+
table = _SCRA_SHORT if short_term else _SCRA
|
|
139
|
+
if grade not in table:
|
|
140
|
+
raise _refuse("grade", grade, "CRE20 Table 7", "CRE20.21")
|
|
141
|
+
return _p(table[grade], "CRE20.21", "CRE20 Table 7")
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def corporate_risk_weight(
|
|
145
|
+
rating: str,
|
|
146
|
+
sme: bool = False,
|
|
147
|
+
investment_grade_unrated: bool = False,
|
|
148
|
+
regulatory_retail_sme: bool = False,
|
|
149
|
+
) -> RegulatoryParameter:
|
|
150
|
+
"""CRE20.43 Table 10 by rating bucket; for an unrated corporate, the CRE20.44 to CRE20.47 alternatives by flag.
|
|
151
|
+
|
|
152
|
+
The three flags describe an unrated corporate (investment grade where ratings are not allowed, an SME, a
|
|
153
|
+
regulatory retail SME): a flag on a rated bucket and two flags at once are refused.
|
|
154
|
+
"""
|
|
155
|
+
flags = {
|
|
156
|
+
"sme": sme,
|
|
157
|
+
"investment_grade_unrated": investment_grade_unrated,
|
|
158
|
+
"regulatory_retail_sme": regulatory_retail_sme,
|
|
159
|
+
}
|
|
160
|
+
raised = [name for name, on in flags.items() if on]
|
|
161
|
+
if raised:
|
|
162
|
+
if rating != "unrated":
|
|
163
|
+
raise ValueError(
|
|
164
|
+
f"{raised[0]} applies to an unrated corporate only (CRE20.44 to CRE20.47), rating is {rating!r}"
|
|
165
|
+
)
|
|
166
|
+
if len(raised) > 1:
|
|
167
|
+
raise ValueError(f"{raised[0]} and {raised[1]} cannot both be set (CRE20.44 to CRE20.47)")
|
|
168
|
+
if sme:
|
|
169
|
+
return _p(0.85, "CRE20.47", "CRE20.47")
|
|
170
|
+
if regulatory_retail_sme:
|
|
171
|
+
return _p(0.75, "CRE20.47", "CRE20.47")
|
|
172
|
+
return _p(0.65, "CRE20.44", "CRE20.44 and CRE20.46")
|
|
173
|
+
if rating not in _CORPORATE:
|
|
174
|
+
raise _refuse("rating", rating, "CRE20 Table 10", "CRE20.43")
|
|
175
|
+
return _p(_CORPORATE[rating], "CRE20.43", "CRE20 Table 10")
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def retail_risk_weight(kind: str) -> RegulatoryParameter:
|
|
179
|
+
"""CRE20.68: regulatory retail 75 percent, transactors 45 percent, other retail 100 percent."""
|
|
180
|
+
if kind not in _RETAIL:
|
|
181
|
+
raise _refuse("kind", kind, "CRE20.68", "CRE20.68")
|
|
182
|
+
return _p(_RETAIL[kind], "CRE20.68", "CRE20.68")
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def equity_risk_weight(kind: str) -> RegulatoryParameter:
|
|
186
|
+
"""CRE20.57 to CRE20.60: equity, speculative unlisted equity, legislated programmes and subordinated debt."""
|
|
187
|
+
if kind not in _EQUITY:
|
|
188
|
+
raise _refuse("kind", kind, "CRE20.57 to CRE20.60", "CRE20.57")
|
|
189
|
+
return _p(_EQUITY[kind], "CRE20.57", "CRE20.57 to CRE20.60")
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def _band(ltv: float) -> int:
|
|
193
|
+
for i, edge in enumerate(_LTV_EDGES):
|
|
194
|
+
if ltv <= edge:
|
|
195
|
+
return i
|
|
196
|
+
return len(_LTV_EDGES)
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def residential_re_risk_weight(
|
|
200
|
+
ltv: float, cash_flow_dependent: bool = False, loan_splitting: bool = False
|
|
201
|
+
) -> RegulatoryParameter:
|
|
202
|
+
"""CRE20.82 Table 11 (and CRE20.84 Table 12 when cash-flow dependent) by LTV band; CRE20.83 loan splitting.
|
|
203
|
+
|
|
204
|
+
The upper edge of a band belongs to it (LTV exactly 0.8 gives 0.3). With loan splitting the weight is 0.2 for the
|
|
205
|
+
part of the loan up to 55 percent of the property value; splitting the loan is the caller's.
|
|
206
|
+
"""
|
|
207
|
+
value = _nonnegative("ltv", ltv)
|
|
208
|
+
if loan_splitting:
|
|
209
|
+
if cash_flow_dependent:
|
|
210
|
+
raise ValueError("loan_splitting applies to exposures that are not cash-flow dependent (CRE20.83)")
|
|
211
|
+
return _p(LOAN_SPLITTING_WEIGHT, "CRE20.83", "CRE20.83")
|
|
212
|
+
band = _band(value)
|
|
213
|
+
if cash_flow_dependent:
|
|
214
|
+
return _p(_RESIDENTIAL_CFD[band], "CRE20.84", "CRE20 Table 12")
|
|
215
|
+
return _p(_RESIDENTIAL[band], "CRE20.82", "CRE20 Table 11")
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def commercial_re_risk_weight(
|
|
219
|
+
ltv: float, cash_flow_dependent: bool, counterparty_weight: float | None = None
|
|
220
|
+
) -> RegulatoryParameter:
|
|
221
|
+
"""CRE20.85 Table 13 (not cash-flow dependent) and CRE20.87 Table 14 (cash-flow dependent) by LTV."""
|
|
222
|
+
value = _nonnegative("ltv", ltv)
|
|
223
|
+
if cash_flow_dependent:
|
|
224
|
+
for edge, weight in _COMMERCIAL_CFD:
|
|
225
|
+
if value <= edge:
|
|
226
|
+
return _p(weight, "CRE20.87", "CRE20 Table 14")
|
|
227
|
+
if counterparty_weight is None:
|
|
228
|
+
raise ValueError(
|
|
229
|
+
"counterparty_weight is required when the exposure is not cash-flow dependent (CRE20 Table 13, CRE20.85)"
|
|
230
|
+
)
|
|
231
|
+
cp = _nonnegative("counterparty_weight", counterparty_weight)
|
|
232
|
+
return _p(min(0.6, cp) if value <= 0.6 else cp, "CRE20.85", "CRE20 Table 13")
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def apply_currency_mismatch(weight: float) -> RegulatoryParameter:
|
|
236
|
+
"""CRE20.92: 1.5 times the unadjusted weight, at most 1.5 (150 percent); the result is the adjusted weight."""
|
|
237
|
+
w = _nonnegative("weight", weight)
|
|
238
|
+
return _p(min(CURRENCY_MISMATCH_MULTIPLIER * w, CURRENCY_MISMATCH_CAP), "CRE20.92", "CRE20.92")
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def credit_conversion_factor(kind: str) -> RegulatoryParameter:
|
|
242
|
+
"""CRE20.94 to CRE20.101: the credit conversion factor of an off-balance-sheet item (the `value` is the factor)."""
|
|
243
|
+
if kind not in _CCF:
|
|
244
|
+
raise _refuse("kind", kind, "CRE20.94 to CRE20.101", "CRE20.94")
|
|
245
|
+
return _p(_CCF[kind], "CRE20.94", "CRE20.94 to CRE20.101")
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
def defaulted_risk_weight(
|
|
249
|
+
specific_provision_share: float, residential_non_cash_flow_dependent: bool = False
|
|
250
|
+
) -> RegulatoryParameter:
|
|
251
|
+
"""CRE20.104 to CRE20.107: 150 percent below a specific provision share of 20 percent, 100 percent from it."""
|
|
252
|
+
share = _nonnegative("specific_provision_share", specific_provision_share)
|
|
253
|
+
if residential_non_cash_flow_dependent:
|
|
254
|
+
return _p(1.0, "CRE20.104", "CRE20.104 to CRE20.107")
|
|
255
|
+
return _p(1.5 if share < 0.2 else 1.0, "CRE20.104", "CRE20.104 to CRE20.107")
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
_CLASSES = (
|
|
259
|
+
"sovereign",
|
|
260
|
+
"eca",
|
|
261
|
+
"bank-ecra",
|
|
262
|
+
"bank-scra",
|
|
263
|
+
"corporate",
|
|
264
|
+
"retail",
|
|
265
|
+
"equity",
|
|
266
|
+
"residential-re",
|
|
267
|
+
"commercial-re",
|
|
268
|
+
"defaulted",
|
|
269
|
+
"ccf",
|
|
270
|
+
"currency-mismatch",
|
|
271
|
+
)
|
|
272
|
+
_OPTION_USERS = {
|
|
273
|
+
"short_term": ("bank-ecra", "bank-scra"),
|
|
274
|
+
"cash_flow_dependent": ("residential-re", "commercial-re"),
|
|
275
|
+
"counterparty_weight": ("commercial-re",),
|
|
276
|
+
}
|
|
277
|
+
_OPTION_DEFAULTS = {"short_term": False, "cash_flow_dependent": False, "counterparty_weight": None}
|
|
278
|
+
_CORPORATE_FLAGS = {
|
|
279
|
+
"investment-grade-unrated": "investment_grade_unrated",
|
|
280
|
+
"sme-unrated": "sme",
|
|
281
|
+
"regulatory-retail-sme": "regulatory_retail_sme",
|
|
282
|
+
}
|
|
283
|
+
_DEFAULTED_KEYS = ("provision-below-20pct", "provision-at-least-20pct", "residential-non-cash-flow-dependent")
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
def _ltv_key(key: str) -> float:
|
|
287
|
+
try:
|
|
288
|
+
return float(key)
|
|
289
|
+
except (TypeError, ValueError):
|
|
290
|
+
raise ValueError(f"key {key!r} must be the LTV as a string of the number") from None
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def lookup(exposure_class: str, key: str, **options: object) -> RegulatoryParameter:
|
|
294
|
+
"""The `RegulatoryParameter` of the function the class dispatches to.
|
|
295
|
+
|
|
296
|
+
`exposure_class` is one of sovereign, eca, bank-ecra, bank-scra, corporate, retail, equity, residential-re,
|
|
297
|
+
commercial-re, defaulted, ccf, currency-mismatch; `key` the rating bucket, the grade, the kind, an ECA score or an
|
|
298
|
+
LTV as a string, or for currency-mismatch `multiplier` or `cap`. The options are `short_term`,
|
|
299
|
+
`cash_flow_dependent` and `counterparty_weight`; an option the class does not use must be left at its default, and
|
|
300
|
+
an unknown option is refused.
|
|
301
|
+
"""
|
|
302
|
+
if exposure_class not in _CLASSES:
|
|
303
|
+
raise ValueError(f"exposure_class {exposure_class!r} is not one of {', '.join(_CLASSES)}")
|
|
304
|
+
for name, got in options.items():
|
|
305
|
+
if name not in _OPTION_DEFAULTS:
|
|
306
|
+
raise ValueError(f"option {name!r} is not one of short_term, cash_flow_dependent, counterparty_weight")
|
|
307
|
+
if exposure_class not in _OPTION_USERS[name] and got != _OPTION_DEFAULTS[name]:
|
|
308
|
+
raise ValueError(f"{name} does not apply to exposure_class {exposure_class!r}")
|
|
309
|
+
short_term = bool(options.get("short_term", False))
|
|
310
|
+
cash_flow_dependent = bool(options.get("cash_flow_dependent", False))
|
|
311
|
+
counterparty_weight = options.get("counterparty_weight")
|
|
312
|
+
if exposure_class == "sovereign":
|
|
313
|
+
return sovereign_risk_weight(key)
|
|
314
|
+
if exposure_class == "eca":
|
|
315
|
+
try:
|
|
316
|
+
score = int(key)
|
|
317
|
+
except (TypeError, ValueError):
|
|
318
|
+
raise ValueError(f"key {key!r} must be an ECA score as a string of the integer 0 to 7") from None
|
|
319
|
+
return eca_risk_weight(score)
|
|
320
|
+
if exposure_class == "bank-ecra":
|
|
321
|
+
return bank_risk_weight_ecra(key, short_term)
|
|
322
|
+
if exposure_class == "bank-scra":
|
|
323
|
+
return bank_risk_weight_scra(key, short_term)
|
|
324
|
+
if exposure_class == "corporate":
|
|
325
|
+
if key in _CORPORATE_FLAGS:
|
|
326
|
+
return corporate_risk_weight("unrated", **{_CORPORATE_FLAGS[key]: True})
|
|
327
|
+
return corporate_risk_weight(key)
|
|
328
|
+
if exposure_class == "retail":
|
|
329
|
+
return retail_risk_weight(key)
|
|
330
|
+
if exposure_class == "equity":
|
|
331
|
+
return equity_risk_weight(key)
|
|
332
|
+
if exposure_class == "residential-re":
|
|
333
|
+
return residential_re_risk_weight(_ltv_key(key), cash_flow_dependent)
|
|
334
|
+
if exposure_class == "commercial-re":
|
|
335
|
+
return commercial_re_risk_weight(_ltv_key(key), cash_flow_dependent, counterparty_weight) # type: ignore[arg-type]
|
|
336
|
+
if exposure_class == "defaulted":
|
|
337
|
+
if key not in _DEFAULTED_KEYS:
|
|
338
|
+
raise _refuse("key", key, "CRE20.104 to CRE20.107", "CRE20.104")
|
|
339
|
+
if key == "residential-non-cash-flow-dependent":
|
|
340
|
+
return defaulted_risk_weight(0.0, residential_non_cash_flow_dependent=True)
|
|
341
|
+
return defaulted_risk_weight(0.0 if key == "provision-below-20pct" else 0.2)
|
|
342
|
+
if exposure_class == "ccf":
|
|
343
|
+
return credit_conversion_factor(key)
|
|
344
|
+
if key == "multiplier":
|
|
345
|
+
return _p(CURRENCY_MISMATCH_MULTIPLIER, "CRE20.92", "CRE20.92")
|
|
346
|
+
if key == "cap":
|
|
347
|
+
return _p(CURRENCY_MISMATCH_CAP, "CRE20.92", "CRE20.92")
|
|
348
|
+
raise _refuse("key", key, "CRE20.92", "CRE20.92")
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"""Macro stress testing: the satellites of a default or loss rate, the scenario paths, the capital engine of the IAPE
|
|
2
|
+
projection, the reverse stress and the scenario models (the VAR conditional forecast and growth-at-risk).
|
|
3
|
+
|
|
4
|
+
Modules are imported by path (for example ``from riskvalidation.stress import capital``); nothing is re-exported here.
|
|
5
|
+
Rates, ratios and probabilities are decimals; money is a float in one currency and is never converted; a path keeps the
|
|
6
|
+
unit of its source. The engine computes and states no compliance claim: the reverse stress statement and the P2G proxy
|
|
7
|
+
are Contraste's, not regulatory text. The supervisory replication (C19) is not part of this package. The validation
|
|
8
|
+
tests are in ``riskvalidation.validation.stress``. Contract: ``engine-stress-api`` 1.0.0.
|
|
9
|
+
"""
|