//------------------------------------------------------------------------- internal static ScenarioMarketData marketData() { Curve curve = ConstantCurve.of(Curves.discountFactors("Test", ACT_360), 0.99); TestMarketDataMap md = new TestMarketDataMap(VAL_DATE, ImmutableMap.of(DISCOUNT_CURVE_ID, curve), ImmutableMap.of()); return(md); }
//------------------------------------------------------------------------- internal static ScenarioMarketData marketData() { Curve curve = ConstantCurve.of(Curves.discountFactors("Test", ACT_360), 0.99); TestMarketDataMap md = new TestMarketDataMap(VAL_DATE, ImmutableMap.of(DISCOUNT_CURVE_ID, curve, FORWARD_CURVE_ID, curve, VOL_ID, NORMAL_VOL_SWAPTION_PROVIDER_USD), ImmutableMap.of()); return(md); }
public virtual void recovery_test_shiftedBlack() { double lambdaT = 0.07; double lambdaK = 0.07; double error = 1.0e-5; ConstantCurve shiftCurve = ConstantCurve.of("Black shift", 0.02); DirectIborCapletFloorletVolatilityDefinition definition = DirectIborCapletFloorletVolatilityDefinition.of(NAME, USD_LIBOR_3M, ACT_ACT_ISDA, lambdaT, lambdaK, INTERPOLATOR, shiftCurve); ImmutableList <Period> maturities = createBlackMaturities(); DoubleArray strikes = createBlackStrikes(); DoubleMatrix errorMatrix = DoubleMatrix.filled(maturities.size(), strikes.size(), error); RawOptionData data = RawOptionData.of(maturities, strikes, STRIKE, createFullBlackDataMatrix(), errorMatrix, BLACK_VOLATILITY); IborCapletFloorletVolatilityCalibrationResult res = CALIBRATOR.calibrate(definition, CALIBRATION_TIME, data, RATES_PROVIDER); ShiftedBlackIborCapletFloorletExpiryStrikeVolatilities resVols = (ShiftedBlackIborCapletFloorletExpiryStrikeVolatilities)res.Volatilities; 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_BLACK.presentValue(caps[j], RATES_PROVIDER, resVols).Amount; assertEquals(priceOrg, priceCalib, Math.Max(priceOrg, 1d) * TOL); } } assertTrue(res.ChiSquare > 0d); assertEquals(resVols.Index, USD_LIBOR_3M); assertEquals(resVols.Name, definition.Name); assertEquals(resVols.ValuationDateTime, CALIBRATION_TIME); assertEquals(resVols.ShiftCurve, definition.ShiftCurve.get()); }
//------------------------------------------------------------------------- internal static ScenarioMarketData marketData() { Curve curve = ConstantCurve.of(Curves.discountFactors("Test", ACT_360), 0.99); TestMarketDataMap md = new TestMarketDataMap(VAL_DATE, ImmutableMap.of(DISCOUNT_CURVE_ID, curve, FORWARD_CURVE_ID, curve, VOL_ID, VOL_SIMPLE_MONEY_PRICE, QUOTE_ID_OPTION, SETTLEMENT_PRICE), ImmutableMap.of()); return(md); }
//------------------------------------------------------------------------- internal static ScenarioMarketData marketData() { Curve curve1 = ConstantCurve.of(Curves.discountFactors("Test", ACT_360), 0.992); Curve curve2 = ConstantCurve.of(Curves.discountFactors("Test", ACT_360), 0.991); TestMarketDataMap md = new TestMarketDataMap(VAL_DATE, ImmutableMap.of(DISCOUNT_CURVE_EUR_ID, curve1, DISCOUNT_CURVE_USD_ID, curve2, VOL_ID, VOLS, FxRateId.of(EUR, USD), FxRate.of(EUR, USD, 1.62)), ImmutableMap.of()); return(md); }
//------------------------------------------------------------------------- // creates a simple provider private SimpleRatesProvider createProvider(ResolvedFra fraExp) { DiscountFactors mockDf = SimpleDiscountFactors.of(GBP, VAL_DATE, ConstantCurve.of(Curves.discountFactors("DSC", DAY_COUNT), DISCOUNT_FACTOR)); LocalDateDoubleTimeSeries timeSeries = LocalDateDoubleTimeSeries.of(VAL_DATE, FORWARD_RATE); IborIndexRates mockIbor = SimpleIborIndexRates.of(GBP_LIBOR_3M, VAL_DATE, ConstantCurve.of(Curves.forwardRates("L3M", DAY_COUNT), FORWARD_RATE), timeSeries); SimpleRatesProvider prov = new SimpleRatesProvider(VAL_DATE, mockDf); prov.IborRates = mockIbor; return prov; }
//------------------------------------------------------------------------- public virtual void coverage() { SabrIborCapletFloorletVolatilityCalibrationDefinition test1 = SabrIborCapletFloorletVolatilityCalibrationDefinition.ofFixedBeta(NAME, USD_LIBOR_3M, ACT_365F, BETA_RHO, ALPHA_KNOTS, BETA_RHO_KNOTS, NU_KNOTS, DOUBLE_QUADRATIC, FLAT, LINEAR, HAGAN); coverImmutableBean(test1); Curve betaCurve = InterpolatedNodalCurve.of(Curves.sabrParameterByExpiry(NAME.Name + "-Beta", ACT_365F, SABR_BETA), DoubleArray.of(2d, 5d), DoubleArray.of(0.5, 0.8), CurveInterpolators.PCHIP); Curve shiftCurve = ConstantCurve.of("shift curve", 0.03d); DoubleArray initial = DoubleArray.of(0.34, 0.5, -0.22, 1.2); ImmutableList <DoubleArray> knots = ImmutableList.of(ALPHA_KNOTS, DoubleArray.of(), BETA_RHO_KNOTS, DoubleArray.of(1.1)); SabrIborCapletFloorletVolatilityCalibrationDefinition test2 = SabrIborCapletFloorletVolatilityCalibrationDefinition.builder().betaCurve(betaCurve).dayCount(ACT_360).extrapolatorLeft(LINEAR).extrapolatorRight(FLAT).interpolator(PCHIP).index(GBP_LIBOR_3M).initialParameters(initial).name(IborCapletFloorletVolatilitiesName.of("other")).parameterCurveNodes(knots).sabrVolatilityFormula(HAGAN).shiftCurve(shiftCurve).build(); coverBeanEquals(test1, test2); }
public virtual void test_of_curveGroup() { ImmutableMap <Currency, Curve> discounts = ImmutableMap.of(USD, ConstantCurve.of(CURVE_ID_DSC.CurveName, 1)); ImmutableMap <Index, Curve> forwards = ImmutableMap.of(USD_LIBOR_3M, ConstantCurve.of(CURVE_ID_FWD.CurveName, 1)); RatesCurveGroup group = RatesCurveGroup.of(CURVE_ID_DSC.CurveGroupName, discounts, forwards); RatesMarketDataLookup test = RatesMarketDataLookup.of(group); assertEquals(test.queryType(), typeof(RatesMarketDataLookup)); assertEquals(test.DiscountCurrencies, ImmutableSet.of(USD)); assertEquals(test.getDiscountMarketDataIds(USD), ImmutableSet.of(CURVE_ID_DSC)); assertEquals(test.ForwardIndices, ImmutableSet.of(USD_LIBOR_3M)); assertEquals(test.getForwardMarketDataIds(USD_LIBOR_3M), ImmutableSet.of(CURVE_ID_FWD)); assertThrowsIllegalArg(() => test.getDiscountMarketDataIds(GBP)); assertThrowsIllegalArg(() => test.getForwardMarketDataIds(GBP_LIBOR_3M)); }
public virtual void test_ofFixedBeta() { SabrIborCapletFloorletVolatilityCalibrationDefinition test = SabrIborCapletFloorletVolatilityCalibrationDefinition.ofFixedBeta(NAME, USD_LIBOR_3M, ACT_365F, BETA_RHO, ALPHA_KNOTS, BETA_RHO_KNOTS, NU_KNOTS, DOUBLE_QUADRATIC, FLAT, LINEAR, HAGAN); assertEquals(test.BetaCurve.get(), ConstantCurve.of(Curves.sabrParameterByExpiry(NAME.Name + "-Beta", ACT_365F, SABR_BETA), BETA_RHO)); assertEquals(test.DayCount, ACT_365F); assertEquals(test.ExtrapolatorLeft, FLAT); assertEquals(test.ExtrapolatorRight, LINEAR); assertEquals(test.Index, USD_LIBOR_3M); assertEquals(test.InitialParameters, DoubleArray.of(0.1, BETA_RHO, -0.2, 0.5)); assertEquals(test.Interpolator, DOUBLE_QUADRATIC); assertEquals(test.Name, NAME); assertFalse(test.RhoCurve.Present); assertEquals(test.SabrVolatilityFormula, HAGAN); assertEquals(test.ShiftCurve, ConstantCurve.of("Zero shift", 0d)); }
public virtual void test_serialization() { ImmutableMap <Currency, CurveId> discounts = ImmutableMap.of(USD, CURVE_ID_DSC); ImmutableMap <Index, CurveId> forwards = ImmutableMap.of(USD_LIBOR_3M, CURVE_ID_FWD); DefaultRatesMarketDataLookup test = DefaultRatesMarketDataLookup.of(discounts, forwards, ObservableSource.NONE, FxRateLookup.ofRates()); assertSerialization(test); Curve curve = ConstantCurve.of(Curves.discountFactors("DSC", ACT_360), 0.99); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: java.util.Map<? extends com.opengamma.strata.data.MarketDataId<?>, ?> valuesMap = com.google.common.collect.ImmutableMap.of(CURVE_ID_DSC, curve, CURVE_ID_FWD, curve); IDictionary <MarketDataId <object>, ?> valuesMap = ImmutableMap.of(CURVE_ID_DSC, curve, CURVE_ID_FWD, curve); MarketData md = MarketData.of(date(2016, 6, 30), valuesMap); assertSerialization(test.marketDataView(md)); assertSerialization(test.ratesProvider(md)); }
public virtual void test_bondDiscountingProvider() { LocalDate valDate = LocalDate.of(2015, 6, 30); Curve ccAUsd = ConstantNodalCurve.of(Curves.zeroRates(CC_A_USD.CurveName, ACT_365F), 0.5d, 1.5d); Curve ccBGbp = ConstantNodalCurve.of(Curves.zeroRates(CC_B_GBP.CurveName, ACT_365F), 0.5d, 2d); Curve ccAGbp = ConstantNodalCurve.of(Curves.zeroRates(CC_A_GBP.CurveName, ACT_365F), 0.5d, 3d); Curve dcGbp = ConstantNodalCurve.of(Curves.zeroRates(DC_GBP.CurveName, ACT_365F), 0.5d, 0.1d); Curve dcUsd = ConstantNodalCurve.of(Curves.zeroRates(DC_USD.CurveName, ACT_365F), 0.5d, 0.05d); Curve rcA = ConstantCurve.of(Curves.recoveryRates(RC_A.CurveName, ACT_365F), 0.5d); Curve rcB = ConstantCurve.of(Curves.recoveryRates(RC_B.CurveName, ACT_365F), 0.4234d); IDictionary <CurveId, Curve> curveMap = new Dictionary <CurveId, Curve>(); curveMap[CC_A_USD] = ccAUsd; curveMap[CC_B_GBP] = ccBGbp; curveMap[CC_A_GBP] = ccAGbp; curveMap[DC_USD] = dcUsd; curveMap[DC_GBP] = dcGbp; curveMap[RC_A] = rcA; curveMap[RC_B] = rcB; MarketData md = ImmutableMarketData.of(valDate, ImmutableMap.copyOf(curveMap)); CreditRatesProvider provider = LOOKUP_WITH_SOURCE.creditRatesProvider(md); assertEquals(provider.ValuationDate, valDate); assertEquals(provider.findData(CC_A_USD.CurveName), ccAUsd); assertEquals(provider.findData(DC_USD.CurveName), dcUsd); assertEquals(provider.findData(RC_B.CurveName), rcB); assertEquals(provider.findData(CurveName.of("Rubbish")), null); // check credit curve LegalEntitySurvivalProbabilities cc = provider.survivalProbabilities(ISSUER_A, GBP); IsdaCreditDiscountFactors ccUnder = (IsdaCreditDiscountFactors)cc.SurvivalProbabilities; assertEquals(ccUnder.Curve.Name, ccAGbp.Name); assertThrowsRuntime(() => provider.survivalProbabilities(ISSUER_B, USD)); assertThrowsRuntime(() => provider.survivalProbabilities(ISSUER_C, USD)); // check discount curve IsdaCreditDiscountFactors dc = (IsdaCreditDiscountFactors)provider.discountFactors(USD); assertEquals(dc.Curve.Name, dcUsd.Name); assertThrowsRuntime(() => provider.discountFactors(EUR)); // check recovery rate curve ConstantRecoveryRates rc = (ConstantRecoveryRates)provider.recoveryRates(ISSUER_B); assertEquals(rc.RecoveryRate, rcB.getParameter(0)); assertThrowsRuntime(() => provider.recoveryRates(ISSUER_C)); }
public virtual void test_build_fail() { Curve betaCurve = InterpolatedNodalCurve.of(Curves.sabrParameterByExpiry(NAME.Name + "-Beta", ACT_365F, SABR_BETA), DoubleArray.of(2d, 5d), DoubleArray.of(0.5, 0.8), CurveInterpolators.PCHIP); Curve rhoCurve = InterpolatedNodalCurve.of(Curves.sabrParameterByExpiry(NAME.Name + "-Rho", ACT_365F, SABR_RHO), DoubleArray.of(2d, 5d), DoubleArray.of(0.5, 0.8), CurveInterpolators.PCHIP); Curve shiftCurve = ConstantCurve.of("shift curve", 0.03d); DoubleArray initial = DoubleArray.of(0.34, 0.5, -0.22, 1.2); ImmutableList <DoubleArray> knotsEmptyBeta = ImmutableList.of(ALPHA_KNOTS, DoubleArray.of(), BETA_RHO_KNOTS, NU_KNOTS); ImmutableList <DoubleArray> knotsEmptyRho = ImmutableList.of(ALPHA_KNOTS, BETA_RHO_KNOTS, DoubleArray.of(), NU_KNOTS); // beta, rho not set assertThrowsIllegalArg(() => SabrIborCapletFloorletVolatilityCalibrationDefinition.builder().dayCount(ACT_365F).extrapolatorLeft(FLAT).extrapolatorRight(FLAT).interpolator(DOUBLE_QUADRATIC).index(USD_LIBOR_3M).initialParameters(initial).name(NAME).parameterCurveNodes(knotsEmptyBeta).sabrVolatilityFormula(HAGAN).shiftCurve(shiftCurve).build()); // beta set, but rho knots not defined assertThrowsIllegalArg(() => SabrIborCapletFloorletVolatilityCalibrationDefinition.builder().dayCount(ACT_365F).betaCurve(betaCurve).extrapolatorLeft(FLAT).extrapolatorRight(FLAT).interpolator(DOUBLE_QUADRATIC).index(USD_LIBOR_3M).initialParameters(initial).name(NAME).parameterCurveNodes(knotsEmptyRho).sabrVolatilityFormula(HAGAN).shiftCurve(shiftCurve).build()); // beta rho set assertThrowsIllegalArg(() => SabrIborCapletFloorletVolatilityCalibrationDefinition.builder().dayCount(ACT_365F).betaCurve(betaCurve).rhoCurve(rhoCurve).extrapolatorLeft(FLAT).extrapolatorRight(FLAT).interpolator(DOUBLE_QUADRATIC).index(USD_LIBOR_3M).initialParameters(initial).name(NAME).parameterCurveNodes(knotsEmptyBeta).sabrVolatilityFormula(HAGAN).shiftCurve(shiftCurve).build()); // wrong initial value array size assertThrowsIllegalArg(() => SabrIborCapletFloorletVolatilityCalibrationDefinition.builder().dayCount(ACT_365F).betaCurve(betaCurve).extrapolatorLeft(FLAT).extrapolatorRight(FLAT).interpolator(DOUBLE_QUADRATIC).index(USD_LIBOR_3M).initialParameters(DoubleArray.of(0.34, 0.5, -0.22)).name(NAME).parameterCurveNodes(knotsEmptyBeta).sabrVolatilityFormula(HAGAN).shiftCurve(shiftCurve).build()); assertThrowsIllegalArg(() => SabrIborCapletFloorletVolatilityCalibrationDefinition.builder().dayCount(ACT_365F).betaCurve(betaCurve).extrapolatorLeft(FLAT).extrapolatorRight(FLAT).interpolator(DOUBLE_QUADRATIC).index(USD_LIBOR_3M).initialParameters(initial).name(NAME).parameterCurveNodes(ImmutableList.of(ALPHA_KNOTS, BETA_RHO_KNOTS, NU_KNOTS)).sabrVolatilityFormula(HAGAN).shiftCurve(shiftCurve).build()); }
public virtual void test_ratesProvider() { ImmutableMap <Currency, CurveId> discounts = ImmutableMap.of(USD, CURVE_ID_DSC); ImmutableMap <Index, CurveId> forwards = ImmutableMap.of(USD_FED_FUND, CURVE_ID_DSC, USD_LIBOR_3M, CURVE_ID_FWD, US_CPI_U, CURVE_ID_FWD); RatesMarketDataLookup test = RatesMarketDataLookup.of(discounts, forwards); LocalDate valDate = date(2015, 6, 30); Curve dscCurve = ConstantCurve.of(Curves.discountFactors(CURVE_ID_DSC.CurveName, ACT_360), 1d); Curve fwdCurve = ConstantCurve.of(Curves.discountFactors(CURVE_ID_FWD.CurveName, ACT_360), 2d); MarketData md = ImmutableMarketData.of(valDate, ImmutableMap.of(CURVE_ID_DSC, dscCurve, CURVE_ID_FWD, fwdCurve)); RatesProvider ratesProvider = test.ratesProvider(md); assertEquals(ratesProvider.ValuationDate, valDate); assertEquals(ratesProvider.findData(CURVE_ID_DSC.CurveName), dscCurve); assertEquals(ratesProvider.findData(CURVE_ID_FWD.CurveName), fwdCurve); assertEquals(ratesProvider.findData(CurveName.of("Rubbish")), null); assertEquals(ratesProvider.IborIndices, ImmutableSet.of(USD_LIBOR_3M)); assertEquals(ratesProvider.OvernightIndices, ImmutableSet.of(USD_FED_FUND)); assertEquals(ratesProvider.PriceIndices, ImmutableSet.of(US_CPI_U)); assertEquals(ratesProvider.TimeSeriesIndices, ImmutableSet.of()); // check discount factors SimpleDiscountFactors df = (SimpleDiscountFactors)ratesProvider.discountFactors(USD); assertEquals(df.Curve.Name, dscCurve.Name); assertThrowsIllegalArg(() => ratesProvider.discountFactors(GBP)); // check Ibor DiscountIborIndexRates ibor = (DiscountIborIndexRates)ratesProvider.iborIndexRates(USD_LIBOR_3M); SimpleDiscountFactors iborDf = (SimpleDiscountFactors)ibor.DiscountFactors; assertEquals(iborDf.Curve.Name, fwdCurve.Name); assertThrowsIllegalArg(() => ratesProvider.iborIndexRates(GBP_LIBOR_3M)); // check Overnight DiscountOvernightIndexRates on = (DiscountOvernightIndexRates)ratesProvider.overnightIndexRates(USD_FED_FUND); SimpleDiscountFactors onDf = (SimpleDiscountFactors)on.DiscountFactors; assertEquals(onDf.Curve.Name, dscCurve.Name); assertThrowsIllegalArg(() => ratesProvider.overnightIndexRates(GBP_SONIA)); // check price curve must be interpolated assertThrowsIllegalArg(() => ratesProvider.priceIndexValues(US_CPI_U)); // to immutable ImmutableRatesProvider expectedImmutable = ImmutableRatesProvider.builder(valDate).fxRateProvider(MarketDataFxRateProvider.of(md)).discountCurve(USD, dscCurve).indexCurve(USD_FED_FUND, dscCurve).indexCurve(USD_LIBOR_3M, fwdCurve).indexCurve(US_CPI_U, fwdCurve).build(); assertEquals(ratesProvider.toImmutableRatesProvider(), expectedImmutable); }
public virtual void test_builder() { Curve betaCurve = InterpolatedNodalCurve.of(Curves.sabrParameterByExpiry(NAME.Name + "-Beta", ACT_365F, SABR_BETA), DoubleArray.of(2d, 5d), DoubleArray.of(0.5, 0.8), CurveInterpolators.PCHIP); Curve shiftCurve = ConstantCurve.of("shift curve", 0.03d); DoubleArray initial = DoubleArray.of(0.34, 0.5, -0.22, 1.2); ImmutableList <DoubleArray> knots = ImmutableList.of(ALPHA_KNOTS, DoubleArray.of(), BETA_RHO_KNOTS, NU_KNOTS); SabrIborCapletFloorletVolatilityCalibrationDefinition test = SabrIborCapletFloorletVolatilityCalibrationDefinition.builder().betaCurve(betaCurve).dayCount(ACT_365F).extrapolatorLeft(FLAT).extrapolatorRight(FLAT).interpolator(DOUBLE_QUADRATIC).index(USD_LIBOR_3M).initialParameters(initial).name(NAME).parameterCurveNodes(knots).sabrVolatilityFormula(HAGAN).shiftCurve(shiftCurve).build(); assertEquals(test.BetaCurve.get(), betaCurve); assertEquals(test.DayCount, ACT_365F); assertEquals(test.ExtrapolatorLeft, FLAT); assertEquals(test.ExtrapolatorRight, FLAT); assertEquals(test.Index, USD_LIBOR_3M); assertEquals(test.InitialParameters, initial); assertEquals(test.Interpolator, DOUBLE_QUADRATIC); assertEquals(test.Name, NAME); assertFalse(test.RhoCurve.Present); assertEquals(test.SabrVolatilityFormula, HAGAN); assertEquals(test.ShiftCurve, shiftCurve); }
//------------------------------------------------------------------------- public virtual void coverage() { coverImmutableBean(VOLS); ShiftedBlackIborCapletFloorletExpiryStrikeVolatilities vols = ShiftedBlackIborCapletFloorletExpiryStrikeVolatilities.of(USD_LIBOR_3M, VAL_DATE_TIME.plusMonths(1), InterpolatedNodalSurface.of(METADATA, TIME, STRIKE, VOL, GridSurfaceInterpolator.of(TIME_SQUARE, LINEAR)), ConstantCurve.of("shift", 0.05)); coverBeanEquals(VOLS, vols); }
public virtual void recovery_test_blackSurface_shift() { SurfaceIborCapletFloorletVolatilityBootstrapDefinition definition = SurfaceIborCapletFloorletVolatilityBootstrapDefinition.of(IborCapletFloorletVolatilitiesName.of("test"), USD_LIBOR_3M, ACT_ACT_ISDA, LINEAR, LINEAR, ConstantCurve.of("Black shift", 0.02)); DoubleArray strikes = createBlackStrikes(); RawOptionData data = RawOptionData.of(createBlackMaturities(), strikes, ValueType.STRIKE, createFullBlackDataMatrix(), ValueType.BLACK_VOLATILITY); IborCapletFloorletVolatilityCalibrationResult res = CALIBRATOR.calibrate(definition, CALIBRATION_TIME, data, RATES_PROVIDER); ShiftedBlackIborCapletFloorletExpiryStrikeVolatilities resVol = (ShiftedBlackIborCapletFloorletExpiryStrikeVolatilities)res.Volatilities; for (int i = 0; i < strikes.size(); ++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_BLACK.presentValue(caps[j], RATES_PROVIDER, resVol).Amount; assertEquals(priceOrg, priceCalib, Math.Max(priceOrg, 1d) * TOL); } } assertEquals(res.ChiSquare, 0d); assertEquals(resVol.Index, USD_LIBOR_3M); assertEquals(resVol.Name, definition.Name); assertEquals(resVol.ValuationDateTime, CALIBRATION_TIME); assertEquals(resVol.ShiftCurve, definition.ShiftCurve.get()); InterpolatedNodalSurface surface = (InterpolatedNodalSurface)resVol.Surface; for (int i = 0; i < surface.ParameterCount; ++i) { GenericVolatilitySurfacePeriodParameterMetadata metadata = (GenericVolatilitySurfacePeriodParameterMetadata)surface.getParameterMetadata(i); assertEquals(metadata.Strike.Value + 0.02, surface.YValues.get(i)); } }
public virtual void recovery_test_normal2_shift() { SurfaceIborCapletFloorletVolatilityBootstrapDefinition definition = SurfaceIborCapletFloorletVolatilityBootstrapDefinition.of(IborCapletFloorletVolatilitiesName.of("test"), USD_LIBOR_3M, ACT_ACT_ISDA, LINEAR, DOUBLE_QUADRATIC, ConstantCurve.of("Black shift", 0.02)); DoubleArray strikes = createNormalEquivStrikes(); RawOptionData data = RawOptionData.of(createNormalEquivMaturities(), strikes, ValueType.STRIKE, createFullNormalEquivDataMatrix(), ValueType.NORMAL_VOLATILITY); IborCapletFloorletVolatilityCalibrationResult res = CALIBRATOR.calibrate(definition, CALIBRATION_TIME, data, RATES_PROVIDER); ShiftedBlackIborCapletFloorletExpiryStrikeVolatilities resVol = (ShiftedBlackIborCapletFloorletExpiryStrikeVolatilities)res.Volatilities; for (int i = 0; i < strikes.size(); ++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_BLACK.presentValue(caps[j], RATES_PROVIDER, resVol).Amount; assertEquals(priceOrg, priceCalib, Math.Max(priceOrg, 1d) * TOL); } } assertEquals(res.ChiSquare, 0d); }
//------------------------------------------------------------------------- internal static ScenarioMarketData marketData() { Curve curve = ConstantCurve.of(Curves.discountFactors("Test", ACT_360), 0.99); return(new TestMarketDataMap(VAL_DATE, ImmutableMap.of(REPO_CURVE_ID, curve, ISSUER_CURVE_ID, curve, QUOTE_ID, SETTLE_PRICE * 100, VOLS_ID, VOLS), ImmutableMap.of())); }