Preparing Default Labels and Weight-of-Evidence Features for Credit Risk
Summary
The document describes a credit-risk data preparation workflow for estimating probability of default. The example defines a default event from arrears, term-expiry, or bankruptcy indicators, recodes the outcome for modeling convenience, and uses stratified sampling to split observations into training and test sets. It also shows date conversion and rounding of arrears fields as preprocessing steps.
The question concerns reproducing weight-of-evidence variables from a book’s example. The response says the author provides hardcoded WOE information in supplementary materials and points to R packages that can support binning and WOE calculation. It does not give the actual feature bins, formulas, or code needed to recreate the variables, so the advice is only a pointer. Reproduction depends on obtaining the source data and matching the author’s binning and transformation choices; this is a credit-risk modeling example rather than a trading strategy.
Key ideas
- Define the default target by combining relevant delinquency, expiry, and bankruptcy events.
- Stratified sampling can preserve outcome proportions in training and test partitions.
- Weight-of-evidence features require binning and mappings from predictor groups to transformed values.
- Supplementary code or R packages may help reproduce the published WOE transformations.
- The response does not provide the bins or code, so exact replication remains unresolved.
Tags
Full text
# Calculation of the Probability of Default # Calculation of the Probability of Default 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. ## Answer by bugrabalkac (score 1) https://quant.stackexchange.com/a/60169 As I can see author shares hardcoded WOE information in https://www.tizianobellini.com/copy-of-data-and-code within the name of "Complementary Software Code". If you want to dig yourself in you can try several packages in R such as smbinning or Klar.
Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.