Single Probablity of Default Example
Overview
The homogenous credit model assumes that all loans in the porfolio have the same
probability of default.
This is a simplification which can be useful in the following situations:
- The bank does not have any way to differentiate between the risk of different loans
- The bank has limited data
- The analyst seeks a quick ballpark estimation of the credit risk.
Sample Dataset
This example utilizes a randomly generated dataset. The script to generate the dataset is provided as sample.py.
The generate method returns a of loans, and a list of monthly snapshops fof those loans.
import lib.homogenous_credit.sample as sp
# generate a sample dataset
loans,snapshots = sp.generate()
Note that in this example, we use a dataset that assigns a grade to each loan, which presumably is a measure of the loans
credit worthiness. However, the homogenous model will ignore this
Mapping
Once a datset has been optained, the data needs to be mapped to the LoanSnapshot pydantic data class.
The loan snapshots will be inputs to the estimation library.
'''
create dataset with the required fields
'''
data = [
dt.LoanSnapshot(default = x['default'], date=x['date'], account=x['id'])
for x in snapshots
]
Calculating the Default Statistics
The homogenous estimate libary provides a function to estimate the
probability of default
and the
joint probability of default.
import lib.credit.homogenous as est
pd = est.estimate(data)
jrate = est.joint_rate(data)
print('pd is '+str(pd))
print('jrate is '+str(jrate))
Sample