Interview Query
~3 hrs
AnalyticsMachine LearningData Viz & InterpretationStatisticsFixed-Income & Risk Management

BusinessOptics Data Scientist: Probabilistic Loan Default Model

Fit a probability of default model to historical credit data in Python, evaluate it on a hold-out set, then use it to estimate the expected value of a live loan book.

Business opticsBusiness optics
Data Scientist
Updated 7 days agoReviewed byIQIQ Team

Overview

This is a pre-interview task for the position of data scientist at BusinessOptics.

The goal is to fit a statistical model to historical credit data and then use the model to estimate the value of current loans. The task is broken up into five steps explained in detail below.

This is a relatively straightforward task and should not take you too long to complete. Complete the task using a Python notebook and commonly-used data science libraries. Demonstrate familiarity with core concepts in data science and that you can use the relevant technologies (or online resources) to solve the task. Within these parameters there are many ways to solve the task. If necessary, you may make (and note) assumptions about the data and the interpretation of the task.


Step 1: Set Up Your Environment

If you do not already have Anaconda, download and install it (https://www.continuum.io/downloads). Launch a Jupyter Notebook (either from Anaconda Navigator or from the terminal/command prompt with the command jupyter notebook). Create a new notebook which you will use for this task. You can add any notes and assumptions to the notebook.


Step 2: Load the Data and Explore Relationships

Load the supplied comma-separated data file data_science_task.csv using the pandas read_csv function:
https://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html

Each row in the dataset represents a loan with the following fields:

FieldDescription
account_noA unique account number per loan
genderGender of the account holder: either 'M' or 'F'
ageAge of the account holder at the point of application
incomeMonthly nett income of the account holder at the point of application
loan_amountThe amount of money lent
termThe number of months the loan is to be repaid over
installment_amountThe monthly installment amount
interest_rateThe interest rate on the loan
credit_score_at_applicationCredit score at the point of application: a positive integer less than 1000; higher scores indicate greater creditworthiness
outstanding_balanceThe remaining amount of the loan that still has to be repaid
statusThe state of the account: one of three values (see below)

Status values:

  • LIVE: The loan is still being repaid; outstanding_balance will be greater than zero.
  • PAID_UP: The loan has been completely repaid; outstanding_balance will be zero.
  • DEFAULT: The loan was not fully repaid and no further payments can be expected; outstanding_balance will be greater than zero and the amount will not be recoverable.

In order to get a sense of the distribution of the fields and the relationships between them, make some plots using the pandas DataFrame plot function:
https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.plot.html

An example plot could be a histogram of a particular field or a scatter plot indicating the relationship between variables. Don't spend too long on these plots: they needn't be beautiful nor exhaustive. The goal is simply to demonstrate that you can visualise relationships in the dataset.


Step 3: Fit a Probabilistic Classification Model

Separate the data into two datasets: a current dataset and a historical dataset: using the status field:

  • Historical data: rows with status equal to "PAID_UP" or "DEFAULT"
  • Current data: rows with status equal to "LIVE"

Using a probabilistic classification algorithm of your choice from scikit-learn (http://scikit-learn.org/), fit a probability of default model to the historical data.

In order to evaluate the model (Step 4), you will need to create a backtesting or hold-out set that is not used to fit the model. You can do this using scikit-learn's model_selection package or your own method.

You will need to decide how to encode categorical fields in the data: you can use pandas get_dummies or the label and one-hot encoders from scikit-learn.

Important: Do not use the outstanding_balance field as a predictor. This field is by definition perfectly correlated with the default variable you are trying to predict.


Step 4: Evaluate Your Model

Choose a suitable evaluation metric from scikit-learn's metrics package. Use your fitted model to predict the probabilities of default for the hold-out test dataset, then use scikit-learn to calculate the chosen metric based on the actual test set outcomes and the predicted test set outcomes.


Step 5: Forecast the Expected Value of the Loan Book

Use your fitted model to predict the probability of default for each loan in the current (LIVE) dataset.

Use these probabilities to calculate the expected repayment amount for each loan:

expected_repayment = (1 - probability_of_default) × outstanding_balance

You may disregard any impact of the time value of money in this calculation.

Sum all the expected repayment amounts to find the total expected value of the book.

You can verify that this total repayment amount roughly reflects the average default rate observed in the historical data by computing the ratio of the expected value to the sum of the outstanding_balance and comparing it to the proportion of "PAID_UP" to "DEFAULT" accounts in the historical dataset.


Deliverable

Submit a single PDF file containing your complete solution. The PDF must include:

  • All code (which must be executable and capable of regenerating every result, chart, and table)
  • All plots and exploratory visualisations from Step 2
  • Your fitted model and evaluation metric results from Steps 3 and 4
  • The expected value calculation and total expected value of the loan book from Step 5
  • Any notes or assumptions you made during the task
Download project files