Instructions
Installation
Clone the credit risk modelling
package using HTTPS:
git clone https://github.com/RandomCollection/Credit-Risk-Modelling.git
Usage
Within a Python module, import the package as:
import credit_risk_modelling as crm
Many of the default configurations can be adjusted according to own preferences via the cfg.py
module. In particular,
grades, Probabilities of Default (PDs), colours, date formats, and column names.
Example
data
>>> import credit_risk_modelling as crm
>>> data = crm.load_data.load_data()
>>> data
DATE ID GRADE GRADE_PD OVERRIDE OVERRIDE_PD DEFAULT
0 2019-12-31 10 B 0.1000 B 0.1000 0
1 2019-12-31 100 BBB 0.0090 BB 0.0400 0
2 2019-12-31 1000 BBB 0.0090 BBB 0.0090 0
3 2019-12-31 1001 BBB 0.0090 BBB 0.0090 0
4 2019-12-31 1003 BBB 0.0090 BBB 0.0090 0
... ... ... ... ... ... ... ...
4145 2023-12-31 994 AA 0.0010 AA 0.0010 0
4146 2023-12-31 995 AA 0.0010 AA 0.0010 0
4147 2023-12-31 996 A 0.0020 A 0.0020 0
4148 2023-12-31 998 B 0.1000 B 0.1000 0
4149 2023-12-31 999 AAA 0.0002 AAA 0.0002 0
[4150 rows x 7 columns]
Discrimination
>>> discrimination = (
>>> data
>>> .crm.discrimination(default="DEFAULT", score="GRADE_PD", alpha=0.1, by="DATE")
>>> )
.table()
>>> discrimination.table()
BY OBS DEFAULT_OBS AR AR_BOUND_LOWER AR_BOUND_UPPER ALPHA
0 2019-12-31 750 131 0.941644 0.907460 0.975829 0.1
1 2020-12-31 800 170 0.905444 0.867548 0.943339 0.1
2 2021-12-31 700 150 0.929358 0.894257 0.964458 0.1
3 2022-12-31 900 205 0.932367 0.902949 0.961785 0.1
4 2023-12-31 1000 236 0.921183 0.891655 0.950711 0.1
.plot()
>>> discrimination.plot(show=True)