private String notional(SwapLeg leg) { if (leg instanceof RateCalculationSwapLeg) { RateCalculationSwapLeg rcLeg = (RateCalculationSwapLeg) leg; NotionalSchedule notionalSchedule = rcLeg.getNotionalSchedule(); ValueSchedule amount = notionalSchedule.getAmount(); double notional = amount.getInitialValue(); String vary = !amount.getSteps().isEmpty() || amount.getStepSequence().isPresent() ? " variable" : ""; Currency currency = notionalSchedule.getFxReset().map(fxr -> fxr.getReferenceCurrency()).orElse(rcLeg.getCurrency()); return SummarizerUtils.amount(currency, notional) + vary; } if (leg instanceof RatePeriodSwapLeg) { RatePeriodSwapLeg rpLeg = (RatePeriodSwapLeg) leg; return SummarizerUtils.amount(rpLeg.getPaymentPeriods().get(0).getNotionalAmount()); } return ""; }
public void test_findNotional() { ResolvedSwapLeg test = ResolvedSwapLeg.builder() .type(IBOR) .payReceive(RECEIVE) .paymentPeriods(RPP1, RPP2) .build(); // Date is before the start date assertEquals(test.findNotional(RPP1.getStartDate().minusMonths(1)), Optional.of(RPP1.getNotionalAmount())); // Date is on the start date assertEquals(test.findNotional(RPP1.getStartDate()), Optional.of(RPP1.getNotionalAmount())); // Date is after the start date assertEquals(test.findNotional(RPP1.getStartDate().plusDays(1)), Optional.of(RPP1.getNotionalAmount())); // Date is before the end date assertEquals(test.findNotional(RPP2.getEndDate().minusDays(1)), Optional.of(RPP2.getNotionalAmount())); // Date is on the end date assertEquals(test.findNotional(RPP2.getEndDate()), Optional.of(RPP2.getNotionalAmount())); // Date is after the end date assertEquals(test.findNotional(RPP2.getEndDate().plusMonths(1)), Optional.of(RPP2.getNotionalAmount())); }
/** * Computes cash flow equivalent and sensitivity of fixed leg. * <p> * The return type is a map of {@code NotionalExchange} and {@code PointSensitivityBuilder}. * * @param fixedLeg the fixed leg * @param ratesProvider the rates provider * @return the cash flow equivalent and sensitivity */ public static ImmutableMap<Payment, PointSensitivityBuilder> cashFlowEquivalentAndSensitivityFixedLeg( ResolvedSwapLeg fixedLeg, RatesProvider ratesProvider) { ArgChecker.isTrue(fixedLeg.getType().equals(SwapLegType.FIXED), "Leg type should be FIXED"); ArgChecker.isTrue(fixedLeg.getPaymentEvents().isEmpty(), "PaymentEvent should be empty"); Map<Payment, PointSensitivityBuilder> res = new HashMap<Payment, PointSensitivityBuilder>(); for (SwapPaymentPeriod paymentPeriod : fixedLeg.getPaymentPeriods()) { ArgChecker.isTrue(paymentPeriod instanceof RatePaymentPeriod, "rate payment should be RatePaymentPeriod"); RatePaymentPeriod ratePaymentPeriod = (RatePaymentPeriod) paymentPeriod; ArgChecker.isTrue(ratePaymentPeriod.getAccrualPeriods().size() == 1, "rate payment should not be compounding"); RateAccrualPeriod rateAccrualPeriod = ratePaymentPeriod.getAccrualPeriods().get(0); double factor = rateAccrualPeriod.getYearFraction() * ((FixedRateComputation) rateAccrualPeriod.getRateComputation()).getRate(); CurrencyAmount notional = ratePaymentPeriod.getNotionalAmount().multipliedBy(factor); LocalDate paymentDate = ratePaymentPeriod.getPaymentDate(); Payment pay = Payment.of(notional, paymentDate); res.put(pay, PointSensitivityBuilder.none()); } return ImmutableMap.copyOf(res); }
double factor = rateAccrualPeriod.getYearFraction() * ((FixedRateComputation) rateAccrualPeriod.getRateComputation()).getRate(); CurrencyAmount notional = ratePaymentPeriod.getNotionalAmount().multipliedBy(factor); LocalDate paymentDate = ratePaymentPeriod.getPaymentDate(); NotionalExchange pay = NotionalExchange.of(notional, paymentDate);
public void test_builder_oneAccrualPeriod() { RatePaymentPeriod test = RatePaymentPeriod.builder() .paymentDate(DATE_2014_10_01) .accrualPeriods(RAP2) .dayCount(ACT_365F) .currency(GBP) .notional(1000d) .compoundingMethod(CompoundingMethod.STRAIGHT) .build(); assertEquals(test.getStartDate(), DATE_2014_06_30); assertEquals(test.getEndDate(), DATE_2014_09_30); assertEquals(test.getPaymentDate(), DATE_2014_10_01); assertEquals(test.getAccrualPeriods(), ImmutableList.of(RAP2)); assertEquals(test.getCurrency(), GBP); assertEquals(test.getFxReset(), Optional.empty()); assertEquals(test.getNotional(), 1000d, 0d); assertEquals(test.getNotionalAmount(), CurrencyAmount.of(GBP, 1000d)); assertEquals(test.getCompoundingMethod(), CompoundingMethod.STRAIGHT); assertEquals(test.isCompoundingApplicable(), false); }
public void test_builder_twoAccrualPeriods_compoundingDefaultedToNone_fxReset() { RatePaymentPeriod test = RatePaymentPeriod.builder() .paymentDate(DATE_2014_10_01) .accrualPeriods(RAP1, RAP2) .dayCount(ACT_365F) .currency(GBP) .fxReset(FX_RESET_USD) .notional(1000d) .compoundingMethod(CompoundingMethod.NONE) .build(); assertEquals(test.getStartDate(), DATE_2014_03_30); assertEquals(test.getEndDate(), DATE_2014_09_30); assertEquals(test.getPaymentDate(), DATE_2014_10_01); assertEquals(test.getAccrualPeriods(), ImmutableList.of(RAP1, RAP2)); assertEquals(test.getCurrency(), GBP); assertEquals(test.getFxReset(), Optional.of(FX_RESET_USD)); assertEquals(test.getNotional(), 1000d, 0d); assertEquals(test.getNotionalAmount(), CurrencyAmount.of(USD, 1000d)); assertEquals(test.isCompoundingApplicable(), false); }
ArgChecker.isTrue(ratePaymentPeriod.getAccrualPeriods().size() == 1, "rate payment should not be compounding"); RateAccrualPeriod rateAccrualPeriod = ratePaymentPeriod.getAccrualPeriods().get(0); CurrencyAmount notional = ratePaymentPeriod.getNotionalAmount(); LocalDate paymentDate = ratePaymentPeriod.getPaymentDate(); IborIndexObservation obs = ((IborRateComputation) rateAccrualPeriod.getRateComputation()).getObservation();
ArgChecker.isTrue(ratePaymentPeriod.getAccrualPeriods().size() == 1, "rate payment should not be compounding"); RateAccrualPeriod rateAccrualPeriod = ratePaymentPeriod.getAccrualPeriods().get(0); CurrencyAmount notional = ratePaymentPeriod.getNotionalAmount(); LocalDate paymentDate = ratePaymentPeriod.getPaymentDate(); IborIndexObservation obs = ((IborRateComputation) rateAccrualPeriod.getRateComputation()).getObservation();
builder.put(ExplainKey.PAYMENT_CURRENCY, currency); builder.put(ExplainKey.NOTIONAL, CurrencyAmount.of(currency, notional)); builder.put(ExplainKey.TRADE_NOTIONAL, paymentPeriod.getNotionalAmount()); if (paymentDate.isBefore(provider.getValuationDate())) { builder.put(ExplainKey.COMPLETED, Boolean.TRUE);