Пример #1
0
        public virtual void test_explainPresentValue_paymentDateInPast()
        {
            SimpleRatesProvider prov = createProvider(NOTIONAL_EXCHANGE_REC_GBP);

            prov.ValuationDate = VAL_DATE.plusYears(1);

            DiscountingNotionalExchangePricer test = DiscountingNotionalExchangePricer.DEFAULT;
            ExplainMapBuilder builder = ExplainMap.builder();

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

            Currency       currency = NOTIONAL_EXCHANGE_REC_GBP.Currency;
            CurrencyAmount notional = NOTIONAL_EXCHANGE_REC_GBP.PaymentAmount;

            assertEquals(explain.get(ExplainKey.ENTRY_TYPE).get(), "NotionalExchange");
            assertEquals(explain.get(ExplainKey.PAYMENT_DATE).get(), NOTIONAL_EXCHANGE_REC_GBP.PaymentDate);
            assertEquals(explain.get(ExplainKey.PAYMENT_CURRENCY).get(), currency);
            assertEquals(explain.get(ExplainKey.TRADE_NOTIONAL).get().Currency, currency);
            assertEquals(explain.get(ExplainKey.TRADE_NOTIONAL).get().Amount, notional.Amount, TOLERANCE);
            assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().Currency, currency);
            assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().Amount, 0d, TOLERANCE);
            assertEquals(explain.get(ExplainKey.PRESENT_VALUE).get().Currency, currency);
            assertEquals(explain.get(ExplainKey.PRESENT_VALUE).get().Amount, 0d * DISCOUNT_FACTOR, TOLERANCE);
        }
Пример #2
0
        public virtual void test_currentCash_zero()
        {
            ImmutableRatesProvider            prov = ImmutableRatesProvider.builder(VAL_DATE).discountCurve(GBP, DISCOUNT_CURVE_GBP).build();
            DiscountingNotionalExchangePricer test = DiscountingNotionalExchangePricer.DEFAULT;
            double computed = test.currentCash(NOTIONAL_EXCHANGE_REC_GBP, prov);

            assertEquals(computed, 0d);
        }
Пример #3
0
        public virtual void test_forecastValue()
        {
            SimpleRatesProvider prov = createProvider(NOTIONAL_EXCHANGE_REC_GBP);

            DiscountingNotionalExchangePricer test = DiscountingNotionalExchangePricer.DEFAULT;
            double calculated = test.forecastValue(NOTIONAL_EXCHANGE_REC_GBP, prov);

            assertEquals(calculated, NOTIONAL_EXCHANGE_REC_GBP.PaymentAmount.Amount, 0d);
        }
Пример #4
0
        public virtual void test_currentCash_onPayment()
        {
            ImmutableRatesProvider            prov = ImmutableRatesProvider.builder(NOTIONAL_EXCHANGE_REC_GBP.PaymentDate).discountCurve(GBP, DISCOUNT_CURVE_GBP).build();
            DiscountingNotionalExchangePricer test = DiscountingNotionalExchangePricer.DEFAULT;
            double notional = NOTIONAL_EXCHANGE_REC_GBP.PaymentAmount.Amount;
            double computed = test.currentCash(NOTIONAL_EXCHANGE_REC_GBP, prov);

            assertEquals(computed, notional);
        }
Пример #5
0
        //-------------------------------------------------------------------------
        public virtual void test_currencyExposure()
        {
            ImmutableRatesProvider            prov = ImmutableRatesProvider.builder(VAL_DATE).discountCurve(GBP, DISCOUNT_CURVE_GBP).build();
            DiscountingNotionalExchangePricer test = DiscountingNotionalExchangePricer.DEFAULT;
            MultiCurrencyAmount computed           = test.currencyExposure(NOTIONAL_EXCHANGE_REC_GBP, prov);
            PointSensitivities  point    = test.presentValueSensitivity(NOTIONAL_EXCHANGE_REC_GBP, prov).build();
            MultiCurrencyAmount expected = prov.currencyExposure(point).plus(CurrencyAmount.of(NOTIONAL_EXCHANGE_REC_GBP.Currency, test.presentValue(NOTIONAL_EXCHANGE_REC_GBP, prov)));

            assertEquals(computed, expected);
        }
Пример #6
0
        //-------------------------------------------------------------------------
        public virtual void test_presentValueSensitivity()
        {
            SimpleRatesProvider prov = createProvider(NOTIONAL_EXCHANGE_REC_GBP);

            DiscountingNotionalExchangePricer test = DiscountingNotionalExchangePricer.DEFAULT;
            PointSensitivities senseComputed       = test.presentValueSensitivity(NOTIONAL_EXCHANGE_REC_GBP, prov).build();

            double             eps           = 1.0e-7;
            PointSensitivities senseExpected = PointSensitivities.of(dscSensitivityFD(prov, NOTIONAL_EXCHANGE_REC_GBP, eps));

            assertTrue(senseComputed.equalWithTolerance(senseExpected, NOTIONAL_EXCHANGE_REC_GBP.PaymentAmount.Amount * eps));
        }
Пример #7
0
        private IList <ZeroRateSensitivity> dscSensitivityFD(RatesProvider provider, NotionalExchange @event, double eps)
        {
            Currency      currency       = @event.Currency;
            LocalDate     paymentDate    = @event.PaymentDate;
            double        discountFactor = provider.discountFactor(currency, paymentDate);
            double        paymentTime    = DAY_COUNT.relativeYearFraction(VAL_DATE, paymentDate);
            RatesProvider provUp         = mock(typeof(RatesProvider));
            RatesProvider provDw         = mock(typeof(RatesProvider));

            when(provUp.ValuationDate).thenReturn(VAL_DATE);
            when(provUp.discountFactor(currency, paymentDate)).thenReturn(discountFactor * Math.Exp(-eps * paymentTime));
            when(provDw.ValuationDate).thenReturn(VAL_DATE);
            when(provDw.discountFactor(currency, paymentDate)).thenReturn(discountFactor * Math.Exp(eps * paymentTime));
            DiscountingNotionalExchangePricer pricer = DiscountingNotionalExchangePricer.DEFAULT;
            double pvUp = pricer.presentValue(@event, provUp);
            double pvDw = pricer.presentValue(@event, provDw);
            double res  = 0.5 * (pvUp - pvDw) / eps;
            IList <ZeroRateSensitivity> zeroRateSensi = new List <ZeroRateSensitivity>();

            zeroRateSensi.Add(ZeroRateSensitivity.of(currency, paymentTime, res));
            return(zeroRateSensi);
        }