From 78cb7b1c80053d7858892571700342b523a22815 Mon Sep 17 00:00:00 2001 From: Anish Pentyala Date: Thu, 26 Nov 2026 23:55:50 -0800 Subject: [PATCH 1/2] Use each issuer curve's recovery in CDS index portfolio spreads --- financepy/products/credit/cds_index_portfolio.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/financepy/products/credit/cds_index_portfolio.py b/financepy/products/credit/cds_index_portfolio.py index 67183315..21a336a5 100644 --- a/financepy/products/credit/cds_index_portfolio.py +++ b/financepy/products/credit/cds_index_portfolio.py @@ -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 @@ -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 @@ -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 @@ -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 From 524ef02be311c159548096086735ed930cb1275a Mon Sep 17 00:00:00 2001 From: Anish Pentyala Date: Thu, 26 Nov 2026 23:58:41 -0800 Subject: [PATCH 2/2] Test CDS index portfolio statistics with non-default recovery --- tests/unit/test_cds_index_portfolio.py | 43 ++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/tests/unit/test_cds_index_portfolio.py b/tests/unit/test_cds_index_portfolio.py index 9d8567d8..4f445927 100644 --- a/tests/unit/test_cds_index_portfolio.py +++ b/tests/unit/test_cds_index_portfolio.py @@ -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