public void test_parsePayReceive() { assertEquals(LoaderUtils.parsePayReceive("PAY"), PayReceive.PAY); assertEquals(LoaderUtils.parsePayReceive("Pay"), PayReceive.PAY); assertEquals(LoaderUtils.parsePayReceive("pay"), PayReceive.PAY); assertEquals(LoaderUtils.parsePayReceive("p"), PayReceive.PAY); assertEquals(LoaderUtils.parsePayReceive("RECEIVE"), PayReceive.RECEIVE); assertEquals(LoaderUtils.parsePayReceive("Receive"), PayReceive.RECEIVE); assertEquals(LoaderUtils.parsePayReceive("receive"), PayReceive.RECEIVE); assertEquals(LoaderUtils.parsePayReceive("rec"), PayReceive.RECEIVE); assertEquals(LoaderUtils.parsePayReceive("r"), PayReceive.RECEIVE); assertThrowsIllegalArg(() -> LoaderUtils.parseBoolean("Rubbish")); }
static FxSingle parseFxSingle(CsvRow row, String prefix) { PayReceive direction1 = LoaderUtils.parsePayReceive(row.getValue(prefix + LEG_1_DIRECTION_FIELD)); Currency currency1 = Currency.of(row.getValue(prefix + LEG_1_CURRENCY_FIELD)); double notional1 = LoaderUtils.parseDouble(row.getValue(prefix + LEG_1_NOTIONAL_FIELD)); LocalDate paymentDate1 = row.findValue(prefix + LEG_1_PAYMENT_DATE_FIELD) .map(str -> LoaderUtils.parseDate(str)) .orElseGet(() -> LoaderUtils.parseDate(row.getValue(prefix + PAYMENT_DATE_FIELD))); PayReceive direction2 = LoaderUtils.parsePayReceive(row.getValue(prefix + LEG_2_DIRECTION_FIELD)); Currency currency2 = Currency.of(row.getValue(prefix + LEG_2_CURRENCY_FIELD)); double notional2 = LoaderUtils.parseDouble(row.getValue(prefix + LEG_2_NOTIONAL_FIELD)); LocalDate paymentDate2 = row.findValue(prefix + LEG_2_PAYMENT_DATE_FIELD) .map(str -> LoaderUtils.parseDate(str)) .orElseGet(() -> LoaderUtils.parseDate(row.getValue(prefix + PAYMENT_DATE_FIELD))); Optional<BusinessDayAdjustment> paymentAdj = parsePaymentDateAdjustment(row); if (direction1.equals(direction2)) { throw new IllegalArgumentException(Messages.format( "FxSingle legs must not have the same direction: {}, {}", direction1.toString(), direction2.toString())); } Payment payment1 = Payment.of(currency1, direction1.normalize(notional1), paymentDate1); Payment payment2 = Payment.of(currency2, direction2.normalize(notional2), paymentDate2); return paymentAdj .map(adj -> FxSingle.of(payment1, payment2, adj)) .orElseGet(() -> FxSingle.of(payment1, payment2)); }
private static RateCalculationSwapLeg parseLeg( CsvRow row, String leg, FloatingRateIndex index, DayCount defaultFixedLegDayCount) { PayReceive payReceive = LoaderUtils.parsePayReceive(getValue(row, leg, DIRECTION_FIELD)); PeriodicSchedule accrualSch = parseAccrualSchedule(row, leg); PaymentSchedule paymentSch = parsePaymentSchedule(row, leg, accrualSch.getFrequency()); NotionalSchedule notionalSch = parseNotionalSchedule(row, leg); RateCalculation calc = parseRateCalculation( row, leg, index, defaultFixedLegDayCount, accrualSch.getBusinessDayAdjustment(), notionalSch.getCurrency()); return RateCalculationSwapLeg.builder() .payReceive(payReceive) .accrualSchedule(accrualSch) .paymentSchedule(paymentSch) .notionalSchedule(notionalSch) .calculation(calc) .build(); }