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_cashFlows() { RatesProvider mockProv = mock(RatesProvider.class); SwapPaymentPeriodPricer<SwapPaymentPeriod> mockPeriod = mock(SwapPaymentPeriodPricer.class); DispatchingSwapPaymentEventPricer eventPricer = DispatchingSwapPaymentEventPricer.DEFAULT; ResolvedSwapLeg expSwapLeg = IBOR_SWAP_LEG_REC_GBP_MULTI; SwapPaymentPeriod period1 = IBOR_RATE_PAYMENT_PERIOD_REC_GBP; SwapPaymentPeriod period2 = IBOR_RATE_PAYMENT_PERIOD_REC_GBP_2; NotionalExchange event = NOTIONAL_EXCHANGE_REC_GBP; double fv1 = 520d; double fv2 = 450d; double df = 1.0d; double df1 = 0.98; double df2 = 0.93; when(mockPeriod.forecastValue(period1, mockProv)).thenReturn(fv1); when(mockPeriod.forecastValue(period2, mockProv)).thenReturn(fv2); when(mockProv.getValuationDate()).thenReturn(LocalDate.of(2014, 7, 1)); when(mockProv.discountFactor(expSwapLeg.getCurrency(), period1.getPaymentDate())).thenReturn(df1); when(mockProv.discountFactor(expSwapLeg.getCurrency(), period2.getPaymentDate())).thenReturn(df2); when(mockProv.discountFactor(expSwapLeg.getCurrency(), event.getPaymentDate())).thenReturn(df); DiscountingSwapLegPricer pricer = new DiscountingSwapLegPricer(mockPeriod, eventPricer); CashFlows computed = pricer.cashFlows(expSwapLeg, mockProv); CashFlow flow1 = CashFlow.ofForecastValue(period1.getPaymentDate(), GBP, fv1, df1); CashFlow flow2 = CashFlow.ofForecastValue(period2.getPaymentDate(), GBP, fv2, df2); CashFlow flow3 = CashFlow.ofForecastValue(event.getPaymentDate(), GBP, event.getPaymentAmount().getAmount(), df); CashFlows expected = CashFlows.of(ImmutableList.of(flow1, flow2, flow3)); assertEquals(computed, expected); }
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_currentCash_onPayment() { ImmutableRatesProvider prov = ImmutableRatesProvider.builder(NOTIONAL_EXCHANGE_REC_GBP.getPaymentDate()) .discountCurve(GBP, DISCOUNT_CURVE_GBP) .build(); DiscountingNotionalExchangePricer test = DiscountingNotionalExchangePricer.DEFAULT; double notional = NOTIONAL_EXCHANGE_REC_GBP.getPaymentAmount().getAmount(); double computed = test.currentCash(NOTIONAL_EXCHANGE_REC_GBP, prov); assertEquals(computed, notional); }
for (int loopcf = 0; loopcf < nPayments; loopcf++) { NotionalExchange payment = (NotionalExchange) cashFlowEquiv.getPaymentEvents().get(loopcf); LocalDate maturityDate = payment.getPaymentDate(); alpha[loopcf] = hwProvider.alpha(ratesProvider.getValuationDate(), expiryDate, expiryDate, maturityDate); discountedCashFlow[loopcf] = paymentPricer.presentValueAmount(payment.getPayment(), ratesProvider);
NotionalExchange payment = (NotionalExchange) cashFlowEquiv.getPaymentEvents().get(loopcf); ValueDerivatives valueDeriv = hwProvider.alphaAdjoint( ratesProvider.getValuationDate(), expiryDate, expiryDate, payment.getPaymentDate()); alpha[loopcf] = valueDeriv.getValue(); alphaAdjoint[loopcf] = valueDeriv.getDerivatives().toArray();
@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 payExp = (NotionalExchange) expected.getPaymentEvents().get(i); assertEquals(payCmp.getCurrency(), payExp.getCurrency()); assertEquals(payCmp.getPaymentDate(), payExp.getPaymentDate()); assertTrue(DoubleMath.fuzzyEquals(payCmp.getPaymentAmount().getAmount(), payExp.getPaymentAmount().getAmount(), NOTIONAL * eps));