/** * Obtains a convention based on the specified index. * <p> * This uses the index name to find the matching convention. * By default, this will always return a convention, however configuration may be added * to restrict the conventions that are registered. * * @param index the index, from which the index name is used to find the matching convention * @return the convention * @throws IllegalArgumentException if no convention is registered for the index */ public static FraConvention of(IborIndex index) { return FraConvention.of(index); }
@Test(dataProvider = "name") public void test_of_lookup(FraConvention convention, String name) { assertEquals(FraConvention.of(name), convention); }
public void test_of_lookup_notFound() { assertThrowsIllegalArg(() -> FraConvention.of("Rubbish")); }
public void test_unknownIndex() { assertThrowsIllegalArg(() -> FraConvention.of("Rubbish")); }
public void test_of_lookup_null() { assertThrowsIllegalArg(() -> FraConvention.of((String) null)); }
@Test(dataProvider = "name") public void test_extendedEnum(FraConvention convention, String name) { FraConvention.of(name); // ensures map is populated ImmutableMap<String, FraConvention> map = FraConvention.extendedEnum().lookupAll(); assertEquals(map.get(name), convention); }
/** * Obtains a template based on the specified period and index. * <p> * The period from the spot date to the start date is specified. * The period from the spot date to the end date will be the period to start * plus the tenor of the index. * <p> * For example, a '2 x 5' FRA has a period to the start date of 2 months. * The index will be a 3 month index, such as 'USD-LIBOR-3M'. * The period to the end date will be the period to the start date plus the index tenor. * * @param periodToStart the period between the spot date and the start date * @param index the index that defines the market convention * @return the template */ public static FraTemplate of(Period periodToStart, IborIndex index) { return of(periodToStart, periodToStart.plus(index.getTenor().getPeriod()), FraConvention.of(index)); }
private static CurveNode curveFraCurveNode( String conventionStr, String timeStr, String label, QuoteId quoteId, double spread, CurveNodeDate date, CurveNodeDateOrder order) { Matcher matcher = FRA_TIME_REGEX.matcher(timeStr.toUpperCase(Locale.ENGLISH)); if (!matcher.matches()) { throw new IllegalArgumentException(Messages.format("Invalid time format for FRA: {}", timeStr)); } Period periodToStart = Period.parse("P" + matcher.group(1) + "M"); Period periodToEnd = Period.parse("P" + matcher.group(2) + "M"); FraConvention convention = FraConvention.of(conventionStr); FraTemplate template = FraTemplate.of(periodToStart, periodToEnd, convention); return FraCurveNode.builder() .template(template) .rateId(quoteId) .additionalSpread(spread) .label(label) .date(date) .dateOrder(order) .build(); }
double notional = LoaderUtils.parseDouble(row.getValue(NOTIONAL_FIELD)); double fixedRate = LoaderUtils.parseDoublePercent(row.getValue(FIXED_RATE_FIELD)); Optional<FraConvention> conventionOpt = row.findValue(CONVENTION_FIELD).map(s -> FraConvention.of(s)); Optional<Period> periodToStartOpt = row.findValue(PERIOD_TO_START_FIELD).map(s -> LoaderUtils.parsePeriod(s)); Optional<LocalDate> startDateOpt = row.findValue(START_DATE_FIELD).map(s -> LoaderUtils.parseDate(s));
public void test_of_index() { ImmutableFraConvention test = ImmutableFraConvention.of(GBP_LIBOR_3M); assertEquals(test.getIndex(), GBP_LIBOR_3M); assertEquals(test.getName(), GBP_LIBOR_3M.getName()); assertEquals(test.getCurrency(), GBP); assertEquals(test.getSpotDateOffset(), GBP_LIBOR_3M.getEffectiveDateOffset()); assertEquals(test.getBusinessDayAdjustment(), BDA_MOD_FOLLOW); assertEquals(test.getPaymentDateOffset(), DaysAdjustment.NONE); assertEquals(test.getFixingDateOffset(), GBP_LIBOR_3M.getFixingDateOffset()); assertEquals(test.getDayCount(), ACT_365F); assertEquals(test.getDiscounting(), ISDA); // ensure other factories match assertEquals(FraConvention.of(GBP_LIBOR_3M), test); assertEquals(FraConventions.of(GBP_LIBOR_3M), test); }
public void test_toTemplate_badDateOrder() { FraConvention base = FraConvention.of(GBP_LIBOR_3M); LocalDate tradeDate = LocalDate.of(2015, 5, 5); LocalDate startDate = date(2015, 4, 5); LocalDate endDate = date(2015, 7, 5); LocalDate paymentDate = date(2015, 8, 7); assertThrowsIllegalArg(() -> base.toTrade(tradeDate, startDate, endDate, paymentDate, BUY, NOTIONAL_2M, 0.25d)); }
public void coverage() { FraTemplate test = FraTemplate.of(Period.ofMonths(2), GBP_LIBOR_3M); coverImmutableBean(test); FraTemplate test2 = FraTemplate.of(Period.ofMonths(3), Period.ofMonths(6), FraConvention.of(USD_LIBOR_3M)); coverBeanEquals(test, test2); }