CashFlows cashFlowEventsInternal(ResolvedSwapLeg leg, RatesProvider provider) { ImmutableList.Builder<CashFlow> builder = ImmutableList.builder(); for (SwapPaymentEvent event : leg.getPaymentEvents()) { if (!event.getPaymentDate().isBefore(provider.getValuationDate())) { double forecastValue = paymentEventPricer.forecastValue(event, provider); if (forecastValue != 0d) { Currency currency = event.getCurrency(); LocalDate paymentDate = event.getPaymentDate(); double discountFactor = provider.discountFactor(currency, paymentDate); CashFlow singleCashFlow = CashFlow.ofForecastValue(paymentDate, currency, forecastValue, discountFactor); builder.add(singleCashFlow); } } } return CashFlows.of(builder.build()); }
private ImmutableList<SwapPaymentEvent> createEvents( List<NotionalPaymentPeriod> adjPaymentPeriods, DateAdjuster paymentDateAdjuster, ReferenceData refData) { ImmutableList.Builder<SwapPaymentEvent> events = ImmutableList.builder(); LocalDate initialExchangeDate = paymentDateAdjuster.adjust(adjPaymentPeriods.get(0).getStartDate()); events.addAll(NotionalSchedule.createEvents( adjPaymentPeriods, initialExchangeDate, initialExchange, intermediateExchange, finalExchange, refData)); paymentEvents.forEach(pe -> events.add(pe.adjustPaymentDate(paymentDateAdjuster))); return events.build(); }
double presentValueEventsInternal(ResolvedSwapLeg leg, RatesProvider provider) { double total = 0d; for (SwapPaymentEvent event : leg.getPaymentEvents()) { if (!event.getPaymentDate().isBefore(provider.getValuationDate())) { total += paymentEventPricer.presentValue(event, provider); } } return total; }
@Override public void collectCurrencies(ImmutableSet.Builder<Currency> builder) { builder.add(currency); for (RatePaymentPeriod paymentPeriod : paymentPeriods) { builder.add(paymentPeriod.getCurrency()); paymentPeriod.getFxReset().ifPresent(fxr -> builder.add(fxr.getReferenceCurrency())); } paymentEvents.forEach(ev -> builder.add(ev.getCurrency())); }
private double currentCashEventsInternal(ResolvedSwapLeg leg, RatesProvider provider) { double total = 0d; for (SwapPaymentEvent event : leg.getPaymentEvents()) { if (!event.getPaymentDate().isBefore(provider.getValuationDate())) { total += paymentEventPricer.currentCash(event, provider); } } return total; } }
double forecastValueEventsInternal(ResolvedSwapLeg leg, RatesProvider provider) { double total = 0d; for (SwapPaymentEvent event : leg.getPaymentEvents()) { if (!event.getPaymentDate().isBefore(provider.getValuationDate())) { total += paymentEventPricer.forecastValue(event, provider); } } return total; }
PointSensitivityBuilder presentValueSensitivityEventsInternal(ResolvedSwapLeg leg, RatesProvider provider) { PointSensitivityBuilder builder = PointSensitivityBuilder.none(); for (SwapPaymentEvent event : leg.getPaymentEvents()) { if (!event.getPaymentDate().isBefore(provider.getValuationDate())) { builder = builder.combinedWith(paymentEventPricer.presentValueSensitivity(event, provider)); } } return builder; }
private MultiCurrencyAmount currencyExposureEventsInternal(ResolvedSwapLeg leg, RatesProvider provider) { MultiCurrencyAmount total = MultiCurrencyAmount.empty(); for (SwapPaymentEvent event : leg.getPaymentEvents()) { if (!event.getPaymentDate().isBefore(provider.getValuationDate())) { total = total.plus(paymentEventPricer.currencyExposure(event, provider)); } } return total; }
private PointSensitivityBuilder legValueSensitivity( ResolvedSwapLeg leg, RatesProvider provider, BiFunction<SwapPaymentPeriod, RatesProvider, PointSensitivityBuilder> periodFn, BiFunction<SwapPaymentEvent, RatesProvider, PointSensitivityBuilder> eventFn) { PointSensitivityBuilder builder = PointSensitivityBuilder.none(); for (SwapPaymentPeriod period : leg.getPaymentPeriods()) { if (!period.getPaymentDate().isBefore(provider.getValuationDate())) { builder = builder.combinedWith(periodFn.apply(period, provider)); } } for (SwapPaymentEvent event : leg.getPaymentEvents()) { if (!event.getPaymentDate().isBefore(provider.getValuationDate())) { builder = builder.combinedWith(eventFn.apply(event, provider)); } } return builder; }
public void test_currentCash_payEvent() { ResolvedSwapLeg expSwapLeg = FIXED_SWAP_LEG_PAY_USD; LocalDate paymentDate = expSwapLeg.getPaymentEvents().get(0).getPaymentDate(); RatesProvider prov = new MockRatesProvider(paymentDate); SwapPaymentEventPricer<SwapPaymentEvent> mockEvent = mock(SwapPaymentEventPricer.class); double expected = 1234d; when(mockEvent.currentCash(expSwapLeg.getPaymentEvents().get(0), prov)).thenReturn(expected); DiscountingSwapLegPricer pricer = new DiscountingSwapLegPricer(SwapPaymentPeriodPricer.standard(), mockEvent); CurrencyAmount computed = pricer.currentCash(expSwapLeg, prov); assertEquals(computed, CurrencyAmount.of(expSwapLeg.getCurrency(), expected)); }
public void test_presentValue() { CurrencyAmount computedRec = PRICER.presentValue(SWAPTION_REC_LONG, RATE_PROVIDER, HW_PROVIDER); CurrencyAmount computedPay = PRICER.presentValue(SWAPTION_PAY_SHORT, RATE_PROVIDER, HW_PROVIDER); SwapPaymentEventPricer<SwapPaymentEvent> paymentEventPricer = SwapPaymentEventPricer.standard(); ResolvedSwapLeg cashFlowEquiv = CashFlowEquivalentCalculator.cashFlowEquivalentSwap(RSWAP_REC, RATE_PROVIDER); LocalDate expiryDate = MATURITY.toLocalDate(); int nPayments = cashFlowEquiv.getPaymentEvents().size(); double[] alpha = new double[nPayments]; double[] discountedCashFlow = new double[nPayments]; for (int loopcf = 0; loopcf < nPayments; loopcf++) { SwapPaymentEvent payment = cashFlowEquiv.getPaymentEvents().get(loopcf); alpha[loopcf] = HW_PROVIDER.alpha(RATE_PROVIDER.getValuationDate(), expiryDate, expiryDate, payment.getPaymentDate()); discountedCashFlow[loopcf] = paymentEventPricer.presentValue(payment, RATE_PROVIDER); } double omegaPay = -1d; double kappa = HW_PROVIDER.getModel().kappa(DoubleArray.copyOf(discountedCashFlow), DoubleArray.copyOf(alpha)); double expectedRec = 0.0; double expectedPay = 0.0; for (int loopcf = 0; loopcf < nPayments; loopcf++) { expectedRec += discountedCashFlow[loopcf] * NORMAL.getCDF((kappa + alpha[loopcf])); expectedPay += discountedCashFlow[loopcf] * NORMAL.getCDF(omegaPay * (kappa + alpha[loopcf])); } assertEquals(computedRec.getCurrency(), EUR); assertEquals(computedRec.getAmount(), expectedRec, NOTIONAL * TOL); assertEquals(computedPay.getCurrency(), EUR); assertEquals(computedPay.getAmount(), expectedPay, NOTIONAL * TOL); }