Risk_Manager / analytics /monitoring_analysis.py
GenAICoder's picture
Update analytics/monitoring_analysis.py
215a7b0 verified
Raw
History Blame Contribute Delete
1.66 kB
# analytics/monitoring_analysis.py
import pandas as pd
from metrics.vintage_metrics import (
calculate_vintage_dpd,
calculate_vintage_ncl
)
def generate_monitoring_table(df):
dpd_30_mob3 = calculate_vintage_dpd(
df=df,
mob=3,
dpd_threshold=30,
metric_type="count"
)
dpd_30_mob6 = calculate_vintage_dpd(
df=df,
mob=6,
dpd_threshold=30,
metric_type="count"
)
dpd_60_mob6 = calculate_vintage_dpd(
df=df,
mob=6,
dpd_threshold=60,
metric_type="count"
)
ncl_y1 = calculate_vintage_ncl(
df=df,
mob=12
)
final_table = (
dpd_30_mob3[
["booking_vintage", "dpd_rate"]
]
.rename(
columns={
"dpd_rate": "30+@3"
}
)
)
final_table = final_table.merge(
dpd_30_mob6[
["booking_vintage", "dpd_rate"]
].rename(
columns={
"dpd_rate": "30+@6"
}
),
on="booking_vintage",
how="outer"
)
final_table = final_table.merge(
dpd_60_mob6[
["booking_vintage", "dpd_rate"]
].rename(
columns={
"dpd_rate": "60+@6"
}
),
on="booking_vintage",
how="outer"
)
final_table = final_table.merge(
ncl_y1[
["booking_vintage", "ncl_rate"]
].rename(
columns={
"ncl_rate": "Yr1_NCL"
}
),
on="booking_vintage",
how="outer"
)
return final_table