The brief
A credit desk follows a company whose 5-year bond trades at a spread of 210 basis points over the risk-free rate. The bank's lending team wants to lend the same company $20 million for 4 years, repaid in instalments, and needs the loan's fair value.
The desk models default with a constant hazard rate . When the company defaults, a lender recovers 40% of what it is owed at that moment. Calibrate to the bond, then value the loan with it.
Your task
- Write
default_probability(hazard, t0, t1): the probability that the company defaults between timest0andt1, seen from time 0. RaiseValueErrorunlesshazardis at least 0 and . - Write
risky_value(schedule, r, hazard, recovery): the value today of a schedule of payments from the company, discounted at the continuous rater. RaiseValueErrorifhazardis negative orrecoveryis outside . - Write
hazard_from_spread(spread, schedule, r, recovery): the hazard rate at whichrisky_valueequals the bond's market price. RaiseValueErrorifspreadis negative, or if no hazard rate between 0 and 1 gives that price.
Each schedule entry (t, amount, exposure) is a payment of amount at time t, made only if the company has not defaulted by then. exposure is what the company owes between the previous payment time (or 0) and t. A default in that period pays recovery times exposure at once.
The market prices the bond by discounting each payment at the rate plus the spread :
The data
RATE is the risk-free rate, continuously compounded; SPREAD and RECOVERY are the bond's spread and the recovery rate. BOND is per 100 of face value. LOAN is in $ millions: $2.5 million of principal every six months, with interest at 6% a year on what is still owed.
Hint: Payments that need survival
Lesson 2.5.5 gives the chance of surviving to time as , and the default time's density as . A payment at is worth its amount times . The chance of default between and is the integral of the density between them (lesson 2.5.3).
Hint: The value of recovery
A default at time in period pays then, where is the recovery rate and the exposure. Weight each moment by the density and discount it: integrate from to . It is lesson 2.5.5's stream with a hazard rate, over one period.
Hint: Solving for the hazard rate
The value falls as rises, so a root lies between 0 and 1 when the price lies between the values there. Bisection or brentq finds it (lesson 1.3.2). As a check, should come out close to .