private static Optional<BusinessDayAdjustment> parseBusinessDayAdjustment( CsvRow row, String leg, String cnvField, String calField) { BusinessDayConvention dateCnv = findValue(row, leg, cnvField) .map(s -> LoaderUtils.parseBusinessDayConvention(s)) .orElse(BusinessDayConventions.MODIFIED_FOLLOWING); return findValue(row, leg, calField) .map(s -> HolidayCalendarId.of(s)) .map(cal -> BusinessDayAdjustment.of(dateCnv, cal)); }
private static double parseTradeQuantity(CsvRow row) { double quantity = LoaderUtils.parseDouble(row.getValue(QUANTITY_FIELD)); Optional<BuySell> buySellOpt = row.findValue(BUY_SELL_FIELD).map(str -> LoaderUtils.parseBuySell(str)); if (buySellOpt.isPresent()) { quantity = buySellOpt.get().normalize(quantity); } return quantity; }
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")); }
public void test_parsePutCall() { assertEquals(LoaderUtils.parsePutCall("PUT"), PutCall.PUT); assertEquals(LoaderUtils.parsePutCall("Put"), PutCall.PUT); assertEquals(LoaderUtils.parsePutCall("put"), PutCall.PUT); assertEquals(LoaderUtils.parsePutCall("p"), PutCall.PUT); assertEquals(LoaderUtils.parsePutCall("CALL"), PutCall.CALL); assertEquals(LoaderUtils.parsePutCall("Call"), PutCall.CALL); assertEquals(LoaderUtils.parsePutCall("call"), PutCall.CALL); assertEquals(LoaderUtils.parsePutCall("c"), PutCall.CALL); assertThrowsIllegalArg(() -> LoaderUtils.parseBoolean("Rubbish")); }
public void test_parseBuySell() { assertEquals(LoaderUtils.parseBuySell("BUY"), BuySell.BUY); assertEquals(LoaderUtils.parseBuySell("Buy"), BuySell.BUY); assertEquals(LoaderUtils.parseBuySell("buy"), BuySell.BUY); assertEquals(LoaderUtils.parseBuySell("b"), BuySell.BUY); assertEquals(LoaderUtils.parseBuySell("SELL"), BuySell.SELL); assertEquals(LoaderUtils.parseBuySell("Sell"), BuySell.SELL); assertEquals(LoaderUtils.parseBuySell("sell"), BuySell.SELL); assertEquals(LoaderUtils.parseBuySell("s"), BuySell.SELL); assertThrowsIllegalArg(() -> LoaderUtils.parseBoolean("Rubbish")); }
private static SecurityTrade parseSecurityTrade(CsvRow row, TradeInfo info, TradeCsvInfoResolver resolver) { String securityIdScheme = row.findValue(SECURITY_ID_SCHEME_FIELD).orElse(DEFAULT_SECURITY_SCHEME); String securityIdValue = row.getValue(SECURITY_ID_FIELD); SecurityId securityId = SecurityId.of(securityIdScheme, securityIdValue); double price = LoaderUtils.parseDouble(row.getValue(PRICE_FIELD)); double quantity = parseTradeQuantity(row); return SecurityTrade.of(info, securityId, quantity, price); }
private static CurveNodeDate parseDate(String dateStr) { if (dateStr.isEmpty()) { return CurveNodeDate.END; } if (dateStr.length() == 10 && dateStr.charAt(4) == '-' && dateStr.charAt(7) == '-') { return CurveNodeDate.of(LoaderUtils.parseDate(dateStr)); } String dateUpper = dateStr.toUpperCase(Locale.ENGLISH); if (dateUpper.equals("END")) { return CurveNodeDate.END; } if (dateUpper.equals("LASTFIXING")) { return CurveNodeDate.LAST_FIXING; } throw new IllegalArgumentException(Messages.format( "Invalid format for node date, should be date in 'yyyy-MM-dd' format, 'End' or 'LastFixing': {}", dateUpper)); }
public void test_findIndex() { assertEquals(LoaderUtils.findIndex("GBP-LIBOR-3M"), IborIndices.GBP_LIBOR_3M); assertEquals(LoaderUtils.findIndex("GBP-SONIA"), OvernightIndices.GBP_SONIA); assertEquals(LoaderUtils.findIndex("GB-RPI"), PriceIndices.GB_RPI); assertEquals(LoaderUtils.findIndex("GBP/USD-WM"), FxIndices.GBP_USD_WM); assertThrowsIllegalArg(() -> LoaderUtils.findIndex("Rubbish")); }
public void test_parseBoolean() { assertEquals(LoaderUtils.parseBoolean("TRUE"), true); assertEquals(LoaderUtils.parseBoolean("True"), true); assertEquals(LoaderUtils.parseBoolean("true"), true); assertEquals(LoaderUtils.parseBoolean("t"), true); assertEquals(LoaderUtils.parseBoolean("yes"), true); assertEquals(LoaderUtils.parseBoolean("y"), true); assertEquals(LoaderUtils.parseBoolean("FALSE"), false); assertEquals(LoaderUtils.parseBoolean("False"), false); assertEquals(LoaderUtils.parseBoolean("false"), false); assertEquals(LoaderUtils.parseBoolean("f"), false); assertEquals(LoaderUtils.parseBoolean("no"), false); assertEquals(LoaderUtils.parseBoolean("n"), false); assertThrowsIllegalArg(() -> LoaderUtils.parseBoolean("Rubbish")); }
public void test_parseDoublePercent() { assertEquals(LoaderUtils.parseDoublePercent("1.2"), 0.012d, 1e-10); assertThrowsIllegalArg( () -> LoaderUtils.parseDoublePercent("Rubbish"), "Unable to parse percentage from 'Rubbish'"); }
public void test_parseCurrency() { assertEquals(LoaderUtils.parseCurrency("GBP"), Currency.GBP); assertThrowsIllegalArg(() -> LoaderUtils.parseCurrency("A")); }
public void test_parseInteger() { assertEquals(LoaderUtils.parseInteger("2"), 2); assertThrowsIllegalArg(() -> LoaderUtils.parseInteger("Rubbish"), "Unable to parse integer from 'Rubbish'"); }
public void test_parseDouble() { assertEquals(LoaderUtils.parseDouble("1.2"), 1.2d, 1e-10); assertThrowsIllegalArg(() -> LoaderUtils.parseDouble("Rubbish"), "Unable to parse double from 'Rubbish'"); }
public void test_parseTenor() { assertEquals(LoaderUtils.parseTenor("P2D"), Tenor.ofDays(2)); assertEquals(LoaderUtils.parseTenor("2D"), Tenor.ofDays(2)); assertThrowsIllegalArg(() -> LoaderUtils.parseTenor("2")); }
public void test_parsePeriod() { assertEquals(LoaderUtils.parsePeriod("P2D"), Period.ofDays(2)); assertEquals(LoaderUtils.parsePeriod("2D"), Period.ofDays(2)); assertThrowsIllegalArg(() -> LoaderUtils.parsePeriod("2")); }
public void test_parseYearMonth() { assertEquals(LoaderUtils.parseYearMonth("2012-06"), YearMonth.of(2012, 6)); assertEquals(LoaderUtils.parseYearMonth("201206"), YearMonth.of(2012, 6)); assertEquals(LoaderUtils.parseYearMonth("Jun-2012"), YearMonth.of(2012, 6)); assertEquals(LoaderUtils.parseYearMonth("Jun-12"), YearMonth.of(2012, 6)); assertEquals(LoaderUtils.parseYearMonth("Jun2012"), YearMonth.of(2012, 6)); assertEquals(LoaderUtils.parseYearMonth("Jun12"), YearMonth.of(2012, 6)); assertEquals(LoaderUtils.parseYearMonth("1/6/2012"), YearMonth.of(2012, 6)); assertEquals(LoaderUtils.parseYearMonth("01/6/2012"), YearMonth.of(2012, 6)); assertEquals(LoaderUtils.parseYearMonth("1/06/2012"), YearMonth.of(2012, 6)); assertEquals(LoaderUtils.parseYearMonth("01/06/2012"), YearMonth.of(2012, 6)); assertThrowsIllegalArg(() -> LoaderUtils.parseYearMonth("2/6/2012")); assertThrowsIllegalArg(() -> LoaderUtils.parseYearMonth("1/6/12")); assertThrowsIllegalArg(() -> LoaderUtils.parseYearMonth("Jun1")); assertThrowsIllegalArg(() -> LoaderUtils.parseYearMonth("12345678")); assertThrowsIllegalArg(() -> LoaderUtils.parseYearMonth("Rubbish")); }
public void test_tryParseCurrency() { assertEquals(LoaderUtils.tryParseCurrency("GBP"), Optional.of(Currency.GBP)); assertEquals(LoaderUtils.tryParseCurrency("123"), Optional.empty()); assertEquals(LoaderUtils.tryParseCurrency("G"), Optional.empty()); assertEquals(LoaderUtils.tryParseCurrency(""), Optional.empty()); assertEquals(LoaderUtils.tryParseCurrency(null), Optional.empty()); }
static Optional<BusinessDayAdjustment> parsePaymentDateAdjustment(CsvRow row) { Optional<BusinessDayAdjustment> paymentAdj = Optional.empty(); Optional<String> paymentDateCnv = row.findValue(PAYMENT_DATE_CNV_FIELD); // Optional field with Business day adjustment if (paymentDateCnv.isPresent()) { BusinessDayConvention bdCnv = LoaderUtils.parseBusinessDayConvention(paymentDateCnv.get()); if (!bdCnv.equals(BusinessDayConventions.NO_ADJUST)) { Optional<String> paymentDateCalOpt = row.findValue(PAYMENT_DATE_CAL_FIELD); if (paymentDateCalOpt.isPresent()) { paymentAdj = Optional.of(BusinessDayAdjustment.of( LoaderUtils.parseBusinessDayConvention(paymentDateCnv.get()), HolidayCalendarId.of(paymentDateCalOpt.get()))); } } } return paymentAdj; }
public void test_tryParseTenor() { assertEquals(LoaderUtils.tryParseTenor("P2D"), Optional.of(Tenor.ofDays(2))); assertEquals(LoaderUtils.tryParseTenor("2D"), Optional.of(Tenor.ofDays(2))); assertEquals(LoaderUtils.tryParseTenor("2X"), Optional.empty()); assertEquals(LoaderUtils.tryParseTenor("2"), Optional.empty()); assertEquals(LoaderUtils.tryParseTenor(""), Optional.empty()); assertEquals(LoaderUtils.tryParseTenor(null), Optional.empty()); }
public void test_parseDate() { assertEquals(LoaderUtils.parseDate("2012-06-30"), LocalDate.of(2012, 6, 30)); assertEquals(LoaderUtils.parseDate("20120630"), LocalDate.of(2012, 6, 30)); assertEquals(LoaderUtils.parseDate("2012/06/30"), LocalDate.of(2012, 6, 30)); assertEquals(LoaderUtils.parseDate("30/06/2012"), LocalDate.of(2012, 6, 30)); assertEquals(LoaderUtils.parseDate("30/06/12"), LocalDate.of(2012, 6, 30)); assertEquals(LoaderUtils.parseDate("30-Jun-2012"), LocalDate.of(2012, 6, 30)); assertEquals(LoaderUtils.parseDate("30-Jun-12"), LocalDate.of(2012, 6, 30)); assertEquals(LoaderUtils.parseDate("30Jun2012"), LocalDate.of(2012, 6, 30)); assertEquals(LoaderUtils.parseDate("30Jun12"), LocalDate.of(2012, 6, 30)); assertEquals(LoaderUtils.parseDate("2012-05-04"), LocalDate.of(2012, 5, 4)); assertEquals(LoaderUtils.parseDate("20120504"), LocalDate.of(2012, 5, 4)); assertEquals(LoaderUtils.parseDate("2012/5/4"), LocalDate.of(2012, 5, 4)); assertEquals(LoaderUtils.parseDate("4/5/2012"), LocalDate.of(2012, 5, 4)); assertEquals(LoaderUtils.parseDate("4/5/12"), LocalDate.of(2012, 5, 4)); assertEquals(LoaderUtils.parseDate("4-May-2012"), LocalDate.of(2012, 5, 4)); assertEquals(LoaderUtils.parseDate("4-May-12"), LocalDate.of(2012, 5, 4)); assertEquals(LoaderUtils.parseDate("4May2012"), LocalDate.of(2012, 5, 4)); assertEquals(LoaderUtils.parseDate("4May12"), LocalDate.of(2012, 5, 4)); assertThrowsIllegalArg(() -> LoaderUtils.parseDate("040512")); assertThrowsIllegalArg(() -> LoaderUtils.parseDate("Rubbish")); }