Credit Default Swaps (CDS) and Credit Derivatives › Worked Example: Pricing a 5-Year CDS
Quantitative FinanceAll chapters Credit Default Swaps (CDS) and Credit Derivatives › Worked Example: Pricing a 5-Year CDSOne section · Sections in this chapter8 / 16 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Let's work through a complete example of pricing a CDS contract. We'll calculate the fair spread for a 5-year CDS with quarterly premium payments. This example will demonstrate how the theoretical framework translates into concrete calculations that can be implemented programmatically.
Setup
Assume the following parameters:
- Maturity: 5 years
- Premium payments: Quarterly
- Hazard rate: 2% per year (constant)
- Recovery rate: 40%
- Risk-free rate: 4% per year (flat term structure)
- Notional: \$10,000,000
import numpy as np
# CDS parameters
maturity_years = 5
payments_per_year = 4
hazard_rate = 0.02 # 2% annual default intensity
recovery_rate = 0.40
risk_free_rate = 0.04
notional = 10_000_000
# Generate payment times
num_payments = maturity_years * payments_per_year
payment_times = np.array(
[(i + 1) / payments_per_year for i in range(num_payments)]
)
delta_t = 1 / payments_per_year # Time between payments (0.25 years)Number of payment dates: 20 Payment times (years): [np.float64(0.25), np.float64(0.5), np.float64(0.75), np.float64(1.0)] ... [np.float64(4.25), np.float64(4.5), np.float64(4.75), np.float64(5.0)]
Calculate Survival and Discount Factors
# Survival probabilities at each payment date
survival_probs = np.exp(-hazard_rate * payment_times)
# Discount factors (continuous compounding)
discount_factors = np.exp(-risk_free_rate * payment_times)
# Default probabilities for each period
# Q(t_{i-1}) - Q(t_i) = probability of default in period i
survival_probs_prev = np.concatenate([[1.0], survival_probs[:-1]])
default_probs = survival_probs_prev - survival_probsSample survival and discount factors: ------------------------------------------------------------ Time Survival Q(t) Discount D(t) Default Prob ------------------------------------------------------------ 0.25 0.9950 0.9900 0.0050 1.00 0.9802 0.9608 0.0049 2.00 0.9608 0.9231 0.0048 3.00 0.9418 0.8869 0.0047 4.00 0.9231 0.8521 0.0046 5.00 0.9048 0.8187 0.0045

Calculate the Risky Annuity (Premium Leg Factor)
# Risky annuity: sum of delta_t * Q(t_i) * D(t_i)
risky_annuity = np.sum(delta_t * survival_probs * discount_factors)
pv_1bp = risky_annuity * notional / 10000Risky Annuity (RPV01): 4.287380 PV of 1 bp spread on Notional: $4287.38
The risky annuity (RPV01) indicates that for every \4.55. This factor accounts for both the time value of money and the probability that the entity survives to make payments. On the full notional, a 1 basis point spread is worth roughly \$4,546.
Calculate the Protection Leg Factor
# Protection leg factor: sum of D(t_i) * [Q(t_{i-1}) - Q(t_i)]
protection_leg_factor = np.sum(discount_factors * default_probs)Protection Leg Factor: 0.085962
The protection leg factor represents the present value of receiving \$1 contingent on default. It is calculated by summing the discounted probability of default for each period. This value (~0.057) is the cost of protection before adjusting for the recovery rate.
Calculate the Fair CDS Spread
# Fair spread calculation
loss_given_default = 1 - recovery_rate
fair_spread = (loss_given_default * protection_leg_factor) / risky_annuity
# Convert to basis points
fair_spread_bps = fair_spread * 10000
annual_premium = fair_spread * notional================================================== FAIR CDS SPREAD CALCULATION ================================================== Inputs: Hazard rate: 2.00% Recovery rate: 40.00% Risk-free rate: 4.00% Maturity: 5 years Results: Fair CDS spread: 120.30 basis points Annual premium: $120,300.50
The calculation results in a fair spread of approximately 75 basis points. This means the protection buyer must pay 0.75% of the notional annually to equate the expected premium payments with the expected default compensation.
Verify: Check Spread vs. Hazard Rate Approximation
Recall our earlier approximation: . Let's verify:
# Simple approximation
approx_spread = hazard_rate * (1 - recovery_rate)
approx_spread_bps = approx_spread * 10000
difference = abs(fair_spread_bps - approx_spread_bps)Exact fair spread: 120.30 bps Approximation (λ × LGD): 120.00 bps Difference: 0.30 bps
The approximation is quite accurate. The small difference arises from timing effects: the exact formula accounts for discounting and the precise timing of premium and protection payments.