public virtual void pointAndParameterFx()
        {
            ImmutableRatesProvider test        = ImmutableRatesProvider.builder(VAL_DATE).fxRateProvider(FX_MATRIX).discountCurve(GBP, DISCOUNT_CURVE_GBP).discountCurve(USD, DISCOUNT_CURVE_USD).build();
            ImmutableRatesProvider test_gbp_up = ImmutableRatesProvider.builder(VAL_DATE).fxRateProvider(FX_MATRIX).discountCurve(GBP, DISCOUNT_CURVE_GBP_UP).discountCurve(USD, DISCOUNT_CURVE_USD).build();
            ImmutableRatesProvider test_gbp_dw = ImmutableRatesProvider.builder(VAL_DATE).fxRateProvider(FX_MATRIX).discountCurve(GBP, DISCOUNT_CURVE_GBP_DOWN).discountCurve(USD, DISCOUNT_CURVE_USD).build();
            ImmutableRatesProvider test_usd_up = ImmutableRatesProvider.builder(VAL_DATE).fxRateProvider(FX_MATRIX).discountCurve(GBP, DISCOUNT_CURVE_GBP).discountCurve(USD, DISCOUNT_CURVE_USD_UP).build();
            ImmutableRatesProvider test_usd_dw = ImmutableRatesProvider.builder(VAL_DATE).fxRateProvider(FX_MATRIX).discountCurve(GBP, DISCOUNT_CURVE_GBP).discountCurve(USD, DISCOUNT_CURVE_USD_DOWN).build();
            LocalDate matuirtyDate             = GBP_USD_WM.calculateMaturityFromFixing(VAL_DATE, REF_DATA);
            double    maturityTime             = DAY_COUNT.relativeYearFraction(VAL_DATE, matuirtyDate);
            // GBP based
            FxIndexObservation      obs = FxIndexObservation.of(GBP_USD_WM, VAL_DATE, REF_DATA);
            PointSensitivityBuilder sensiBuildCmpGBP = test.fxIndexRates(GBP_USD_WM).ratePointSensitivity(obs, GBP);
            FxIndexSensitivity      sensiBuildExpGBP = FxIndexSensitivity.of(obs, GBP, USD, 1.0);

            assertTrue(sensiBuildCmpGBP.Equals(sensiBuildExpGBP));
            double sense_gbp1 = 0.5 * (test_gbp_up.fxIndexRates(GBP_USD_WM).rate(obs, GBP) - test_gbp_dw.fxIndexRates(GBP_USD_WM).rate(obs, GBP)) / EPS_FD * (-maturityTime * GBP_DSC);
            double sense_usd1 = 0.5 * (test_usd_up.fxIndexRates(GBP_USD_WM).rate(obs, GBP) - test_usd_dw.fxIndexRates(GBP_USD_WM).rate(obs, GBP)) / EPS_FD * (-maturityTime * USD_DSC);
            PointSensitivityBuilder sensiBuildDecGBP = ZeroRateSensitivity.of(GBP, maturityTime, USD, sense_gbp1);

            sensiBuildDecGBP = sensiBuildDecGBP.combinedWith(ZeroRateSensitivity.of(USD, maturityTime, USD, sense_usd1));
            CurrencyParameterSensitivities paramSensiCmpGBP = test.parameterSensitivity(sensiBuildCmpGBP.build().normalized());
            CurrencyParameterSensitivities paramSensiExpGBP = test.parameterSensitivity(sensiBuildDecGBP.build().normalized());

            assertTrue(paramSensiCmpGBP.equalWithTolerance(paramSensiExpGBP, EPS_FD));
            // USD based
            PointSensitivityBuilder sensiBuildCmpUSD = test.fxIndexRates(GBP_USD_WM).ratePointSensitivity(obs, USD);
            FxIndexSensitivity      sensiBuildExpUSD = FxIndexSensitivity.of(obs, USD, GBP, 1.0);

            assertTrue(sensiBuildCmpUSD.Equals(sensiBuildExpUSD));
            double sense_gbp2 = 0.5 * (test_gbp_up.fxIndexRates(GBP_USD_WM).rate(obs, USD) - test_gbp_dw.fxIndexRates(GBP_USD_WM).rate(obs, USD)) / EPS_FD * (-maturityTime * GBP_DSC);
            double sense_usd2 = 0.5 * (test_usd_up.fxIndexRates(GBP_USD_WM).rate(obs, USD) - test_usd_dw.fxIndexRates(GBP_USD_WM).rate(obs, USD)) / EPS_FD * (-maturityTime * USD_DSC);
            PointSensitivityBuilder sensiBuildDecUSD = ZeroRateSensitivity.of(GBP, maturityTime, GBP, sense_gbp2);

            sensiBuildDecUSD = sensiBuildDecUSD.combinedWith(ZeroRateSensitivity.of(USD, maturityTime, GBP, sense_usd2));
            CurrencyParameterSensitivities paramSensiCmpUSD = test.parameterSensitivity(sensiBuildCmpUSD.build().normalized());
            CurrencyParameterSensitivities paramSensiExpUSD = test.parameterSensitivity(sensiBuildDecUSD.build().normalized());

            assertTrue(paramSensiCmpUSD.equalWithTolerance(paramSensiExpUSD, EPS_FD));
        }
