Get startedGet started for free

Total expected loss

It's time to estimate the total expected loss given all your decisions. The data frame test_pred_df has the probability of default for each loan and that loan's value. Use these two values to calculate the expected loss for each loan. Then, you can sum those values and get the total expected loss.

For this exercise, you will assume that the exposure is the full value of the loan, and the loss given default is 100%. This means that a default on each the loan is a loss of the entire amount.

The data frame test_pred_df has been loaded into the workspace.

This exercise is part of the course

Credit Risk Modeling in Python

View Course

Exercise instructions

  • Print the top five rows of test_pred_df.
  • Create a new column expected_loss for each loan by using the formula above.
  • Calculate the total expected loss of the entire portfolio, rounded to two decimal places, and store it as tot_exp_loss.
  • Print the total expected loss.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# 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(____))
Edit and Run Code