@Test
 /** Test the present value. */
 public void presentValueExplicit() {
   final MultipleCurrencyAmount pv = METHOD_HW.presentValue(SWAPTION_LONG_PAYER, HW_MULTICURVES);
   final double timeToExpiry = SWAPTION_LONG_PAYER.getTimeToExpiry();
   final AnnuityPaymentFixed cfe =
       CFEC.visitSwap(SWAPTION_LONG_PAYER.getUnderlyingSwap(), MULTICURVES);
   final int numberOfPayments = cfe.getNumberOfPayments();
   final double alpha[] = new double[numberOfPayments];
   final double disccf[] = new double[numberOfPayments];
   for (int loopcf = 0; loopcf < numberOfPayments; loopcf++) {
     alpha[loopcf] =
         MODEL.alpha(
             HW_PARAMETERS,
             0.0,
             timeToExpiry,
             timeToExpiry,
             cfe.getNthPayment(loopcf).getPaymentTime());
     disccf[loopcf] =
         MULTICURVES.getDiscountFactor(EUR, cfe.getNthPayment(loopcf).getPaymentTime())
             * cfe.getNthPayment(loopcf).getAmount();
   }
   final double kappa = MODEL.kappa(disccf, alpha);
   double pvExpected = 0.0;
   for (int loopcf = 0; loopcf < numberOfPayments; loopcf++) {
     pvExpected += disccf[loopcf] * NORMAL.getCDF(-kappa - alpha[loopcf]);
   }
   assertEquals(
       "Swaption physical - Hull-White - present value", pvExpected, pv.getAmount(EUR), 1E-2);
   final MultipleCurrencyAmount pv2 =
       METHOD_HW.presentValue(SWAPTION_LONG_PAYER, cfe, HW_MULTICURVES);
   assertEquals("Swaption physical - Hull-White - present value", pv, pv2);
 }
 @Test(enabled = true)
 /**
  * Tests to estimate the impact of mu on the CMS coupon pricing. "enabled = false" for the
  * standard testing.
  */
 public void testPriceMultiMu() {
   final double[] mu = new double[] {1.10, 1.30, 1.55, 2.25, 3.50, 6.00, 15.0};
   final int nbMu = mu.length;
   final double priceCouponStd =
       METHOD_STANDARD_CPN.presentValue(CMS_COUPON, SABR_MULTICURVES).getAmount(EUR);
   @SuppressWarnings("unused")
   final double rateCouponStd =
       priceCouponStd
           / (CMS_COUPON.getPaymentYearFraction()
               * CMS_COUPON.getNotional()
               * MULTICURVES.getDiscountFactor(EUR, CMS_COUPON.getPaymentTime()));
   final double[] priceCouponExtra = new double[nbMu];
   final double[] rateCouponExtra = new double[nbMu];
   for (int loopmu = 0; loopmu < nbMu; loopmu++) {
     final CouponCMSSABRExtrapolationRightReplicationMethod methodExtrapolation =
         new CouponCMSSABRExtrapolationRightReplicationMethod(CUT_OFF_STRIKE, mu[loopmu]);
     priceCouponExtra[loopmu] =
         methodExtrapolation.presentValue(CMS_COUPON, SABR_MULTICURVES).getAmount(EUR);
     rateCouponExtra[loopmu] =
         priceCouponExtra[loopmu]
             / (CMS_COUPON.getPaymentYearFraction()
                 * CMS_COUPON.getNotional()
                 * MULTICURVES.getDiscountFactor(EUR, CMS_COUPON.getPaymentTime()));
   }
   final double priceCouponNoAdj =
       METHOD_DSC_CPN.presentValue(CMS_COUPON, MULTICURVES).getAmount(EUR);
   final double rateCouponNoAdj =
       priceCouponNoAdj
           / (CMS_COUPON.getPaymentYearFraction()
               * CMS_COUPON.getNotional()
               * MULTICURVES.getDiscountFactor(EUR, CMS_COUPON.getPaymentTime()));
   for (int loopmu = 1; loopmu < nbMu; loopmu++) {
     assertTrue(
         "Extrapolation: comparison with standard method",
         rateCouponExtra[loopmu - 1] > rateCouponExtra[loopmu]);
   }
   assertTrue(
       "Extrapolation: comparison with standard method",
       rateCouponExtra[nbMu - 1] > rateCouponNoAdj);
 }
 /**
  * Test the present value for a CMS coupon with pricing by replication in the SABR with
  * extrapolation framework. The present value is tested against hard-coded value and cap of strike
  * 0.
  */
 public void presentValue() {
   // CMS cap/floor with strike 0 has the same price as a CMS coupon.
   final double priceCouponStd =
       METHOD_STANDARD_CPN.presentValue(CMS_COUPON, SABR_MULTICURVES).getAmount(EUR).getAmount();
   final double rateCouponStd =
       priceCouponStd
           / (CMS_COUPON.getPaymentYearFraction()
               * CMS_COUPON.getNotional()
               * MULTICURVES.getDiscountFactor(EUR, CMS_COUPON.getPaymentTime()));
   final double priceCouponExtra =
       METHOD_EXTRAPOLATION_CPN
           .presentValue(CMS_COUPON, SABR_MULTICURVES)
           .getAmount(EUR)
           .getAmount();
   final double rateCouponExtra =
       priceCouponExtra
           / (CMS_COUPON.getPaymentYearFraction()
               * CMS_COUPON.getNotional()
               * MULTICURVES.getDiscountFactor(EUR, CMS_COUPON.getPaymentTime()));
   final double priceCouponNoAdj =
       METHOD_DSC_CPN.presentValue(CMS_COUPON, MULTICURVES).getAmount(EUR).getAmount();
   final double rateCouponNoAdj =
       priceCouponNoAdj
           / (CMS_COUPON.getPaymentYearFraction()
               * CMS_COUPON.getNotional()
               * MULTICURVES.getDiscountFactor(EUR, CMS_COUPON.getPaymentTime()));
   assertEquals(
       "Extrapolation: comparison with standard method", rateCouponStd > rateCouponExtra, true);
   assertEquals(
       "Extrapolation: comparison with no convexity adjustment",
       rateCouponExtra > rateCouponNoAdj,
       true);
   final double rateCouponExtraExpected = 0.0189864; // From previous run.
   assertEquals("Extrapolation: hard-coded value", rateCouponExtraExpected, rateCouponExtra, 1E-6);
   final double priceCap0Extra =
       METHOD_EXTRAPOLATION_CAP
           .presentValue(CMS_CAP_0, SABR_MULTICURVES)
           .getAmount(EUR)
           .getAmount();
   assertEquals(
       "Extrapolation: CMS coupon vs Cap 0", priceCouponExtra, priceCap0Extra, TOLERANCE_PV);
 }
 @Test
 public void presentValueMarketDiscount() {
   final MultipleCurrencyAmount pvComputed = METHOD_CPN_IBOR.presentValue(CPN_IBOR, MULTICURVES);
   final double forward =
       MULTICURVES.getForwardRate(
           EURIBOR3M,
           CPN_IBOR.getFixingPeriodStartTime(),
           CPN_IBOR.getFixingPeriodEndTime(),
           CPN_IBOR.getFixingAccrualFactor());
   final double df =
       MULTICURVES.getDiscountFactor(EURIBOR3M.getCurrency(), CPN_IBOR.getPaymentTime());
   final double pvExpected = NOTIONAL * ACCRUAL_FACTOR * forward * df;
   assertEquals(
       "CouponIborDiscountingMarketMethod: present value",
       pvExpected,
       pvComputed.getAmount(EURIBOR3M.getCurrency()),
       TOLERANCE_PV);
 }