How to Prepare Data for Credit Risk Modeling | by Claire Zhang | Towards Data Science

Credit risk measures the probabilities of borrowers fail to pay back the debt and thus default on their obligations. Credit risk modeling is widely adopted in banking industry for multiple applications: from underwriting, account management (e.g. extending line of credits), credit allowance (CECL under GAAP and IFRS-9), stress testing (CCAR) and regulatory capital calculation (Basel II).
There are two key components of credit risk measurement: 1) probability of default (PD), usually defined as likelihood of default over a period of time; and 2) loss given default (LGD), typically referred to as the amount that can not be recovered after the borrower defaults. The multiplication of these two components gives one the expected loss1.
In this article, we will use Freddie Mac single-family loan level dataset as an example to show you how can one prepare the development data (including target variables and loan level characteristics) ready to tackle any credit risk modeling exercise. Let’s get started.
Freddie Mac provides public access (free registration required) to loan-level datasets on single-family mortgages purchased by the Agency from 1999 to 2020. The dataset is organized by quarterly vintages. Within each vintage, it includes 2 files:
Origination data: it contains loan characteristics at origination (e.g. term, interest rate, credit score, Loan-to-Value ratio, Debt-to-Income ratio etc.)Performance data: it contains loan-level monthly performance (including outstanding balance, delinquency status etc.) since origination to most recent quarter.
Origination data: it contains loan characteristics at origination (e.g. term, interest rate, credit score, Loan-to-Value ratio, Debt-to-Income ratio etc.)
Performance data: it contains loan-level monthly performance (including outstanding balance, delinquency status etc.) since origination to most recent quarter.
Since the dataset is a “living” file with new performances added to each vintage file periodically, and given the sheer volume of this dataset, you may want to write an automated downloading code (as shown in sample below) to retrieve data from the website:
#Specify login credentialslogin = { ‘username’: ‘your login email’, ‘password’: ‘your password’}#Define the vintage data to download (for this article, we will look into vintage from Q1 2014 to Q2 2019.Period = ["Q12014","Q22014",...,"Q22019"]with requests.Session() as s:   p =s.post('https://freddiemac.embs.com/FLoan/Data/download2.php')   for Qtr in Period:        #File Names        zip_file = "historical_data1_" + Qtr + ".zip"        perf_file = "historical_data1_time_" + Qtr + ".txt"        orig_file = "historical_data1_" + Qtr + ".txt"        export_file = Qtr + ".csv"        r = s.get(os.path.join(Download, zip_file))        z = zipfile.ZipFile(io.BytesIO(r.content))        z.extractall(Input_Data_Path)
Since many of the loan level characteristics are the main drivers for credit loss forecasting (e.g. low credit score or low income group are generally more vulnerable to economic conditions and thus lead to default), after downloading the vintage files, the first step is to merge the origination data and performance data using account number as unique key. After the merge, now we can take a look at the portfolio overview and characteristics distributions.
LTV distribution at Originations
FICO score distribution at originations
If you are performing credit analysis for the first time, you maybe surprised that the definition of “default” is not as obvious as you might image. In most cases, “default” is not directly observable. For beginners, when it comes to default definition in credit risk modeling, there are two most common misunderstandings:
Is Default equivalent to Zero Balance before maturity?
No, there are many reasons that can cause the loan’s balance being reduced to zero prior to maturity date. Voluntary prepayment being the most common one, along with repurchase, REO disposition etc.
Is Default equivalent to Charge-Offs?
No, the lenders may write-off the amount of debt from its balance sheets when the debt is unlikely to be collected. However, charge-off may happen in a much later date after the loan being severely delinquent (e.g. 6 months without payments). Hence, using charge-off as default can not capture the actual “default” timing. That said, if a loan is charged-off (in some rare cases) without being delinquent, one should still consider it as a default event.
The most widely adopted definition followed in credit risk modeling is to define default event as the earlier date of 1) a loan becomes severely delinquent for the first time; or 2) a loss is recognized on the loan. Under this definition, any loan that results in losses for the portfolio will be included in the default population and the default date will be flagged concurrently with sign of loan characteristics deterioration.
Default = (Severely Delinquent at first time) U (Loss event)
Following this definition, I defined default on the Freddie Mac loan data as the earliest date when a loan become 180 day delinquent or the loan balance reduced to zero due to a) third party sale, b) short sale or charge-off; or c) REO disposition. The chart above represents the loan distributions in each delinquency status. There are 2 immediate observations that can be extracted from the analysis above. First, the sudden “Current” rate drop in Aug 2017 was caused by Hurricane Harvey and subsequently it led to the spikes in delinquency status. Second, one can notice that other than the percentage loan in “Current” status, the delinquency and PD rate keep monotonically increasing from 2014 onwards. This is due to the shape of default curve throughout the mortgage life-cycle, where the default rates generally increases shortly after its origination and reaches its peak when the loans are about 3–5 years in age (as shown in the chart below).
In addition, this definition of default is also known as “first time default”. It is not uncommon to see that a “defaulted” loan may become reperforming / Current again, i.e. being “Cured”. We will discuss this behavior in the “Cured Rate Analysis” below.
Other than modeling the PD directly, often times you will see that the credit risk modeling are focusing on predicting a transition matrix, with delinquency status as “states”, and particularly, default as the “absorbing state”. Individual sub-models are then developed to predict the transition probabilities from one state to the other.
Why is transition probability important?
Let’s look at the two transition probabilities comparisons below:
The first chart demonstrates that there is a strong correlation between the “Current to 30 Day-Past-Due (DPD)” transition and the PD rate. In fact, the spike due to Hurricane Harvey in 2017 almost maintains the exact same shape in the 2 curves with about 6 months time interval.
The second chart below shows the transition probabilities from “30DPD to 60 DPD” and compares that to the one from “60DPD to 90DPD”. One can see that these 2 transitions probabilities are mostly flat across time and the probability of a loan advancing to the next stage of delinquency is almost tripled as it progresses from 30DPD to 60DPD.
What these 2 charts above tell us is that, in order to predict PD, one can also focus on forecasting the transition probability from Current-to-30DPD as an early warning indicator. Because once a loan’s payment is missed, its path to default become a lot more deterministic, with higher certainties as the loan turning more severely delinquent.
Because of the “first time default” definition, you may be wondering what happens after a loan defaulted? There are three typical paths: 1) Charge-off: the loan remains on the balance sheet for an extended period of time until the Bank decide to write it off; 2) Restructuring: the bank works with borrower to come up with a repayment plan; 3) Reperforming: the borrower starts to make payments again and at certain point the loan can even become Current again, i.e. being Cured.
Often times in credit risk modeling, cure rates are not modeled specifically due to its low probabilities. As shown in the chart below, as a loan advances in its delinquency status, the chance of it coming back to Current decreases drastically from 50% to less than 10%, and the cure rate after “default” is expected to be even lower.
In summary, defining PD (or Transition Matrix) is critical to tackle almost any credit risk modeling problem, and there is no set answer to that. Similar to the process covered in this article, it is best practice to determine the PD definition based on loan level characteristics, performance data analysis, along with bank’s credit policies.
Hope you enjoy this introduction to the probability of default and transition matrix analysis. Leave your comments below if you like it. The full code of the above analysis can be found here.
Footnote
[1] EAD: You may have also heard of a third component EAD exposure at default. For term loans like mortgage, and auto loans, EAD is used interchangeably with remaining balance, while for installment loans, like HELOC, or credit cards, apart from the outstanding balance, EAD is also determined by % of undrawn balance that borrower will have used at default (also known as LEQ — loan equivalent exposures). Details of EAD is not covered in this article.