public virtual void test_recovery_normal_fixedRho()
        {
            SabrIborCapletFloorletVolatilityBootstrapDefinition definition = SabrIborCapletFloorletVolatilityBootstrapDefinition.ofFixedRho(IborCapletFloorletVolatilitiesName.of("test"), USD_LIBOR_3M, ACT_ACT_ISDA, 0.0, CurveInterpolators.LINEAR, CurveExtrapolators.FLAT, CurveExtrapolators.FLAT, SabrHaganVolatilityFunctionProvider.DEFAULT);
            RawOptionData data = RawOptionData.of(createNormalEquivMaturities(), createNormalEquivStrikes(), ValueType.STRIKE, createFullNormalEquivDataMatrix(), ValueType.NORMAL_VOLATILITY);
            IborCapletFloorletVolatilityCalibrationResult res     = CALIBRATOR.calibrate(definition, CALIBRATION_TIME, data, RATES_PROVIDER);
            SabrParametersIborCapletFloorletVolatilities  resVols = (SabrParametersIborCapletFloorletVolatilities)res.Volatilities;

            for (int i = 1; i < NUM_BLACK_STRIKES; ++i)
            {
                Pair <IList <ResolvedIborCapFloorLeg>, IList <double> > capsAndVols = getCapsNormalEquivVols(i);
                IList <ResolvedIborCapFloorLeg> caps = capsAndVols.First;
                IList <double> vols  = capsAndVols.Second;
                int            nCaps = caps.Count;
                for (int j = 0; j < nCaps; ++j)
                {
                    ConstantSurface volSurface = ConstantSurface.of(Surfaces.normalVolatilityByExpiryStrike("test", ACT_ACT_ISDA), vols[j]);
                    NormalIborCapletFloorletExpiryStrikeVolatilities constVol = NormalIborCapletFloorletExpiryStrikeVolatilities.of(USD_LIBOR_3M, CALIBRATION_TIME, volSurface);
                    double priceOrg   = LEG_PRICER_NORMAL.presentValue(caps[j], RATES_PROVIDER, constVol).Amount;
                    double priceCalib = LEG_PRICER_SABR.presentValue(caps[j], RATES_PROVIDER, resVols).Amount;
                    assertEquals(priceOrg, priceCalib, Math.Max(priceOrg, 1d) * TOL * 3d);
                }
            }
            assertTrue(res.ChiSquare > 0d);
            assertEquals(resVols.Index, USD_LIBOR_3M);
            assertEquals(resVols.Name, definition.Name);
            assertEquals(resVols.ValuationDateTime, CALIBRATION_TIME);
        }
        public virtual void test_recovery_black_fixedRho()
        {
            SabrIborCapletFloorletVolatilityBootstrapDefinition definition = SabrIborCapletFloorletVolatilityBootstrapDefinition.ofFixedRho(IborCapletFloorletVolatilitiesName.of("test"), USD_LIBOR_3M, ACT_ACT_ISDA, 0.0, CurveInterpolators.STEP_UPPER, CurveExtrapolators.FLAT, CurveExtrapolators.FLAT, SabrHaganVolatilityFunctionProvider.DEFAULT);
            DoubleMatrix  volData    = createFullBlackDataMatrix();
            double        errorValue = 1.0e-3;
            DoubleMatrix  error      = DoubleMatrix.filled(volData.rowCount(), volData.columnCount(), errorValue);
            RawOptionData data       = RawOptionData.of(createBlackMaturities(), createBlackStrikes(), ValueType.STRIKE, volData, error, ValueType.BLACK_VOLATILITY);
            IborCapletFloorletVolatilityCalibrationResult res     = CALIBRATOR.calibrate(definition, CALIBRATION_TIME, data, RATES_PROVIDER);
            SabrParametersIborCapletFloorletVolatilities  resVols = (SabrParametersIborCapletFloorletVolatilities)res.Volatilities;
            double expSq = 0d;

            for (int i = 0; i < NUM_BLACK_STRIKES; ++i)
            {
                Pair <IList <ResolvedIborCapFloorLeg>, IList <double> > capsAndVols = getCapsBlackVols(i);
                IList <ResolvedIborCapFloorLeg> caps = capsAndVols.First;
                IList <double> vols  = capsAndVols.Second;
                int            nCaps = caps.Count;
                for (int j = 0; j < nCaps; ++j)
                {
                    ConstantSurface volSurface = ConstantSurface.of(Surfaces.blackVolatilityByExpiryStrike("test", ACT_ACT_ISDA), vols[j]);
                    BlackIborCapletFloorletExpiryStrikeVolatilities constVol = BlackIborCapletFloorletExpiryStrikeVolatilities.of(USD_LIBOR_3M, CALIBRATION_TIME, volSurface);
                    double priceOrg   = LEG_PRICER_BLACK.presentValue(caps[j], RATES_PROVIDER, constVol).Amount;
                    double priceCalib = LEG_PRICER_SABR.presentValue(caps[j], RATES_PROVIDER, resVols).Amount;
                    expSq += Math.Pow((priceOrg - priceCalib) / priceOrg / errorValue, 2);
                    assertEquals(priceOrg, priceCalib, Math.Max(priceOrg, 1d) * TOL * 3d);
                }
            }
            assertEquals(res.ChiSquare, expSq, expSq * 1.0e-14);
            assertEquals(resVols.Index, USD_LIBOR_3M);
            assertEquals(resVols.Name, definition.Name);
            assertEquals(resVols.ValuationDateTime, CALIBRATION_TIME);
            assertEquals(resVols.Parameters.ShiftCurve, definition.ShiftCurve);
            assertEquals(resVols.Parameters.RhoCurve, definition.RhoCurve.get());
        }
        public virtual void test_ofFixedRho_shift()
        {
            SabrIborCapletFloorletVolatilityBootstrapDefinition test = SabrIborCapletFloorletVolatilityBootstrapDefinition.ofFixedRho(NAME, USD_LIBOR_3M, ACT_ACT_ISDA, 0.5, 0.01, LINEAR, FLAT, FLAT, SabrVolatilityFormula.hagan());

            assertEquals(test.DayCount, ACT_ACT_ISDA);
            assertEquals(test.Index, USD_LIBOR_3M);
            assertEquals(test.Interpolator, LINEAR);
            assertEquals(test.ExtrapolatorLeft, FLAT);
            assertEquals(test.ExtrapolatorRight, FLAT);
            assertEquals(test.Name, NAME);
            assertEquals(test.RhoCurve.get(), ConstantCurve.of(Curves.sabrParameterByExpiry(NAME.Name + "-Rho", ACT_ACT_ISDA, SABR_RHO), 0.5));
            assertFalse(test.BetaCurve.Present);
            assertEquals(test.SabrVolatilityFormula, SabrVolatilityFormula.hagan());
            assertEquals(test.ShiftCurve, ConstantCurve.of("Shift curve", 0.01));
        }