Skip to content

Commit

Permalink
Added Test Case to cover market quoted spread curve instead of single…
Browse files Browse the repository at this point in the history
… spread data point
  • Loading branch information
bleunguts committed May 1, 2024
1 parent cf12820 commit 865d08b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
35 changes: 33 additions & 2 deletions ProjectX.AnalyticsLib.Tests/CreditDefaultSwapFunctionsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ namespace ProjectX.AnalyticsLib.Tests;
public class CreditDefaultSwapFunctionsTest
{
[Test]
public void WhenValuingCdsPVUsingFlatInterestCurveItShouldReturnValidPV()
public void WhenValuingCdsPVItShouldReturnValidPVAndProbabilities()
{
var evalDate = new DateTime(2009, 6, 15);
var effectiveDate = new DateTime(2009, 3, 20);
var maturityDate = new DateTime(2014, 6, 20);
var spreadsInBps = new int[] { 210 };
var spreadsInBps = new double[] { 210.0 };
var tenors = new string[] { "5Y" };
var recoveryRate = 0.4;
var couponInBps = 100;
Expand All @@ -39,4 +39,35 @@ public void WhenValuingCdsPVUsingFlatInterestCurveItShouldReturnValidPV()
Assert.That(actual.PV, Is.EqualTo(471).Within(1), "PV must be equal to expected value within tolerance");
Assert.That(actual.FairSpread, Is.EqualTo(218).Within(1), "Fair spread must be equal to expected value within tolerance");
}

[Test]
public void WhenValuingCdsPVWithMultipleSpreadPointsItShouldReturnValidPVAndProbabilities()
{
var evalDate = new DateTime(2015, 5, 15);
var effectiveDate = new DateTime(2015, 3, 20);
var maturityDate = new DateTime(2018, 6, 20);
var spreadsInBps = new double[] { 34.93, 53.6, 72.02, 106.39, 129.39, 139.46 };
var tenors = new string[] { "1Y","2Y","3Y","5Y","7Y","10Y" };
var recoveryRate = 0.4;
var couponInBps = 100;
var notional = 10_000;
Protection.Side protectionSide = Protection.Side.Buyer;
var interestRate = 0.07;
var actual = CreditDefaultSwapFunctions.PV(
evalDate,
effectiveDate,
maturityDate,
spreadsInBps,
tenors,
recoveryRate,
couponInBps,
notional,
protectionSide,
interestRate);
Assert.That(actual.SurvivalProbabilityPercentage, Is.EqualTo(96.3).Within(1));
Assert.That(actual.DefaultProbabilityPercentage, Is.EqualTo(3.6).Within(1));
Assert.That(actual.HazardRatePercentage, Is.EqualTo(1.8).Within(1));
Assert.That(actual.PV, Is.EqualTo(-137).Within(1), "PV must be equal to expected value within tolerance");
Assert.That(actual.FairSpread, Is.EqualTo(51.3).Within(1), "Fair spread must be equal to expected value within tolerance");
}
}
5 changes: 4 additions & 1 deletion ProjectX.AnalyticsLib/CreditDefaultSwapFunctions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ namespace ProjectX.AnalyticsLib;

public class CreditDefaultSwapFunctions
{
/// <summary>
/// Uses Flat Interest Rate Curve - instead of PiecewiseLogCubic ISDA rate curves
/// </summary>
public static CreditDefaultSwapPVResult PV(
DateTime evaluationDate,
DateTime effectiveDate,
DateTime maturityDate,
int[] spreadsInBps,
double[] spreadsInBps,
string[] tenors,
double recoveryRate,
int couponInBps,
Expand Down

0 comments on commit 865d08b

Please sign in to comment.