@Test
 /** Tests long/short parity. */
 public void longShortParity() {
   CurrencyAmount pvLong = METHOD_HW_INTEGRATION.presentValue(SWAPTION_PAYER_LONG, BUNDLE_HW);
   CurrencyAmount pvShort = METHOD_HW_INTEGRATION.presentValue(SWAPTION_PAYER_SHORT, BUNDLE_HW);
   assertEquals(
       "Swaption cash - Hull-White - present value - long/short parity",
       pvLong.getAmount(),
       -pvShort.getAmount(),
       1E-2);
 }
 @Test(enabled = true)
 /** Tests approximation error. "enabled = false" for the standard testing. */
 public void errorAnalysis() {
   double bp1 = 10000;
   double errorLimit = 5.0E-1; // 0.5 bp
   ParRateCalculator prc = ParRateCalculator.getInstance();
   double forward = prc.visit(SWAP_PAYER, CURVES);
   double[] strikeRel = new double[] {-0.0250, -0.0150, -0.0050, 0.0, 0.0050, 0.0150, 0.0250};
   double[] pvPayerApproximation = new double[strikeRel.length];
   double[] pvPayerIntegration = new double[strikeRel.length];
   double[] pvReceiverApproximation = new double[strikeRel.length];
   double[] pvReceiverIntegration = new double[strikeRel.length];
   for (int loopstrike = 0; loopstrike < strikeRel.length; loopstrike++) {
     SwapFixedIborDefinition swapStrikePayerDefinition =
         SwapFixedIborDefinition.from(
             SETTLEMENT_DATE, CMS_INDEX, bp1, forward + strikeRel[loopstrike], FIXED_IS_PAYER);
     SwaptionCashFixedIborDefinition swaptionStrikePayerDefinition =
         SwaptionCashFixedIborDefinition.from(EXPIRY_DATE, swapStrikePayerDefinition, IS_LONG);
     SwaptionCashFixedIbor swaptionStrikePayer =
         swaptionStrikePayerDefinition.toDerivative(REFERENCE_DATE, CURVES_NAME);
     pvPayerApproximation[loopstrike] =
         METHOD_HW_APPROXIMATION.presentValue(swaptionStrikePayer, BUNDLE_HW).getAmount();
     pvPayerIntegration[loopstrike] =
         METHOD_HW_INTEGRATION.presentValue(swaptionStrikePayer, BUNDLE_HW).getAmount();
     assertEquals(
         "Swaption cash - Hull-White - present value - explicit/numerical integration",
         pvPayerApproximation[loopstrike],
         pvPayerIntegration[loopstrike],
         errorLimit);
     SwapFixedIborDefinition swapStrikeReceiverDefinition =
         SwapFixedIborDefinition.from(
             SETTLEMENT_DATE, CMS_INDEX, bp1, forward + strikeRel[loopstrike], !FIXED_IS_PAYER);
     SwaptionCashFixedIborDefinition swaptionStrikeReceiverDefinition =
         SwaptionCashFixedIborDefinition.from(EXPIRY_DATE, swapStrikeReceiverDefinition, IS_LONG);
     SwaptionCashFixedIbor swaptionStrikeReceiver =
         swaptionStrikeReceiverDefinition.toDerivative(REFERENCE_DATE, CURVES_NAME);
     pvReceiverApproximation[loopstrike] =
         METHOD_HW_APPROXIMATION.presentValue(swaptionStrikeReceiver, BUNDLE_HW).getAmount();
     pvReceiverIntegration[loopstrike] =
         METHOD_HW_INTEGRATION.presentValue(swaptionStrikeReceiver, BUNDLE_HW).getAmount();
     assertEquals(
         "Swaption cash - Hull-White - present value - explicit/numerical integration",
         pvReceiverApproximation[loopstrike],
         pvReceiverIntegration[loopstrike],
         errorLimit);
   }
 }
  @Test(enabled = false)
  /** Tests of performance. "enabled = false" for the standard testing. */
  public void performance() {
    long startTime, endTime;
    final int nbTest = 1000;
    CurrencyAmount pvPayerLongExplicit = CurrencyAmount.of(CUR, 0.0);
    CurrencyAmount pvPayerLongIntegration = CurrencyAmount.of(CUR, 0.0);
    startTime = System.currentTimeMillis();
    for (int looptest = 0; looptest < nbTest; looptest++) {
      pvPayerLongExplicit = METHOD_HW_APPROXIMATION.presentValue(SWAPTION_PAYER_LONG, BUNDLE_HW);
    }
    endTime = System.currentTimeMillis();
    System.out.println(
        nbTest + " pv swaption Hull-White approximation method: " + (endTime - startTime) + " ms");
    // Performance note: HW price: 8-Jul-11: On Mac Pro 3.2 GHz Quad-Core Intel Xeon: 330 ms for
    // 10000 swaptions.
    startTime = System.currentTimeMillis();
    for (int looptest = 0; looptest < nbTest; looptest++) {
      METHOD_HW_APPROXIMATION.presentValueHullWhiteSensitivity(SWAPTION_PAYER_LONG, BUNDLE_HW);
    }
    endTime = System.currentTimeMillis();
    System.out.println(
        nbTest
            + " HW sensitivity swaption Hull-White approximation method: "
            + (endTime - startTime)
            + " ms");
    // Performance note: HW parameters sensitivity: 8-Jul-11: On Mac Pro 3.2 GHz Quad-Core Intel
    // Xeon: 525 ms for 10000 swaptions.
    startTime = System.currentTimeMillis();
    for (int looptest = 0; looptest < nbTest; looptest++) {
      METHOD_HW_APPROXIMATION.presentValueCurveSensitivity(SWAPTION_PAYER_LONG, BUNDLE_HW);
    }
    endTime = System.currentTimeMillis();
    System.out.println(
        nbTest
            + " curve sensitivity swaption Hull-White approximation method: "
            + (endTime - startTime)
            + " ms");
    // Performance note: HW curve sensitivity: 8-Jul-11: On Mac Pro 3.2 GHz Quad-Core Intel Xeon:
    // 550 ms for 10000 swaptions.
    startTime = System.currentTimeMillis();
    for (int looptest = 0; looptest < nbTest; looptest++) {
      pvPayerLongIntegration = METHOD_HW_INTEGRATION.presentValue(SWAPTION_PAYER_LONG, BUNDLE_HW);
    }
    endTime = System.currentTimeMillis();
    System.out.println(
        nbTest
            + " cash swaption Hull-White numerical integration method: "
            + (endTime - startTime)
            + " ms");
    // Performance note: HW numerical integration: 8-Jul-11: On Mac Pro 3.2 GHz Quad-Core Intel
    // Xeon: 1300 ms for 10000 swaptions.

    double difference = 0.0;
    difference = pvPayerLongExplicit.getAmount() - pvPayerLongIntegration.getAmount();
    System.out.println("Difference: " + difference);
  }
 @Test
 /** Tests long/short parity. */
 public void scaling() {
   double scale = 12.3;
   SwapFixedIborDefinition scaledSwapDefinition =
       SwapFixedIborDefinition.from(
           SETTLEMENT_DATE, CMS_INDEX, scale * NOTIONAL, RATE, FIXED_IS_PAYER);
   SwaptionCashFixedIborDefinition scaledSwaptionDefinition =
       SwaptionCashFixedIborDefinition.from(EXPIRY_DATE, scaledSwapDefinition, IS_LONG);
   SwaptionCashFixedIbor scaledSwaption =
       scaledSwaptionDefinition.toDerivative(REFERENCE_DATE, CURVES_NAME);
   CurrencyAmount pvOriginal = METHOD_HW_INTEGRATION.presentValue(SWAPTION_PAYER_LONG, BUNDLE_HW);
   CurrencyAmount pvScaled = METHOD_HW_INTEGRATION.presentValue(scaledSwaption, BUNDLE_HW);
   assertEquals(
       "Swaption cash - Hull-White - present value - scaling",
       scale * pvOriginal.getAmount(),
       pvScaled.getAmount(),
       1E-1);
 }
 @Test
 /** Compare approximate formula with numerical integration. */
 public void comparison() {
   double bp1 = 10000;
   CurrencyAmount pvPayerLongExplicit =
       METHOD_HW_APPROXIMATION.presentValue(SWAPTION_PAYER_LONG, BUNDLE_HW);
   CurrencyAmount pvPayerLongIntegration =
       METHOD_HW_INTEGRATION.presentValue(SWAPTION_PAYER_LONG, BUNDLE_HW);
   assertEquals(
       "Swaption cash - Hull-White - present value - explicit/numerical integration",
       pvPayerLongExplicit.getAmount() / NOTIONAL * bp1,
       pvPayerLongIntegration.getAmount() / NOTIONAL * bp1,
       3.0E-1);
   CurrencyAmount pvPayerShortExplicit =
       METHOD_HW_APPROXIMATION.presentValue(SWAPTION_PAYER_SHORT, BUNDLE_HW);
   CurrencyAmount pvPayerShortIntegration =
       METHOD_HW_INTEGRATION.presentValue(SWAPTION_PAYER_SHORT, BUNDLE_HW);
   assertEquals(
       "Swaption cash - Hull-White - present value - explicit/numerical integration",
       pvPayerShortExplicit.getAmount() / NOTIONAL * bp1,
       pvPayerShortIntegration.getAmount() / NOTIONAL * bp1,
       3.0E-1);
   CurrencyAmount pvReceiverLongExplicit =
       METHOD_HW_APPROXIMATION.presentValue(SWAPTION_RECEIVER_LONG, BUNDLE_HW);
   CurrencyAmount pvReceiverLongIntegration =
       METHOD_HW_INTEGRATION.presentValue(SWAPTION_RECEIVER_LONG, BUNDLE_HW);
   assertEquals(
       "Swaption cash - Hull-White - present value - explicit/numerical integration",
       pvReceiverLongExplicit.getAmount() / NOTIONAL * bp1,
       pvReceiverLongIntegration.getAmount() / NOTIONAL * bp1,
       5.0E-1);
   CurrencyAmount pvReceiverShortExplicit =
       METHOD_HW_APPROXIMATION.presentValue(SWAPTION_RECEIVER_SHORT, BUNDLE_HW);
   CurrencyAmount pvReceiverShortIntegration =
       METHOD_HW_INTEGRATION.presentValue(SWAPTION_RECEIVER_SHORT, BUNDLE_HW);
   assertEquals(
       "Swaption cash - Hull-White - present value - explicit/numerical integration",
       pvReceiverShortExplicit.getAmount() / NOTIONAL * bp1,
       pvReceiverShortIntegration.getAmount() / NOTIONAL * bp1,
       5.0E-1);
 }