public void test_of() { NotionalExchange test = NotionalExchange.of(GBP_1000, DATE_2014_06_30); assertEquals(test.getPayment(), Payment.of(GBP_1000, DATE_2014_06_30)); assertEquals(test.getPaymentDate(), DATE_2014_06_30); assertEquals(test.getPaymentAmount(), GBP_1000); assertEquals(test.getCurrency(), GBP); }
public void test_of_Payment() { NotionalExchange test = NotionalExchange.of(Payment.of(GBP_1000, DATE_2014_06_30)); assertEquals(test.getPayment(), Payment.of(GBP_1000, DATE_2014_06_30)); assertEquals(test.getPaymentDate(), DATE_2014_06_30); assertEquals(test.getPaymentAmount(), GBP_1000); assertEquals(test.getCurrency(), GBP); }
private SimpleRatesProvider createProvider(NotionalExchange ne) { LocalDate paymentDate = ne.getPaymentDate(); double paymentTime = DAY_COUNT.relativeYearFraction(VAL_DATE, paymentDate); Currency currency = ne.getCurrency(); DiscountFactors mockDf = mock(DiscountFactors.class); when(mockDf.discountFactor(paymentDate)).thenReturn(DISCOUNT_FACTOR); ZeroRateSensitivity sens = ZeroRateSensitivity.of(currency, paymentTime, -DISCOUNT_FACTOR * paymentTime); when(mockDf.zeroRatePointSensitivity(paymentDate)).thenReturn(sens); SimpleRatesProvider prov = new SimpleRatesProvider(VAL_DATE, mockDf); prov.setDayCount(DAY_COUNT); return prov; }
private List<ZeroRateSensitivity> dscSensitivityFD(RatesProvider provider, NotionalExchange event, double eps) { Currency currency = event.getCurrency(); LocalDate paymentDate = event.getPaymentDate(); double discountFactor = provider.discountFactor(currency, paymentDate); double paymentTime = DAY_COUNT.relativeYearFraction(VAL_DATE, paymentDate); RatesProvider provUp = mock(RatesProvider.class); RatesProvider provDw = mock(RatesProvider.class); when(provUp.getValuationDate()).thenReturn(VAL_DATE); when(provUp.discountFactor(currency, paymentDate)).thenReturn(discountFactor * Math.exp(-eps * paymentTime)); when(provDw.getValuationDate()).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; List<ZeroRateSensitivity> zeroRateSensi = new ArrayList<>(); zeroRateSensi.add(ZeroRateSensitivity.of(currency, paymentTime, res)); return zeroRateSensi; }
public void test_explainPresentValue() { SimpleRatesProvider prov = createProvider(NOTIONAL_EXCHANGE_REC_GBP); 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.getCurrency(); CurrencyAmount notional = NOTIONAL_EXCHANGE_REC_GBP.getPaymentAmount(); assertEquals(explain.get(ExplainKey.ENTRY_TYPE).get(), "NotionalExchange"); assertEquals(explain.get(ExplainKey.PAYMENT_DATE).get(), NOTIONAL_EXCHANGE_REC_GBP.getPaymentDate()); assertEquals(explain.get(ExplainKey.PAYMENT_CURRENCY).get(), currency); assertEquals(explain.get(ExplainKey.TRADE_NOTIONAL).get().getCurrency(), currency); assertEquals(explain.get(ExplainKey.TRADE_NOTIONAL).get().getAmount(), notional.getAmount(), TOLERANCE); assertEquals(explain.get(ExplainKey.DISCOUNT_FACTOR).get(), DISCOUNT_FACTOR, TOLERANCE); assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().getCurrency(), currency); assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().getAmount(), notional.getAmount(), TOLERANCE); assertEquals(explain.get(ExplainKey.PRESENT_VALUE).get().getCurrency(), currency); assertEquals(explain.get(ExplainKey.PRESENT_VALUE).get().getAmount(), notional.getAmount() * DISCOUNT_FACTOR, TOLERANCE); }
public void test_explainPresentValue_paymentDateInPast() { SimpleRatesProvider prov = createProvider(NOTIONAL_EXCHANGE_REC_GBP); prov.setValuationDate(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.getCurrency(); CurrencyAmount notional = NOTIONAL_EXCHANGE_REC_GBP.getPaymentAmount(); assertEquals(explain.get(ExplainKey.ENTRY_TYPE).get(), "NotionalExchange"); assertEquals(explain.get(ExplainKey.PAYMENT_DATE).get(), NOTIONAL_EXCHANGE_REC_GBP.getPaymentDate()); assertEquals(explain.get(ExplainKey.PAYMENT_CURRENCY).get(), currency); assertEquals(explain.get(ExplainKey.TRADE_NOTIONAL).get().getCurrency(), currency); assertEquals(explain.get(ExplainKey.TRADE_NOTIONAL).get().getAmount(), notional.getAmount(), TOLERANCE); assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().getCurrency(), currency); assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().getAmount(), 0d, TOLERANCE); assertEquals(explain.get(ExplainKey.PRESENT_VALUE).get().getCurrency(), currency); assertEquals(explain.get(ExplainKey.PRESENT_VALUE).get().getAmount(), 0d * DISCOUNT_FACTOR, TOLERANCE); }
public 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.getCurrency(), test.presentValue(NOTIONAL_EXCHANGE_REC_GBP, prov))); assertEquals(computed, expected); }
@Override public void explainPresentValue(NotionalExchange event, RatesProvider provider, ExplainMapBuilder builder) { Currency currency = event.getCurrency(); LocalDate paymentDate = event.getPaymentDate(); builder.put(ExplainKey.ENTRY_TYPE, "NotionalExchange"); builder.put(ExplainKey.PAYMENT_DATE, paymentDate); builder.put(ExplainKey.PAYMENT_CURRENCY, currency); builder.put(ExplainKey.TRADE_NOTIONAL, event.getPaymentAmount()); if (paymentDate.isBefore(provider.getValuationDate())) { builder.put(ExplainKey.COMPLETED, Boolean.TRUE); builder.put(ExplainKey.FORECAST_VALUE, CurrencyAmount.zero(currency)); builder.put(ExplainKey.PRESENT_VALUE, CurrencyAmount.zero(currency)); } else { builder.put(ExplainKey.DISCOUNT_FACTOR, provider.discountFactor(currency, paymentDate)); builder.put(ExplainKey.FORECAST_VALUE, CurrencyAmount.of(currency, forecastValue(event, provider))); builder.put(ExplainKey.PRESENT_VALUE, CurrencyAmount.of(currency, presentValue(event, provider))); } }
NotionalExchange payCmp = (NotionalExchange) computed.getPaymentEvents().get(i); NotionalExchange payExp = (NotionalExchange) expected.getPaymentEvents().get(i); assertEquals(payCmp.getCurrency(), payExp.getCurrency()); assertEquals(payCmp.getPaymentDate(), payExp.getPaymentDate()); assertTrue(DoubleMath.fuzzyEquals(payCmp.getPaymentAmount().getAmount(),