核貸策略與最小化預期損失

以 Python 進行信用風險建模

Michael Crabtree

Data Scientist, Ford Motor Company

選擇核准率

  • 初始核准率設為 85%,也可選其他比率。
  • 測試不同比率有兩種方式:
    • 手動計算臨界值、壞帳率與損失
    • 自動建立上述數值的表格並選擇核准率
  • 所有可能數值的表格稱為策略表(strategy table)
以 Python 進行信用風險建模

建立策略表的準備

  • 設定陣列或清單以儲存各項數值
# Set all the acceptance rates to test
accept_rates = [1.0, 0.95, 0.9, 0.85, 0.8, 0.75, 0.7, 0.65, 0.6, 0.55,
                0.5, 0.45, 0.4, 0.35, 0.3, 0.25, 0.2, 0.15, 0.1, 0.05]
# Create lists to store thresholds and bad rates 
thresholds = []
bad_rates = []
以 Python 進行信用風險建模

計算表格數值

  • 為所有核准率計算臨界值與壞帳率
for rate in accept_rates:
    # Calculate threshold
    threshold = np.quantile(preds_df['prob_default'], rate).round(3)
    # Store threshold value in a list
    thresholds.append(np.quantile(preds_gbt['prob_default'], rate).round(3))
    # Apply the threshold to reassign loan_status
    test_pred_df['pred_loan_status'] = \ 
        test_pred_df['prob_default'].apply(lambda x: 1 if x > thresh else 0)
    # Create accepted loans set of predicted non-defaults
    accepted_loans = test_pred_df[test_pred_df['pred_loan_status'] == 0]
    # Calculate and store bad rate
    bad_rates.append(np.sum((accepted_loans['true_loan_status']) 
             / accepted_loans['true_loan_status'].count()).round(3))
以 Python 進行信用風險建模

解讀策略表

strat_df = pd.DataFrame(zip(accept_rates, thresholds, bad_rates),
                        columns = ['Acceptance Rate','Threshold','Bad Rate'])

策略表與壞帳率長條圖示例

以 Python 進行信用風險建模

加入核准件數

  • 各核准率下的核准件數
    • 可用 len().count()

含核准件數的策略表

以 Python 進行信用風險建模

加入平均貸款金額

  • 測試集資料中的 loan_amnt 平均值

含平均貸款金額的策略表

以 Python 進行信用風險建模

估計投資組合價值

  • 核准且未違約的平均價值減去核准且違約的平均價值
  • 假設每筆違約的損失等於 loan_amnt

含估計投組價值的策略表

以 Python 進行信用風險建模

總預期損失

  • 預期在投組違約部分會損失多少

總預期損失公式

# Probability of default (PD)
test_pred_df['prob_default']
# Exposure at default = loan amount (EAD)
test_pred_df['loan_amnt']
# Loss given default = 1.0 for total loss (LGD)
test_pred_df['loss_given_default']
以 Python 進行信用風險建模

一起來練習吧!

以 Python 進行信用風險建模

Preparing Video For Download...