DefaultSwaption { public double price(final CDSAnalytic forwardStartingCDS, final ISDACompliantYieldCurve yieldCurve, final ISDACompliantCreditCurve creditCurve, final double strike, final double optionExpiry, final double vol, final boolean isPayer, final boolean hasFrontEndProt) { ArgumentChecker.isTrue(forwardStartingCDS.getEffectiveProtectionStart() >= optionExpiry, "Have not provided a forward CDS. The option expiry is {}, but the CDS(effective) protection start time is {}", optionExpiry, forwardStartingCDS.getEffectiveProtectionStart()); final double fep = isPayer && hasFrontEndProt ? forwardStartingCDS.getLGD() * yieldCurve.getDiscountFactor(optionExpiry) * (1 - creditCurve.getSurvivalProbability(optionExpiry)) : 0.0; final double annuity = _pricer.annuity(forwardStartingCDS, yieldCurve, creditCurve, PriceType.CLEAN, 0); final double protLeg = _pricer.protectionLeg(forwardStartingCDS, yieldCurve, creditCurve, 0); final double fwdSpread = protLeg / annuity; final double koVal = annuity * BlackFormulaRepository.price(fwdSpread, strike, optionExpiry, vol, isPayer); return koVal + fep; }  double price(final CDSAnalytic forwardStartingCDS, final ISDACompliantYieldCurve yieldCurve, final ISDACompliantCreditCurve creditCurve, final double strike, final double optionExpiry,
      final double vol, final boolean isPayer, final boolean hasFrontEndProt); double priceFlat(final CDSAnalytic cds, final ISDACompliantYieldCurve yieldCurve, final ISDACompliantCreditCurve creditCurve, final double strike, final double optionExpiry,
      final double vol, final boolean isPayer, final boolean hasFrontEndProt, final double coupon); double priceMod(final CDSAnalytic cds, final ISDACompliantYieldCurve yieldCurve, final ISDACompliantCreditCurve creditCurve, final double strike, final double optionExpiry, final double vol,
      final boolean isPayer, final boolean hasFrontEndProt, final double coupon); double impliedVol(final CDSAnalytic forwardStartingCDS, final ISDACompliantYieldCurve yieldCurve, final ISDACompliantCreditCurve creditCurve, final double strike, final double optionExpiry,
      final double price, final boolean isPayer, final boolean hasFrontEndProt);  }
@Test public void priceTest() { final DefaultSwaption ds = new DefaultSwaption(); final LocalDate tradeDate = LocalDate.of(2014, 2, 5); final LocalDate expiry = LocalDate.of(2014, 3, 20); final LocalDate maturity = LocalDate.of(2019, 6, 20); final double[] pillarParSpreads; final CDSAnalyticFactory factory = new CDSAnalyticFactory(); final Period[] pillarTenors = new Period[] {Period.ofMonths(6), Period.ofYears(1), Period.ofYears(2), Period.ofYears(3), Period.ofYears(4), Period.ofYears(5), Period.ofYears(7), Period.ofYears(10) }; final CDSAnalytic[] pillarCDS = factory.makeIMMCDS(tradeDate, pillarTenors); final double[] strikes = new double[] {100, 140, 150, 160, 170, 180, 182.767, 190, 200, 210, 220, 230, 250, 300 }; final double[] spreads = new double[] {57.43, 74.97, 111.32, 139.32, 157.64, 173.66, 209.28, 228.35 }; final int n = spreads.length; pillarParSpreads = new double[n]; for (int i = 0; i < n; i++) { pillarParSpreads[i] = spreads[i] * ONE_BP; } final double tEAlt = ACT_ACT_ISDA.getDayCountFraction(tradeDate, expiry); final CDSAnalytic fwdCDS = factory.makeCDS(tradeDate, expiry.plusDays(1), expiry.plusDays(1), expiry.plusDays(1), maturity); final ISDACompliantCreditCurve cc = CREDIT_CURVE_BUILDER.calibrateCreditCurve(pillarCDS, pillarParSpreads, YIELD_CURVE); final double expFwdProt = PRICER.protectionLeg(fwdCDS, YIELD_CURVE, cc, 0.0); final double expFwdAnnuity = PRICER.annuity(fwdCDS, YIELD_CURVE, cc, PriceType.CLEAN, 0.0); final double fwdSpread = expFwdProt / expFwdAnnuity; final double vol = 0.33; final int m = strikes.length; for (int i = 0; i < m; i++) { final double pRef = expFwdAnnuity * BlackFormulaRepository.price(fwdSpread, strikes[i] * ONE_BP, tEAlt, vol, true); final double p = ds.price(fwdCDS, YIELD_CURVE, cc, strikes[i] * ONE_BP, tEAlt, vol, true, false); assertEquals(pRef, p, 1.e-12); } }