public virtual void test_relativeTime()
        {
            SabrParametersIborCapletFloorletVolatilities prov = SabrParametersIborCapletFloorletVolatilities.of(NAME, EUR_EURIBOR_3M, DATE_TIME, PARAM);
            double test1 = prov.relativeTime(DATE_TIME);

            assertEquals(test1, 0d);
            double test2 = prov.relativeTime(DATE_TIME.plusYears(2));
            double test3 = prov.relativeTime(DATE_TIME.minusYears(2));

            assertEquals(test2, -test3, 1e-2);
        }
        public virtual void test_parameterSensitivity()
        {
            double alphaSensi = 2.24, betaSensi = 3.45, rhoSensi = -2.12, nuSensi = -0.56, shiftSensi = 2.5;
            SabrParametersIborCapletFloorletVolatilities prov = SabrParametersIborCapletFloorletVolatilities.of(NAME, EUR_EURIBOR_3M, DATE_TIME, PARAM);

            for (int i = 0; i < NB_TEST; i++)
            {
                double                         expiryTime             = prov.relativeTime(TEST_OPTION_EXPIRY[i]);
                PointSensitivities             point                  = PointSensitivities.of(IborCapletFloorletSabrSensitivity.of(NAME, expiryTime, ALPHA, EUR, alphaSensi), IborCapletFloorletSabrSensitivity.of(NAME, expiryTime, BETA, EUR, betaSensi), IborCapletFloorletSabrSensitivity.of(NAME, expiryTime, RHO, EUR, rhoSensi), IborCapletFloorletSabrSensitivity.of(NAME, expiryTime, NU, EUR, nuSensi), IborCapletFloorletSabrSensitivity.of(NAME, expiryTime, SHIFT, EUR, shiftSensi));
                CurrencyParameterSensitivities sensiComputed          = prov.parameterSensitivity(point);
                UnitParameterSensitivity       alphaSensitivities     = prov.Parameters.AlphaCurve.yValueParameterSensitivity(expiryTime);
                UnitParameterSensitivity       betaSensitivities      = prov.Parameters.BetaCurve.yValueParameterSensitivity(expiryTime);
                UnitParameterSensitivity       rhoSensitivities       = prov.Parameters.RhoCurve.yValueParameterSensitivity(expiryTime);
                UnitParameterSensitivity       nuSensitivities        = prov.Parameters.NuCurve.yValueParameterSensitivity(expiryTime);
                UnitParameterSensitivity       shiftSensitivities     = prov.Parameters.ShiftCurve.yValueParameterSensitivity(expiryTime);
                CurrencyParameterSensitivity   alphaSensiObj          = sensiComputed.getSensitivity(IborCapletFloorletSabrRateVolatilityDataSet.META_ALPHA.CurveName, EUR);
                CurrencyParameterSensitivity   betaSensiObj           = sensiComputed.getSensitivity(IborCapletFloorletSabrRateVolatilityDataSet.META_BETA.CurveName, EUR);
                CurrencyParameterSensitivity   rhoSensiObj            = sensiComputed.getSensitivity(IborCapletFloorletSabrRateVolatilityDataSet.META_RHO.CurveName, EUR);
                CurrencyParameterSensitivity   nuSensiObj             = sensiComputed.getSensitivity(IborCapletFloorletSabrRateVolatilityDataSet.META_NU.CurveName, EUR);
                CurrencyParameterSensitivity   shiftSensiObj          = sensiComputed.getSensitivity(IborCapletFloorletSabrRateVolatilityDataSet.META_SHIFT.CurveName, EUR);
                DoubleArray                    alphaNodeSensiComputed = alphaSensiObj.Sensitivity;
                DoubleArray                    betaNodeSensiComputed  = betaSensiObj.Sensitivity;
                DoubleArray                    rhoNodeSensiComputed   = rhoSensiObj.Sensitivity;
                DoubleArray                    nuNodeSensiComputed    = nuSensiObj.Sensitivity;
                DoubleArray                    shiftNodeSensiComputed = shiftSensiObj.Sensitivity;
                assertEquals(alphaSensitivities.Sensitivity.size(), alphaNodeSensiComputed.size());
                assertEquals(betaSensitivities.Sensitivity.size(), betaNodeSensiComputed.size());
                assertEquals(rhoSensitivities.Sensitivity.size(), rhoNodeSensiComputed.size());
                assertEquals(nuSensitivities.Sensitivity.size(), nuNodeSensiComputed.size());
                assertEquals(shiftSensitivities.Sensitivity.size(), shiftNodeSensiComputed.size());
                for (int k = 0; k < alphaNodeSensiComputed.size(); ++k)
                {
                    assertEquals(alphaNodeSensiComputed.get(k), alphaSensitivities.Sensitivity.get(k) * alphaSensi, TOLERANCE_VOL);
                }
                for (int k = 0; k < betaNodeSensiComputed.size(); ++k)
                {
                    assertEquals(betaNodeSensiComputed.get(k), betaSensitivities.Sensitivity.get(k) * betaSensi, TOLERANCE_VOL);
                }
                for (int k = 0; k < rhoNodeSensiComputed.size(); ++k)
                {
                    assertEquals(rhoNodeSensiComputed.get(k), rhoSensitivities.Sensitivity.get(k) * rhoSensi, TOLERANCE_VOL);
                }
                for (int k = 0; k < nuNodeSensiComputed.size(); ++k)
                {
                    assertEquals(nuNodeSensiComputed.get(k), nuSensitivities.Sensitivity.get(k) * nuSensi, TOLERANCE_VOL);
                }
                for (int k = 0; k < shiftNodeSensiComputed.size(); ++k)
                {
                    assertEquals(shiftNodeSensiComputed.get(k), shiftSensitivities.Sensitivity.get(k) * shiftSensi, TOLERANCE_VOL);
                }
            }
        }
        public virtual void test_parameterSensitivity_multi()
        {
            double[] points1 = new double[] { 2.24, 3.45, -2.12, -0.56 };
            double[] points2 = new double[] { -0.145, 1.01, -5.0, -11.0 };
            double[] points3 = new double[] { 1.3, -4.32, 2.1, -7.18 };
            SabrParametersIborCapletFloorletVolatilities prov = SabrParametersIborCapletFloorletVolatilities.of(NAME, EUR_EURIBOR_3M, DATE_TIME, PARAM);
            double expiryTime0 = prov.relativeTime(TEST_OPTION_EXPIRY[0]);
            double expiryTime3 = prov.relativeTime(TEST_OPTION_EXPIRY[3]);

            for (int i = 0; i < NB_TEST; i++)
            {
                PointSensitivities             sensi1   = PointSensitivities.of(IborCapletFloorletSabrSensitivity.of(NAME, expiryTime0, ALPHA, EUR, points1[0]), IborCapletFloorletSabrSensitivity.of(NAME, expiryTime0, BETA, EUR, points1[1]), IborCapletFloorletSabrSensitivity.of(NAME, expiryTime0, RHO, EUR, points1[2]), IborCapletFloorletSabrSensitivity.of(NAME, expiryTime0, NU, EUR, points1[3]));
                PointSensitivities             sensi2   = PointSensitivities.of(IborCapletFloorletSabrSensitivity.of(NAME, expiryTime0, ALPHA, EUR, points2[0]), IborCapletFloorletSabrSensitivity.of(NAME, expiryTime0, BETA, EUR, points2[1]), IborCapletFloorletSabrSensitivity.of(NAME, expiryTime0, RHO, EUR, points2[2]), IborCapletFloorletSabrSensitivity.of(NAME, expiryTime0, NU, EUR, points2[3]));
                PointSensitivities             sensi3   = PointSensitivities.of(IborCapletFloorletSabrSensitivity.of(NAME, expiryTime3, ALPHA, EUR, points3[0]), IborCapletFloorletSabrSensitivity.of(NAME, expiryTime3, BETA, EUR, points3[1]), IborCapletFloorletSabrSensitivity.of(NAME, expiryTime3, RHO, EUR, points3[2]), IborCapletFloorletSabrSensitivity.of(NAME, expiryTime3, NU, EUR, points3[3]));
                PointSensitivities             sensis   = sensi1.combinedWith(sensi2).combinedWith(sensi3).normalized();
                CurrencyParameterSensitivities computed = prov.parameterSensitivity(sensis);
                CurrencyParameterSensitivities expected = prov.parameterSensitivity(sensi1).combinedWith(prov.parameterSensitivity(sensi2)).combinedWith(prov.parameterSensitivity(sensi3));
                DoubleArrayMath.fuzzyEquals(computed.getSensitivity(PARAM.AlphaCurve.Name, EUR).Sensitivity.toArray(), expected.getSensitivity(PARAM.AlphaCurve.Name, EUR).Sensitivity.toArray(), TOLERANCE_VOL);
                DoubleArrayMath.fuzzyEquals(computed.getSensitivity(PARAM.BetaCurve.Name, EUR).Sensitivity.toArray(), expected.getSensitivity(PARAM.BetaCurve.Name, EUR).Sensitivity.toArray(), TOLERANCE_VOL);
                DoubleArrayMath.fuzzyEquals(computed.getSensitivity(PARAM.RhoCurve.Name, EUR).Sensitivity.toArray(), expected.getSensitivity(PARAM.RhoCurve.Name, EUR).Sensitivity.toArray(), TOLERANCE_VOL);
                DoubleArrayMath.fuzzyEquals(computed.getSensitivity(PARAM.NuCurve.Name, EUR).Sensitivity.toArray(), expected.getSensitivity(PARAM.NuCurve.Name, EUR).Sensitivity.toArray(), TOLERANCE_VOL);
            }
        }
        public virtual void test_volatility()
        {
            SabrParametersIborCapletFloorletVolatilities prov = SabrParametersIborCapletFloorletVolatilities.of(NAME, EUR_EURIBOR_3M, DATE_TIME, PARAM);

            for (int i = 0; i < NB_TEST; i++)
            {
                for (int j = 0; j < NB_STRIKE; ++j)
                {
                    double expiryTime  = prov.relativeTime(TEST_OPTION_EXPIRY[i]);
                    double volExpected = PARAM.volatility(expiryTime, TEST_STRIKE[j], TEST_FORWARD);
                    double volComputed = prov.volatility(TEST_OPTION_EXPIRY[i], TEST_STRIKE[j], TEST_FORWARD);
                    assertEquals(volComputed, volExpected, TOLERANCE_VOL);
                    ValueDerivatives volAdjExpected = PARAM.volatilityAdjoint(expiryTime, TEST_STRIKE[j], TEST_FORWARD);
                    ValueDerivatives volAdjComputed = prov.volatilityAdjoint(expiryTime, TEST_STRIKE[j], TEST_FORWARD);
                    assertEquals(volAdjComputed.Value, volExpected, TOLERANCE_VOL);
                    assertTrue(DoubleArrayMath.fuzzyEquals(volAdjComputed.Derivatives.toArray(), volAdjExpected.Derivatives.toArray(), TOLERANCE_VOL));
                }
            }
        }
        //-------------------------------------------------------------------------
        public virtual void test_presentValue_formula()
        {
            CurrencyAmount computedCaplet   = PRICER.presentValue(CAPLET_LONG, RATES, VOLS);
            CurrencyAmount computedFloorlet = PRICER.presentValue(FLOORLET_SHORT, RATES, VOLS);
            double         forward          = RATES.iborIndexRates(EUR_EURIBOR_3M).rate(RATE_COMP.Observation);
            double         expiry           = VOLS.relativeTime(CAPLET_LONG.FixingDateTime);
            double         volatility       = VOLS.volatility(expiry, STRIKE, forward);
            double         df               = RATES.discountFactor(EUR, CAPLET_LONG.PaymentDate);
            double         expectedCaplet   = NOTIONAL * df * CAPLET_LONG.YearFraction * BlackFormulaRepository.price(forward + SHIFT, STRIKE + SHIFT, expiry, volatility, CALL.Call);
            double         expectedFloorlet = -NOTIONAL *df *FLOORLET_SHORT.YearFraction *BlackFormulaRepository.price(forward + SHIFT, STRIKE + SHIFT, expiry, volatility, PUT.Call);

            assertEquals(computedCaplet.Currency, EUR);
            assertEquals(computedCaplet.Amount, expectedCaplet, NOTIONAL * TOL);
            assertEquals(computedFloorlet.Currency, EUR);
            assertEquals(computedFloorlet.Amount, expectedFloorlet, NOTIONAL * TOL);
            // consistency with shifted Black
            ShiftedBlackIborCapletFloorletExpiryStrikeVolatilities vols = ShiftedBlackIborCapletFloorletExpiryStrikeVolatilities.of(EUR_EURIBOR_3M, VALUATION, ConstantSurface.of("constVol", volatility).withMetadata(Surfaces.blackVolatilityByExpiryStrike("costVol", DayCounts.ACT_ACT_ISDA)), IborCapletFloorletSabrRateVolatilityDataSet.CURVE_CONST_SHIFT);
            CurrencyAmount computedCapletBlack   = PRICER_BASE.presentValue(CAPLET_LONG, RATES, vols);
            CurrencyAmount computedFloorletBlack = PRICER_BASE.presentValue(FLOORLET_SHORT, RATES, vols);

            assertEquals(computedCaplet.Amount, computedCapletBlack.Amount, NOTIONAL * TOL);
            assertEquals(computedFloorlet.Amount, computedFloorletBlack.Amount, NOTIONAL * TOL);
        }