開始使用免費開始

總期望損失

現在要根據你先前的所有決策,來估計總期望損失。資料框 test_pred_df 包含每筆貸款的違約機率,以及該筆貸款的金額。請用這兩個數值計算每筆貸款的期望損失。接著將這些值加總,得到總期望損失。

在這個練習中,你可以假設曝險金額等於貸款的全額,且違約損失率為 100%。也就是說,只要違約,就會損失整筆金額。

資料框 test_pred_df 已載入至工作區。

本練習屬於課程

以 Python 進行信用風險建模

檢視課程

練習說明

  • 列印 test_pred_df 的前 5 列。
  • 依上方公式,為每筆貸款建立新欄位 expected_loss
  • 計算整個投資組合的總期望損失,四捨五入到小數點後兩位,並存成 tot_exp_loss
  • 列印總期望損失。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Print the first five rows of the data frame
print(____.head())

# Calculate the bank's expected loss and assign it to a new column
____[____] = ____[____] * ____[____] * ____[____]

# Calculate the total expected loss to two decimal places
____ = round(np.____(____[____]),2)

# Print the total expected loss
print('Total expected loss: ', '${:,.2f}'.format(____))
編輯並執行程式碼