Exemple #2
0
        public virtual void test_currencyExposureOnFixing_noTimeSeries()
        {
            double    eps           = 1.0e-14;
            LocalDate valuationDate = date(2014, 6, 27);
            LocalDate paymentDate   = date(2014, 7, 1);
            LocalDate fixingDate    = date(2014, 6, 27);
            FxResetNotionalExchange resetNotionalUSD      = FxResetNotionalExchange.of(CurrencyAmount.of(USD, NOTIONAL), paymentDate, FxIndexObservation.of(GBP_USD_WM, fixingDate, REF_DATA));
            FxResetNotionalExchange resetNotionalGBP      = FxResetNotionalExchange.of(CurrencyAmount.of(GBP, -NOTIONAL), paymentDate, FxIndexObservation.of(GBP_USD_WM, fixingDate, REF_DATA));
            ImmutableRatesProvider  prov                  = ImmutableRatesProvider.builder(valuationDate).fxRateProvider(FX_MATRIX).discountCurve(GBP, DISCOUNT_CURVE_GBP).discountCurve(USD, DISCOUNT_CURVE_USD).build();
            DiscountingFxResetNotionalExchangePricer test = new DiscountingFxResetNotionalExchangePricer();
            // USD
            MultiCurrencyAmount computedUSD = test.currencyExposure(resetNotionalUSD, prov);
            PointSensitivities  pointUSD    = test.presentValueSensitivity(resetNotionalUSD, prov).build();
            MultiCurrencyAmount expectedUSD = prov.currencyExposure(pointUSD.convertedTo(USD, prov)).plus(CurrencyAmount.of(resetNotionalUSD.Currency, test.presentValue(resetNotionalUSD, prov)));

            assertFalse(computedUSD.contains(GBP));     // 0 GBP
            assertEquals(computedUSD.getAmount(USD).Amount, expectedUSD.getAmount(USD).Amount, eps * NOTIONAL);
            // GBP
            MultiCurrencyAmount computedGBP = test.currencyExposure(resetNotionalGBP, prov);
            PointSensitivities  pointGBP    = test.presentValueSensitivity(resetNotionalGBP, prov).build();
            MultiCurrencyAmount expectedGBP = prov.currencyExposure(pointGBP.convertedTo(GBP, prov)).plus(CurrencyAmount.of(resetNotionalGBP.Currency, test.presentValue(resetNotionalGBP, prov)));

            assertFalse(computedGBP.contains(USD));     // 0 USD
            assertEquals(computedGBP.getAmount(GBP).Amount, expectedGBP.getAmount(GBP).Amount, eps * NOTIONAL);
            // FD approximation
            FxMatrix fxMatrixUp           = FxMatrix.of(GBP, USD, FX_RATE + EPS_FD);
            ImmutableRatesProvider provUp = ImmutableRatesProvider.builder(valuationDate).fxRateProvider(fxMatrixUp).discountCurve(GBP, DISCOUNT_CURVE_GBP).discountCurve(USD, DISCOUNT_CURVE_USD).build();
            double expectedFdUSD          = -(test.presentValue(resetNotionalUSD, provUp) - test.presentValue(resetNotionalUSD, prov)) * FX_RATE * FX_RATE / EPS_FD;

            assertEquals(computedUSD.getAmount(USD).Amount, expectedFdUSD, EPS_FD * NOTIONAL);
            double expectedFdGBP = (test.presentValue(resetNotionalGBP, provUp) - test.presentValue(resetNotionalGBP, prov)) / EPS_FD;

            assertEquals(computedGBP.getAmount(GBP).Amount, expectedFdGBP, EPS_FD * NOTIONAL);
        }
        //-------------------------------------------------------------------------
        public ResolvedFxNdf resolve(ReferenceData refData)
        {
            LocalDate fixingDate = index.calculateFixingFromMaturity(paymentDate, refData);

            return(ResolvedFxNdf.builder().settlementCurrencyNotional(settlementCurrencyNotional).agreedFxRate(agreedFxRate).observation(FxIndexObservation.of(index, fixingDate, refData)).paymentDate(paymentDate).build());
        }