Distributions: Exercises


4. Bond Default. You hold a portfolio of 100 bonds and each has a default probability of 0.05. In this exercise, you will model default using a binomial distribution.

The binomial distribution can be used to determine the probability that some number of loans default. To calculate this probability in R, use the dbinom(k, n, p), where n is the number of bonds, k is the number of defaults, and p is the default probability for a single bond.

Calculate the probability that 3 bonds default.


# Define the number of bonds. n <- ___ # Define the number of defaults. k <- ___ # Define the default probability. p <- ___ # Compute the probability of k defaults. result <- dbinom(___, ___, ___) # Print the result. result # Define the number of bonds. n <- 100 # Define the number of defaults. k <- 3 # Define the default probability. p <- 0.05 # Compute the probability of k defaults. result <- dbinom(k, n, p) # Print the result. result test_error() test_object("n", incorrect_msg="Check the number of bonds.") test_object("k", incorrect_msg="Check the number of defaults.") test_object("p", incorrect_msg="Check the default probability.") success_msg("Great job!")
Remember to use dbinom(n, k, p).

Previous Exercise Next Exercise