// -------------------------------------------------------------------------
 public void test_priceSensitivity() {
   PointSensitivities point =
       OPTION_PRICER.priceSensitivityStickyStrike(
           FUTURE_OPTION_PRODUCT, RATE_PROVIDER, VOL_PROVIDER);
   CurveCurrencyParameterSensitivities computed = RATE_PROVIDER.curveParameterSensitivity(point);
   CurveCurrencyParameterSensitivities expected =
       FD_CAL.sensitivity(
           RATE_PROVIDER,
           (p) ->
               CurrencyAmount.of(
                   EUR, OPTION_PRICER.price(FUTURE_OPTION_PRODUCT, (p), VOL_PROVIDER)));
   double futurePrice = FUTURE_PRICER.price(FUTURE_OPTION_PRODUCT.getUnderlying(), RATE_PROVIDER);
   double strike = FUTURE_OPTION_PRODUCT.getStrikePrice();
   double expiryTime =
       ACT_365F.relativeYearFraction(VALUATION_DATE, FUTURE_OPTION_PRODUCT.getExpiryDate());
   double logMoneyness = Math.log(strike / futurePrice);
   double logMoneynessUp = Math.log(strike / (futurePrice + EPS));
   double logMoneynessDw = Math.log(strike / (futurePrice - EPS));
   double vol = SURFACE.zValue(expiryTime, logMoneyness);
   double volUp = SURFACE.zValue(expiryTime, logMoneynessUp);
   double volDw = SURFACE.zValue(expiryTime, logMoneynessDw);
   double volSensi = 0.5 * (volUp - volDw) / EPS;
   double vega = BlackFormulaRepository.vega(futurePrice, strike, expiryTime, vol);
   CurveCurrencyParameterSensitivities sensiVol =
       RATE_PROVIDER
           .curveParameterSensitivity(
               FUTURE_PRICER.priceSensitivity(
                   FUTURE_OPTION_PRODUCT.getUnderlying(), RATE_PROVIDER))
           .multipliedBy(-vega * volSensi);
   expected = expected.combinedWith(sensiVol);
   assertTrue(computed.equalWithTolerance(expected, 30d * EPS));
 }
  public void regression_withZSpread_periodic() {
    double price =
        FUTURE_PRICER.priceWithZSpread(
            FUTURE_PRODUCT, PROVIDER, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR);
    assertEquals(price, 1.1720190529653407, TOL);
    PointSensitivities point =
        FUTURE_PRICER.priceSensitivityWithZSpread(
            FUTURE_PRODUCT, PROVIDER, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR);
    CurrencyParameterSensitivities test = PROVIDER.parameterSensitivity(point);

    DoubleArray expectedIssuer =
        DoubleArray.of(
            -3.9201229100932256E-4,
            -0.0041367134351306374,
            -0.014173323438217467,
            -0.9886444827927878,
            -4.07533109609094,
            0);
    DoubleArray actualIssuer =
        test.getSensitivity(METADATA_ISSUER.getCurveName(), USD).getSensitivity();
    assertTrue(actualIssuer.equalWithTolerance(expectedIssuer, TOL));

    DoubleArray expectedRepo =
        DoubleArray.of(0.1428352116441475, 0.20242871054203687, 0.0, 0.0, 0.0, 0.0);
    DoubleArray actualRepo =
        test.getSensitivity(METADATA_REPO.getCurveName(), USD).getSensitivity();
    assertTrue(actualRepo.equalWithTolerance(expectedRepo, TOL));
  }
 // -------------------------------------------------------------------------
 public void test_priceSensitivity() {
   PointSensitivities point = FUTURE_PRICER.priceSensitivity(FUTURE_PRODUCT, PROVIDER);
   CurrencyParameterSensitivities computed = PROVIDER.parameterSensitivity(point);
   CurrencyParameterSensitivities expected =
       FD_CAL.sensitivity(
           PROVIDER, (p) -> CurrencyAmount.of(USD, FUTURE_PRICER.price(FUTURE_PRODUCT, (p))));
   assertTrue(computed.equalWithTolerance(expected, EPS * 10.0));
 }
 public void test_priceSensitivityWithZSpread_continuous() {
   PointSensitivities point =
       FUTURE_PRICER.priceSensitivityWithZSpread(
           FUTURE_PRODUCT, PROVIDER, Z_SPREAD, CONTINUOUS, 0);
   CurrencyParameterSensitivities computed = PROVIDER.parameterSensitivity(point);
   CurrencyParameterSensitivities expected =
       FD_CAL.sensitivity(
           PROVIDER,
           (p) ->
               CurrencyAmount.of(
                   USD,
                   FUTURE_PRICER.priceWithZSpread(FUTURE_PRODUCT, (p), Z_SPREAD, CONTINUOUS, 0)));
   assertTrue(computed.equalWithTolerance(expected, EPS * 10.0));
 }
 // -------------------------------------------------------------------------
 public void test_price() {
   double computed = FUTURE_PRICER.price(FUTURE_PRODUCT, PROVIDER);
   double dirtyPrice =
       BOND_PRICER.dirtyPriceFromCurves(BOND, PROVIDER, FUTURE_PRODUCT.getLastDeliveryDate());
   double expected =
       BOND_PRICER.cleanPriceFromDirtyPrice(BOND, FUTURE_PRODUCT.getLastDeliveryDate(), dirtyPrice)
           / CONVERSION_FACTOR[0];
   assertEquals(computed, expected, TOL);
 }
 public void test_theta() {
   double computed = OPTION_PRICER.theta(FUTURE_OPTION_PRODUCT, RATE_PROVIDER, VOL_PROVIDER);
   double futurePrice = FUTURE_PRICER.price(FUTURE_OPTION_PRODUCT.getUnderlying(), RATE_PROVIDER);
   double strike = FUTURE_OPTION_PRODUCT.getStrikePrice();
   double expiryTime =
       ACT_365F.relativeYearFraction(VALUATION_DATE, FUTURE_OPTION_PRODUCT.getExpiryDate());
   double logMoneyness = Math.log(strike / futurePrice);
   double vol = SURFACE.zValue(expiryTime, logMoneyness);
   double expected = BlackFormulaRepository.driftlessTheta(futurePrice, strike, expiryTime, vol);
   assertEquals(computed, expected, TOL);
 }
 public void test_priceWithZSpread_continuous() {
   double computed =
       FUTURE_PRICER.priceWithZSpread(FUTURE_PRODUCT, PROVIDER, Z_SPREAD, CONTINUOUS, 0);
   double dirtyPrice =
       BOND_PRICER.dirtyPriceFromCurvesWithZSpread(
           BOND, PROVIDER, Z_SPREAD, CONTINUOUS, 0, FUTURE_PRODUCT.getLastDeliveryDate());
   double expected =
       BOND_PRICER.cleanPriceFromDirtyPrice(BOND, FUTURE_PRODUCT.getLastDeliveryDate(), dirtyPrice)
           / CONVERSION_FACTOR[0];
   assertEquals(computed, expected, TOL);
 }
  // -------------------------------------------------------------------------
  // regression to 2.x
  public void regression() {
    double price = FUTURE_PRICER.price(FUTURE_PRODUCT, PROVIDER);
    assertEquals(price, 1.2106928633440506, TOL);
    PointSensitivities point = FUTURE_PRICER.priceSensitivity(FUTURE_PRODUCT, PROVIDER);
    CurrencyParameterSensitivities test = PROVIDER.parameterSensitivity(point);

    DoubleArray expectedIssuer =
        DoubleArray.of(
            -3.940585873921608E-4,
            -0.004161527192990392,
            -0.014331606019672717,
            -1.0229665443857998,
            -4.220553063715371,
            0);
    DoubleArray actualIssuer =
        test.getSensitivity(METADATA_ISSUER.getCurveName(), USD).getSensitivity();
    assertTrue(actualIssuer.equalWithTolerance(expectedIssuer, TOL));

    DoubleArray expectedRepo =
        DoubleArray.of(0.14752541809405412, 0.20907575809356016, 0.0, 0.0, 0.0, 0.0);
    DoubleArray actualRepo =
        test.getSensitivity(METADATA_REPO.getCurveName(), USD).getSensitivity();
    assertTrue(actualRepo.equalWithTolerance(expectedRepo, TOL));
  }
 public void test_priceSensitivity_from_future_price() {
   double futurePrice = 1.1d;
   PointSensitivities point =
       OPTION_PRICER.priceSensitivityStickyStrike(
           FUTURE_OPTION_PRODUCT, RATE_PROVIDER, VOL_PROVIDER, futurePrice);
   CurveCurrencyParameterSensitivities computed = RATE_PROVIDER.curveParameterSensitivity(point);
   double delta =
       OPTION_PRICER.deltaStickyStrike(
           FUTURE_OPTION_PRODUCT, RATE_PROVIDER, VOL_PROVIDER, futurePrice);
   CurveCurrencyParameterSensitivities expected =
       RATE_PROVIDER
           .curveParameterSensitivity(
               FUTURE_PRICER.priceSensitivity(
                   FUTURE_OPTION_PRODUCT.getUnderlying(), RATE_PROVIDER))
           .multipliedBy(delta);
   assertTrue(computed.equalWithTolerance(expected, TOL));
 }
 public void test_priceWithZSpread_periodic() {
   double computed =
       FUTURE_PRICER.priceWithZSpread(
           FUTURE_PRODUCT, PROVIDER, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR);
   double dirtyPrice =
       BOND_PRICER.dirtyPriceFromCurvesWithZSpread(
           BOND,
           PROVIDER,
           Z_SPREAD,
           PERIODIC,
           PERIOD_PER_YEAR,
           FUTURE_PRODUCT.getLastDeliveryDate());
   double expected =
       BOND_PRICER.cleanPriceFromDirtyPrice(BOND, FUTURE_PRODUCT.getLastDeliveryDate(), dirtyPrice)
           / CONVERSION_FACTOR[0];
   assertEquals(computed, expected, TOL);
 }
 public void regression_withZSpread_continuous() {
   double price =
       FUTURE_PRICER.priceWithZSpread(FUTURE_PRODUCT, PROVIDER, Z_SPREAD, CONTINUOUS, 0);
   assertEquals(price, 1.1718691843665354, TOL);
   // curve parameter sensitivity is not supported for continuous z-spread in 2.x.
 }