Exercise

# Exercise 2. Bank earnings Monte Carlo

Run a Monte Carlo simulation with 10,000 outcomes for \(S\), the sum of losses over 10,000 loans. Make a histogram of the results.

Instructions

**100 XP**

- Within a
`replicate`

loop with 10,000 iterations, use`sample`

to generate a list of 10,000 loan outcomes: payment (0) or default (1). Use the outcome order`c(0,1)`

and probability of default`p_default`

. - Still within the loop, use the function
`sum`

to count the number of foreclosures multiplied by`loss_per_foreclosure`

to return the sum of all losses across the 10,000 loans.*If you do not take the*`sum`

inside the`replicate`

loop, DataCamp may crash with a "Session Expired" error. - Plot the histogram of values using the function
`hist`

.