AnalyticCDSPricer { public double pv(final CDSAnalytic cds, final ISDACompliantYieldCurve yieldCurve, final ISDACompliantCreditCurve creditCurve, final double fractionalSpread, final PriceType cleanOrDirty) { ArgumentChecker.notNull(cds, "cds"); if (cds.getProtectionEnd() <= 0.0) { return 0.0; } final double rpv01 = annuity(cds, yieldCurve, creditCurve, cleanOrDirty); final double proLeg = protectionLeg(cds, yieldCurve, creditCurve); return proLeg - fractionalSpread * rpv01; } AnalyticCDSPricer();  AnalyticCDSPricer(final AccrualOnDefaultFormulae formula); double pv(final CDSAnalytic cds, final ISDACompliantYieldCurve yieldCurve, final ISDACompliantCreditCurve creditCurve, final double fractionalSpread, final PriceType cleanOrDirty); double pv(final CDSAnalytic cds, final ISDACompliantYieldCurve yieldCurve, final ISDACompliantCreditCurve creditCurve, final double fractionalSpread, final PriceType cleanOrDirty,
      final double valuationTime); double pv(final CDSAnalytic cds, final ISDACompliantYieldCurve yieldCurve, final ISDACompliantCreditCurve creditCurve, final double fractionalSpread); double parSpread(final CDSAnalytic cds, final ISDACompliantYieldCurve yieldCurve, final ISDACompliantCreditCurve creditCurve); double protectionLeg(final CDSAnalytic cds, final ISDACompliantYieldCurve yieldCurve, final ISDACompliantCreditCurve creditCurve); double protectionLeg(final CDSAnalytic cds, final ISDACompliantYieldCurve yieldCurve, final ISDACompliantCreditCurve creditCurve, final double valuationTime); double dirtyAnnuity(final CDSAnalytic cds, final ISDACompliantYieldCurve yieldCurve, final ISDACompliantCreditCurve creditCurve); double annuity(final CDSAnalytic cds, final ISDACompliantYieldCurve yieldCurve, final ISDACompliantCreditCurve creditCurve); double annuity(final CDSAnalytic cds, final ISDACompliantYieldCurve yieldCurve, final ISDACompliantCreditCurve creditCurve, final PriceType cleanOrDirty); double annuity(final CDSAnalytic cds, final ISDACompliantYieldCurve yieldCurve, final ISDACompliantCreditCurve creditCurve, final PriceType cleanOrDirty, final double valuationTime); double pvCreditSensitivity(final CDSAnalytic cds, final ISDACompliantYieldCurve yieldCurve, final ISDACompliantCreditCurve creditCurve, final double fractionalSpread,
      final int creditCurveNode); double pvYieldSensitivity(final CDSAnalytic cds, final ISDACompliantYieldCurve yieldCurve, final ISDACompliantCreditCurve creditCurve, final double fractionalSpread, final int yieldCurveNode); double parSpreadCreditSensitivity(final CDSAnalytic cds, final ISDACompliantYieldCurve yieldCurve, final ISDACompliantCreditCurve creditCurve, final int creditCurveNode); double pvPremiumLegCreditSensitivity(final CDSAnalytic cds, final ISDACompliantYieldCurve yieldCurve, final ISDACompliantCreditCurve creditCurve, final int creditCurveNode); double pvPremiumLegYieldSensitivity(final CDSAnalytic cds, final ISDACompliantYieldCurve yieldCurve, final ISDACompliantCreditCurve creditCurve, final int yieldCurveNode); double protectionLegCreditSensitivity(final CDSAnalytic cds, final ISDACompliantYieldCurve yieldCurve, final ISDACompliantCreditCurve creditCurve, final int creditCurveNode); double protectionLegYieldSensitivity(final CDSAnalytic cds, final ISDACompliantYieldCurve yieldCurve, final ISDACompliantCreditCurve creditCurve, final int yieldCurveNode);  }
