• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Finance Train

Finance Train

High Quality tutorials for finance, risk, data science

  • Home
  • Data Science
  • CFA® Exam
  • PRM Exam
  • Tutorials
  • Careers
  • Products
  • Login

Explore Loan Data in R – Loan Grade and Interest Rate

Data Science, Risk Management

This lesson is part 12 of 28 in the course Credit Risk Modelling in R

There is no set path to how one would go about analyzing a data set. Typically, a data scientist would spend quite some time exploring and observing the data to understand it well.

Let’s look at some of the attributes in our dataset and see their relationship with the default rate. For each loan, we have two basic attributes, namely, grade and the interest rate. In LendingClub, loan grade, or credit grade, is the letter (A-G or AA-HR) that is assigned to a borrower and corresponds with the interest rate that is charged for the loan.

These rates are set based on the originator’s underwriting assessment for the individual borrower. The higher the expected risk of default, the higher the interest rate is set in order to offset this risk. The assessment of the credit grade decision includes FICO, loan term (a shorter term is considered better), proprietary models, and the loan amount requested by the borrower.

We also have the interest rate being charged for each loan.

Default Rate for Each Loan Grade

Let’s create a plot where we will plot the default rate for each grade.

The following command will give us the number of defaults for each grade.

> g1 = loandata %>% filter(loan_status == "Default") %>% group_by(grade) %>% summarise(default_count = n())
> g1
# A tibble: 7 x 2
  grade default_count
  <chr>         <int>
1 A               975
2 B              3487
3 C              5534
4 D              3697
5 E              2704
6 F              1260
7 G               379
>

We can now calculate the default rate in each grade as follows:

> g2 = loandata %>% group_by(grade) %>% summarise(count = n())
> g3 <- g2 %>% left_join(g1) %>% mutate(default_rate = 100*default_count/count) %>% select(grade,count,default_count,default_rate)
Joining, by = "grade"
> g3
# A tibble: 7 x 4
  grade count default_count default_rate
  <chr> <int>         <int>        <dbl>
1 A      9956           975         9.79
2 B     16649          3487        20.9 
3 C     16815          5534        32.9 
4 D      8480          3697        43.6 
5 E      5261          2704        51.4 
6 F      2109          1260        59.7 
7 G       599           379        63.3 
>

We can now plot this using ggplot2.

> ggplot(g3, aes(x=grade, y=default_rate, fill=grade)) + geom_bar(stat="identity")

As we would expect, riskier loans have higher default rates.

Loan Grade Vs Interest Rate

We can also plot the relationship between Loan Grade and Interest Rate.

To do so, we will first convert the interest rate attribute to numeric.

> loandata$int_rate = (as.numeric(gsub(pattern = "%",replacement = "",x = loandata$int_rate)))

We can now group the data by grade and their mean interest rates:

> x1 = loandata %>% filter(loan_status == "Default") %>% group_by(grade) %>% summarise(int_rate=mean(int_rate))
> ggplot(x1, aes(x=grade, y=int_rate, fill=grade)) + geom_bar(stat="identity",position="dodge")

As we would expect, riskier loans (higher grades) have higher interest rates.

Previous Lesson

‹ Credit Risk Modelling – Case Study- Lending Club Data

Next Lesson

Credit Risk Modelling – Required R Packages ›

Join Our Facebook Group - Finance, Risk and Data Science

Posts You May Like

How to Improve your Financial Health

CFA® Exam Overview and Guidelines (Updated for 2021)

Changing Themes (Look and Feel) in ggplot2 in R

Coordinates in ggplot2 in R

Facets for ggplot2 Charts in R (Faceting Layer)

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

In this Course

  • Credit Risk Modelling – Case Studies
  • Classification vs. Regression Models
  • Case Study – German Credit – Steps to Build a Predictive Model
  • Import Credit Data Set in R
  • German Credit Data : Data Preprocessing and Feature Selection in R
  • Credit Modelling: Training and Test Data Sets
  • Build the Predictive Model
  • Logistic Regression Model in R
  • Measure Model Performance in R Using ROCR Package
  • Create a Confusion Matrix in R
  • Credit Risk Modelling – Case Study- Lending Club Data
  • Explore Loan Data in R – Loan Grade and Interest Rate
  • Credit Risk Modelling – Required R Packages
  • Loan Data – Training and Test Data Sets
  • Data Cleaning in R – Part 1
  • Data Cleaning in R – Part 2
  • Data Cleaning in R – Part 3
  • Data Cleaning in R – Part 5
  • Remove Dimensions By Fitting Logistic Regression
  • Create a Function and Prepare Test Data in R
  • Building Credit Risk Model
  • Credit Risk – Logistic Regression Model in R
  • Support Vector Machine (SVM) Model in R
  • Random Forest Model in R
  • Extreme Gradient Boosting in R
  • Predictive Modelling: Averaging Results from Multiple Models
  • Predictive Modelling: Comparing Model Results
  • How Insurance Companies Calculate Risk

Latest Tutorials

    • Data Visualization with R
    • Derivatives with R
    • Machine Learning in Finance Using Python
    • Credit Risk Modelling in R
    • Quantitative Trading Strategies in R
    • Financial Time Series Analysis in R
    • VaR Mapping
    • Option Valuation
    • Financial Reporting Standards
    • Fraud
Facebook Group

Membership

Unlock full access to Finance Train and see the entire library of member-only content and resources.

Subscribe

Footer

Recent Posts

  • How to Improve your Financial Health
  • CFA® Exam Overview and Guidelines (Updated for 2021)
  • Changing Themes (Look and Feel) in ggplot2 in R
  • Coordinates in ggplot2 in R
  • Facets for ggplot2 Charts in R (Faceting Layer)

Products

  • Level I Authority for CFA® Exam
  • CFA Level I Practice Questions
  • CFA Level I Mock Exam
  • Level II Question Bank for CFA® Exam
  • PRM Exam 1 Practice Question Bank
  • All Products

Quick Links

  • Privacy Policy
  • Contact Us

CFA Institute does not endorse, promote or warrant the accuracy or quality of Finance Train. CFA® and Chartered Financial Analyst® are registered trademarks owned by CFA Institute.

Copyright © 2021 Finance Train. All rights reserved.

  • About Us
  • Privacy Policy
  • Contact Us