@Test
 /** Tests the Hull-White parameters sensitivity. */
 public void hullWhiteSensitivity() {
   double[] hwSensitivity =
       METHOD_HW_APPROXIMATION.presentValueHullWhiteSensitivity(SWAPTION_PAYER_LONG, BUNDLE_HW);
   int nbVolatility = PARAMETERS_HW.getVolatility().length;
   double shiftVol = 1.0E-6;
   double[] volatilityBumped = new double[nbVolatility];
   System.arraycopy(PARAMETERS_HW.getVolatility(), 0, volatilityBumped, 0, nbVolatility);
   double[] volatilityTime = new double[nbVolatility - 1];
   System.arraycopy(PARAMETERS_HW.getVolatilityTime(), 1, volatilityTime, 0, nbVolatility - 1);
   double[] pvBumpedPlus = new double[nbVolatility];
   double[] pvBumpedMinus = new double[nbVolatility];
   HullWhiteOneFactorPiecewiseConstantParameters parametersBumped =
       new HullWhiteOneFactorPiecewiseConstantParameters(
           PARAMETERS_HW.getMeanReversion(), volatilityBumped, volatilityTime);
   HullWhiteOneFactorPiecewiseConstantDataBundle bundleBumped =
       new HullWhiteOneFactorPiecewiseConstantDataBundle(parametersBumped, CURVES);
   double[] hwSensitivityExpected = new double[nbVolatility];
   for (int loopvol = 0; loopvol < nbVolatility; loopvol++) {
     volatilityBumped[loopvol] += shiftVol;
     parametersBumped.setVolatility(volatilityBumped);
     pvBumpedPlus[loopvol] =
         METHOD_HW_APPROXIMATION.presentValue(SWAPTION_PAYER_LONG, bundleBumped).getAmount();
     volatilityBumped[loopvol] -= 2 * shiftVol;
     parametersBumped.setVolatility(volatilityBumped);
     pvBumpedMinus[loopvol] =
         METHOD_HW_APPROXIMATION.presentValue(SWAPTION_PAYER_LONG, bundleBumped).getAmount();
     hwSensitivityExpected[loopvol] =
         (pvBumpedPlus[loopvol] - pvBumpedMinus[loopvol]) / (2 * shiftVol);
     assertEquals(
         "Swaption - Hull-White sensitivity adjoint: derivative "
             + loopvol
             + " - difference:"
             + (hwSensitivityExpected[loopvol] - hwSensitivity[loopvol]),
         hwSensitivityExpected[loopvol],
         hwSensitivity[loopvol],
         2.0E+5);
     volatilityBumped[loopvol] = PARAMETERS_HW.getVolatility()[loopvol];
   }
 }
 @Test
 /** Tests the Hull-White parameters sensitivity for the explicit formula. */
 public void presentValueHullWhiteSensitivityExplicit() {
   final double[] hwSensitivity =
       METHOD_HW.presentValueHullWhiteSensitivity(SWAPTION_LONG_PAYER, HW_MULTICURVES);
   final int nbVolatility = HW_PARAMETERS.getVolatility().length;
   final double shiftVol = 1.0E-6;
   final double[] volatilityBumped = new double[nbVolatility];
   System.arraycopy(HW_PARAMETERS.getVolatility(), 0, volatilityBumped, 0, nbVolatility);
   final double[] volatilityTime = new double[nbVolatility - 1];
   System.arraycopy(HW_PARAMETERS.getVolatilityTime(), 1, volatilityTime, 0, nbVolatility - 1);
   final double[] pvBumpedPlus = new double[nbVolatility];
   final double[] pvBumpedMinus = new double[nbVolatility];
   final HullWhiteOneFactorPiecewiseConstantParameters parametersBumped =
       new HullWhiteOneFactorPiecewiseConstantParameters(
           HW_PARAMETERS.getMeanReversion(), volatilityBumped, volatilityTime);
   final HullWhiteOneFactorProviderDiscount bundleBumped =
       new HullWhiteOneFactorProviderDiscount(MULTICURVES, parametersBumped, EUR);
   for (int loopvol = 0; loopvol < nbVolatility; loopvol++) {
     volatilityBumped[loopvol] += shiftVol;
     parametersBumped.setVolatility(volatilityBumped);
     pvBumpedPlus[loopvol] =
         METHOD_HW.presentValue(SWAPTION_LONG_PAYER, bundleBumped).getAmount(EUR);
     volatilityBumped[loopvol] -= 2 * shiftVol;
     parametersBumped.setVolatility(volatilityBumped);
     pvBumpedMinus[loopvol] =
         METHOD_HW.presentValue(SWAPTION_LONG_PAYER, bundleBumped).getAmount(EUR);
     assertEquals(
         "Swaption - Hull-White sensitivity adjoint: derivative "
             + loopvol
             + " - difference:"
             + ((pvBumpedPlus[loopvol] - pvBumpedMinus[loopvol]) / (2 * shiftVol)
                 - hwSensitivity[loopvol]),
         (pvBumpedPlus[loopvol] - pvBumpedMinus[loopvol]) / (2 * shiftVol),
         hwSensitivity[loopvol],
         TOLERANCE_PV_DELTA);
     volatilityBumped[loopvol] = HW_PARAMETERS.getVolatility()[loopvol];
   }
 }