@SuppressWarnings("unused") @Test(enabled = false) public void timingTest() { final int warmup = 1000; final int benchmark = 10000; final double fracSpred = 0.01; final double[] ccTimes = new double[] {0.25, 0.5, 1.00000001, 2.0, 3.0, 5.0, 7.2, 10.0, 20.0 }; final double[] ccRates = new double[] {0.05, 0.06, 0.07, 0.05, 0.09, 0.09, 0.07, 0.065, 0.06 }; final double[] ycTimes = new double[] {1 / 52., 1 / 12., 1 / 4., 1 / 2., 3 / 4., 1.0, 2.1, 5.2, 11.0, 30.0 }; final double[] ycRates = new double[] {0.005, 0.006, 0.007, 0.01, 0.01, 0.015, 0.02, 0.03, 0.04, 0.05 }; final ISDACompliantCreditCurve creditCurve = new ISDACompliantCreditCurve(ccTimes, ccRates); final ISDACompliantYieldCurve yieldCurve = new ISDACompliantYieldCurve(ycTimes, ycRates); final LocalDate today = LocalDate.of(2013, 7, 2); final LocalDate stepin = today.plusDays(1); final LocalDate valueDate = today.plusDays(3); final LocalDate startDate = today.plusMonths(1); final LocalDate endDate1 = LocalDate.of(2018, 6, 20); final LocalDate endDate2 = LocalDate.of(2023, 6, 20); final CDSAnalytic cds1 = new CDSAnalytic(today, stepin, valueDate, startDate, endDate1, true, Period.ofMonths(3), StubType.FRONTSHORT, false, 0.4); final CDSAnalytic cds2 = new CDSAnalytic(today, stepin, valueDate, startDate, endDate2, true, Period.ofMonths(3), StubType.FRONTSHORT, false, 0.4); for (int i = 0; i < warmup; i++) { final double p1 = PRICER.pv(cds1, yieldCurve, creditCurve, fracSpred); final double p2 = PRICER.pv(cds2, yieldCurve, creditCurve, fracSpred); } long timer = System.nanoTime(); double p1 = 0; for (int i = 0; i < benchmark; i++) { p1 += PRICER.pv(cds1, yieldCurve, creditCurve, fracSpred); } System.out.println(p1); double time = (System.nanoTime() - timer) / 1e6; System.out.println("time for " + benchmark + " 5 year CDS: " + time + "ms"); timer = System.nanoTime(); double p2 = 0; for (int i = 0; i < benchmark; i++) { p2 += PRICER.pv(cds2, yieldCurve, creditCurve, fracSpred); } System.out.println(p2); time = (System.nanoTime() - timer) / 1e6; System.out.println("time for " + benchmark + " 10 year CDS: " + time + "ms"); for (int i = 0; i < warmup; i++) { final CDSAnalytic cds1temp = new CDSAnalytic(today, stepin, valueDate, startDate, endDate1, true, Period.ofMonths(3), StubType.FRONTSHORT, false, 0.4); final CDSAnalytic cds2temp = new CDSAnalytic(today, stepin, valueDate, startDate, endDate2, true, Period.ofMonths(3), StubType.FRONTSHORT, false, 0.4); } timer = System.nanoTime(); double p3 = 0; for (int i = 0; i < benchmark; i++) { final CDSAnalytic cds = new CDSAnalytic(today, stepin, valueDate, startDate, endDate1, true, Period.ofMonths(3), StubType.FRONTSHORT, false, 0.4); p3 += PRICER.pv(cds, yieldCurve, creditCurve, fracSpred); } System.out.println(p3); time = (System.nanoTime() - timer) / 1e6; System.out.println("time for " + benchmark + " 5 year CDS with date logic: " + time + "ms"); timer = System.nanoTime(); double p4 = 0; for (int i = 0; i < benchmark; i++) { final CDSAnalytic cds = new CDSAnalytic(today, stepin, valueDate, startDate, endDate2, true, Period.ofMonths(3), StubType.FRONTSHORT, false, 0.4); p4 += PRICER.pv(cds, yieldCurve, creditCurve, fracSpred); } System.out.println(p3); time = (System.nanoTime() - timer) / 1e6; System.out.println("time for " + benchmark + " 10 year CDS with date logic: " + time + "ms"); }