I am reading a book from Tiziano Bellini namely IFRS 9 and CECL Credit Risk Modelling and Validation, to understand the default probability calculation (link : https://www.sciencedirect.com/science/article/pii/B9780128149409000104?via%3Dihub)
Author has provided some R code to illustrate the PD calculation. The Page-51, says that -
# 1. Default flag definition and data preparation
# 1.1. Import data
oneypd<- read.csv(’chap2oneypd.csv’) [,2:45]
library(dplyr)
# 1.1.1. Data overview: data content and format
dplyr::glimpse(oneypd)
# $ id <int> 6670001, 9131199...
# $ vintage_year <int> 2005, 2006...
# $ monthly_installment <dbl> 746.70, 887.40...
# $ loan_balance <dbl> 131304.44, 115486.51...
# $ bureau_score <int> 541, 441...
# ...
# 1.1.2. Date format
library(vars)
oneypd <- dplyr::mutate_at(oneypd, vars(contains(’date’)),
funs(as.Date))
class(oneypd$origination_date)
# 1.1.3. Round arrears count fields
oneypd$max_arrears_12m<- round(oneypd$max_arrears_12m,4)
oneypd$arrears_months<- round(oneypd$arrears_months,4)
# 1.2. Default flag definition
oneypd<- dplyr::mutate(oneypd,
default_event = if_else(oneypd$arrears_event == 1 |
oneypd$term_expiry_event == 1 |
oneypd$bankrupt_event == 1, 1,0))
# 1.3. Database split in train and test samples
# Recode default event variables for more convenient use
# 0-default, 1-non-default
oneypd$default_flag<-
dplyr::if_else(oneypd$default_event == 1,0,1)
# Perform a stratified sampling: 70% train and 30% test
library(caret)
set.seed(2122)
train.index <- caret::createDataPartition(oneypd$default_event,
p = .7, list = FALSE)
train <- oneypd[ train.index,]
test <- oneypd[-train.index,]
Then, he created following table -
However I failed to replicate the generation of the variables starting with woe_
i.e. woe_cc_util
etc.
Can you please help me to create corresponding R
codes to construct those variables? The data is available from the link - https://www.tizianobellini.com/copy-of-chapter-2-4
Really appreciate for any pointer.