Beispiel #1
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);
        }
Beispiel #2
0
        //-------------------------------------------------------------------------
        public virtual void test_currencyExposure()
        {
            double eps = 1.0e-14;
            ImmutableRatesProvider prov = ImmutableRatesProvider.builder(VAL_DATE).fxRateProvider(FX_MATRIX).discountCurve(GBP, DISCOUNT_CURVE_GBP).discountCurve(USD, DISCOUNT_CURVE_USD).build();
            DiscountingFxResetNotionalExchangePricer test = new DiscountingFxResetNotionalExchangePricer();
            // USD
            MultiCurrencyAmount computedUSD = test.currencyExposure(FX_RESET_NOTIONAL_EXCHANGE_REC_USD, prov);
            PointSensitivities  pointUSD    = test.presentValueSensitivity(FX_RESET_NOTIONAL_EXCHANGE_REC_USD, prov).build();
            MultiCurrencyAmount expectedUSD = prov.currencyExposure(pointUSD.convertedTo(USD, prov)).plus(CurrencyAmount.of(FX_RESET_NOTIONAL_EXCHANGE_REC_USD.Currency, test.presentValue(FX_RESET_NOTIONAL_EXCHANGE_REC_USD, prov)));

            assertFalse(computedUSD.contains(GBP));     // 0 GBP
            assertEquals(computedUSD.getAmount(USD).Amount, expectedUSD.getAmount(USD).Amount, eps * NOTIONAL);
            // GBP
            MultiCurrencyAmount computedGBP = test.currencyExposure(FX_RESET_NOTIONAL_EXCHANGE_PAY_GBP, prov);
            PointSensitivities  pointGBP    = test.presentValueSensitivity(FX_RESET_NOTIONAL_EXCHANGE_PAY_GBP, prov).build();
            MultiCurrencyAmount expectedGBP = prov.currencyExposure(pointGBP.convertedTo(GBP, prov)).plus(CurrencyAmount.of(FX_RESET_NOTIONAL_EXCHANGE_PAY_GBP.Currency, test.presentValue(FX_RESET_NOTIONAL_EXCHANGE_PAY_GBP, 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(VAL_DATE).fxRateProvider(fxMatrixUp).discountCurve(GBP, DISCOUNT_CURVE_GBP).discountCurve(USD, DISCOUNT_CURVE_USD).build();
            double expectedFdUSD          = -(test.presentValue(FX_RESET_NOTIONAL_EXCHANGE_REC_USD, provUp) - test.presentValue(FX_RESET_NOTIONAL_EXCHANGE_REC_USD, prov)) * FX_RATE * FX_RATE / EPS_FD;

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

            assertEquals(computedGBP.getAmount(GBP).Amount, expectedFdGBP, EPS_FD * NOTIONAL);
        }
Beispiel #3
0
        public virtual void test_explainPresentValue_paymentDateInPast()
        {
            SimpleRatesProvider prov = createProvider(FX_RESET_NOTIONAL_EXCHANGE_REC_USD);

            prov.ValuationDate = VAL_DATE.plusYears(1);

            DiscountingFxResetNotionalExchangePricer test = new DiscountingFxResetNotionalExchangePricer();
            ExplainMapBuilder builder = ExplainMap.builder();

            test.explainPresentValue(FX_RESET_NOTIONAL_EXCHANGE_REC_USD, prov, builder);
            ExplainMap explain = builder.build();

            Currency paymentCurrency  = FX_RESET_NOTIONAL_EXCHANGE_REC_USD.Currency;
            Currency notionalCurrency = FX_RESET_NOTIONAL_EXCHANGE_REC_USD.ReferenceCurrency;
            double   notional         = FX_RESET_NOTIONAL_EXCHANGE_REC_USD.Notional;

            assertEquals(explain.get(ExplainKey.ENTRY_TYPE).get(), "FxResetNotionalExchange");
            assertEquals(explain.get(ExplainKey.PAYMENT_DATE).get(), FX_RESET_NOTIONAL_EXCHANGE_REC_USD.PaymentDate);
            assertEquals(explain.get(ExplainKey.PAYMENT_CURRENCY).get(), paymentCurrency);
            assertEquals(explain.get(ExplainKey.TRADE_NOTIONAL).get().Currency, notionalCurrency);
            assertEquals(explain.get(ExplainKey.TRADE_NOTIONAL).get().Amount, notional, TOLERANCE);
            assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().Currency, paymentCurrency);
            assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().Amount, 0d, TOLERANCE);
            assertEquals(explain.get(ExplainKey.PRESENT_VALUE).get().Currency, paymentCurrency);
            assertEquals(explain.get(ExplainKey.PRESENT_VALUE).get().Amount, 0d * DISCOUNT_FACTOR, TOLERANCE);
        }
Beispiel #4
0
        public virtual void test_currentCash_zero()
        {
            ImmutableRatesProvider prov = ImmutableRatesProvider.builder(VAL_DATE).fxRateProvider(FX_MATRIX).discountCurve(GBP, DISCOUNT_CURVE_GBP).discountCurve(USD, DISCOUNT_CURVE_USD).build();
            DiscountingFxResetNotionalExchangePricer test = new DiscountingFxResetNotionalExchangePricer();
            double cc = test.currentCash(FX_RESET_NOTIONAL_EXCHANGE_REC_USD, prov);

            assertEquals(cc, 0d);
        }
Beispiel #5
0
        //-------------------------------------------------------------------------
        public virtual void test_forecastValue()
        {
            SimpleRatesProvider prov = createProvider(FX_RESET_NOTIONAL_EXCHANGE_REC_USD);

            DiscountingFxResetNotionalExchangePricer test = new DiscountingFxResetNotionalExchangePricer();
            double calculated = test.forecastValue(FX_RESET_NOTIONAL_EXCHANGE_REC_USD, prov);

            assertEquals(calculated, FX_RESET_NOTIONAL_EXCHANGE_REC_USD.Notional * FX_RATE, 0d);
        }
Beispiel #6
0
        public virtual void test_currentCash_onPayment()
        {
            double eps = 1.0e-14;
            ImmutableRatesProvider prov = ImmutableRatesProvider.builder(FX_RESET_NOTIONAL_EXCHANGE_REC_USD.PaymentDate).fxRateProvider(FX_MATRIX).discountCurve(GBP, DISCOUNT_CURVE_GBP).discountCurve(USD, DISCOUNT_CURVE_USD).build();
            DiscountingFxResetNotionalExchangePricer test = new DiscountingFxResetNotionalExchangePricer();
            double rate  = prov.fxIndexRates(FX_RESET_NOTIONAL_EXCHANGE_REC_USD.Observation.Index).rate(FX_RESET_NOTIONAL_EXCHANGE_REC_USD.Observation, FX_RESET_NOTIONAL_EXCHANGE_REC_USD.ReferenceCurrency);
            double ccUSD = test.currentCash(FX_RESET_NOTIONAL_EXCHANGE_REC_USD, prov);

            assertEquals(ccUSD, NOTIONAL * rate, eps);
            double ccGBP = test.currentCash(FX_RESET_NOTIONAL_EXCHANGE_PAY_GBP, prov);

            assertEquals(ccGBP, -NOTIONAL / rate, eps);
        }
Beispiel #7
0
        //-------------------------------------------------------------------------
        public virtual void test_forecastValueSensitivity()
        {
            ImmutableRatesProvider prov = ImmutableRatesProvider.builder(VAL_DATE).fxRateProvider(FX_MATRIX).discountCurve(GBP, DISCOUNT_CURVE_GBP).discountCurve(USD, DISCOUNT_CURVE_USD).build();

            FxResetNotionalExchange[] expanded = new FxResetNotionalExchange[] { FX_RESET_NOTIONAL_EXCHANGE_REC_USD, FX_RESET_NOTIONAL_EXCHANGE_PAY_GBP };
            for (int i = 0; i < 2; ++i)
            {
                FxResetNotionalExchange fxReset = expanded[i];
                DiscountingFxResetNotionalExchangePricer test = new DiscountingFxResetNotionalExchangePricer();

                PointSensitivityBuilder        pointSensitivityComputed     = test.forecastValueSensitivity(expanded[i], prov);
                CurrencyParameterSensitivities parameterSensitivityComputed = prov.parameterSensitivity(pointSensitivityComputed.build());
                CurrencyParameterSensitivities parameterSensitivityExpected = FD_CALCULATOR.sensitivity(prov, (p) => CurrencyAmount.of(fxReset.Currency, test.forecastValue(fxReset, (p))));
                assertTrue(parameterSensitivityComputed.equalWithTolerance(parameterSensitivityExpected, Math.Abs(expanded[i].Notional) * EPS_FD * 10.0));
            }
        }