Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions financepy/products/credit/cds_index_portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def average_spread(self, value_dt: Date, step_in_dt: Date, maturity_dt: Date, is
average_spd = 0.0

for m in range(0, num_credits):
spd = cds_contract.par_spread(value_dt, issuer_curves[m])
spd = cds_contract.par_spread(value_dt, issuer_curves[m], issuer_curves[m].recovery_rate)
average_spd += spd

average_spd /= num_credits
Expand All @@ -142,7 +142,7 @@ def total_spread(self, value_dt: Date, step_in_dt: Date, maturity_dt: Date, issu
total_spd = 0.0

for m in range(0, num_credits):
spd = cds_contract.par_spread(value_dt, issuer_curves[m])
spd = cds_contract.par_spread(value_dt, issuer_curves[m], issuer_curves[m].recovery_rate)
total_spd += spd

return total_spd
Expand All @@ -162,10 +162,10 @@ def min_spread(self, value_dt: Date, step_in_dt: Date, maturity_dt: Date, issuer

cds_contract = CDS(step_in_dt, maturity_dt, 0.0)

min_spd = cds_contract.par_spread(value_dt, issuer_curves[0])
min_spd = cds_contract.par_spread(value_dt, issuer_curves[0], issuer_curves[0].recovery_rate)

for m in range(1, num_credits):
spd = cds_contract.par_spread(value_dt, issuer_curves[m])
spd = cds_contract.par_spread(value_dt, issuer_curves[m], issuer_curves[m].recovery_rate)
if spd < min_spd:
min_spd = spd

Expand All @@ -186,10 +186,10 @@ def max_spread(self, value_dt: Date, step_in_dt: Date, maturity_dt: Date, issuer

cds_contract = CDS(step_in_dt, maturity_dt, 0.0)

max_spd = cds_contract.par_spread(value_dt, issuer_curves[0])
max_spd = cds_contract.par_spread(value_dt, issuer_curves[0], issuer_curves[0].recovery_rate)

for m in range(1, num_credits):
spd = cds_contract.par_spread(value_dt, issuer_curves[m])
spd = cds_contract.par_spread(value_dt, issuer_curves[m], issuer_curves[m].recovery_rate)
if spd > max_spd:
max_spd = spd

Expand Down
43 changes: 43 additions & 0 deletions tests/unit/test_cds_index_portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,46 @@ def test_cds_index_portfolio():
assert round(intrinsic_spd_5yr, 3) == 35.538
assert round(intrinsic_spd_7yr, 3) == 49.009
assert round(intrinsic_spd_10yr, 3) == 61.409


def test_cds_index_portfolio_spreads_use_curve_recovery():

# The par spread of a CDS on a curve calibrated from a quote at that CDS's
# maturity must reproduce the quote. When the curve is calibrated with a
# recovery rate other than the 40% par_spread default, the index portfolio
# spread statistics must still use the curve's own recovery rate.
trade_dt = Date(1, 8, 2007)
step_in_dt = trade_dt.add_days(1)
value_dt = step_in_dt

libor_curve = build_ibor_curve(trade_dt)
maturity_5yr = trade_dt.next_cds_date(60)

quote = 100.0 / 10000.0
recovery_rate = 0.30

cds_5yr = CDS(step_in_dt, maturity_5yr, quote)
issuer_curve = CDSCurve(
value_dt, [cds_5yr], libor_curve, recovery_rate
)
issuer_curves = [issuer_curve, issuer_curve, issuer_curve]

cds_index = CDSIndexPortfolio()

avg_spd = cds_index.average_spread(
value_dt, step_in_dt, maturity_5yr, issuer_curves
)
total_spd = cds_index.total_spread(
value_dt, step_in_dt, maturity_5yr, issuer_curves
)
min_spd = cds_index.min_spread(
value_dt, step_in_dt, maturity_5yr, issuer_curves
)
max_spd = cds_index.max_spread(
value_dt, step_in_dt, maturity_5yr, issuer_curves
)

assert round(avg_spd * 10000.0, 4) == 100.0
assert round(total_spd * 10000.0, 4) == 300.0
assert round(min_spd * 10000.0, 4) == 100.0
assert round(max_spd * 10000.0, 4) == 100.0