Override
The module provides methods to perform override analytics. In general, it can be used to analyse changes in grades per date. For changes in grades between two dates, see the "migration" method. It provides the number of observations, the rating grade upgrades, the rating grade downgrades, the rating grade migration rate (rating grade changes of more than one grade to number of cohort), and the rating grade downgrade rate (rating grade downgrades of more than one grade to rating grade changes of more than one grade). It also provides a "heatmap" override matrix.
Accessor
Initialise the DataFrame with the override method. Minimal working example:
df.crm.override(grade_1="GRADE_1", grade_2="GRADE_2")
Parameters:
Name | Type | Description | Default |
---|---|---|---|
grade_1
|
str
|
Defines the first grade column, for example, grades before an override. Scores can be transformed to grades via the module "general.py" if necessary. |
required |
grade_2
|
str
|
Defines the second grade column, for example, grades after an override. Scores can be transformed to grades via the module "general.py" if necessary. |
required |
Returns:
Type | Description |
---|---|
Override
|
Returns a class called "Override" providing override analytics methods. |
Methods
plot(x_axis_label='Grade After Override', y_axis_label='Grade Before Override', grade_range=None, annotation=True, font_size=7, fig_size=(7.5, 7.5), path=None, show=False)
Minimal working example:
df.crm.override(grade_1="GRADE_1", grade_2="GRADE_2").plot()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x_axis_label
|
str
|
Defines the x-axis label. |
'Grade After Override'
|
y_axis_label
|
str
|
Defines the y-axis label. |
'Grade Before Override'
|
grade_range
|
list
|
Extends the grade range to the specified range. Use "cfg.GRADES" for the complete range. |
None
|
annotation
|
bool
|
Adds a "Downgrade" and "Upgrade" box to the plot. |
True
|
font_size
|
int
|
Defines the font size of the plot. |
7
|
fig_size
|
tuple
|
Defines the figure size. |
(7.5, 7.5)
|
path
|
str
|
Defines the saving path including the filename of the figure and should be entered as r"C:\<path>\<filename>.<image_format>". |
None
|
show
|
bool
|
If True, plot is shown. |
False
|
Returns:
Type | Description |
---|---|
BytesIO
|
Returns a "heatmap" override matrix. |
table()
Minimal working example:
df.crm.override(grade_1="GRADE_1", grade_2="GRADE_2").table()
Returns:
Type | Description |
---|---|
DataFrame
|
Returns a table containing the number of observations, the rating grade upgrades, and the rating grade downgrades. |
Examples
>>> 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]
>>> (
>>> data
>>> .loc[lambda df: df["DATE"].dt.year == 2023]
>>> .crm.override(grade_1="GRADE", grade_2="OVERRIDE")
>>> .table()
>>> )
OBS_1 OUTFLOWS OBS_1_COHORT OBS_2 INFLOWS OBS_2_COHORT UNCHANGED UP_1 UP_2 UP_3 UP_>3 UP_TOTAL DOWN_1 DOWN_2 DOWN_3 DOWN_>3 DOWN_TOTAL MR DR
0 1000 0 1000 1000 0 1000 929 9 7 3 12 31 13 8 4 15 40 0.049 0.55102
>>> (
>>> data
>>> .loc[lambda df: df["DATE"].dt.year == 2023]
>>> .crm.override(grade_1="GRADE", grade_2="OVERRIDE")
>>> .plot(show=True)
>>> )