/** * Creates a trade based on this template. * <p> * This returns a trade based on the specified date. * The notional is unsigned, with buy/sell determining the direction of the trade. * If buying the FRA, the floating rate is received from the counterparty, with the fixed rate being paid. * If selling the FRA, the floating rate is paid to the counterparty, with the fixed rate being received. * * @param tradeDate the date of the trade * @param buySell the buy/sell flag, see {@link Fra#getBuySell()} * @param notional the notional amount, in the payment currency of the template * @param fixedRate the fixed rate, typically derived from the market * @param refData the reference data, used to resolve the trade dates * @return the trade * @throws ReferenceDataNotFoundException if an identifier cannot be resolved in the reference data */ public FraTrade createTrade( LocalDate tradeDate, BuySell buySell, double notional, double fixedRate, ReferenceData refData) { return convention.createTrade(tradeDate, periodToStart, periodToEnd, buySell, notional, fixedRate, refData); }
/** * 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_extendedEnum(FraConvention convention, String name) { FraConvention.of(name); // ensures map is populated ImmutableMap<String, FraConvention> map = FraConvention.extendedEnum().lookupAll(); assertEquals(map.get(name), convention); }
ReferenceData refData) { Period periodToEnd = periodToStart.plus(getIndex().getTenor()); return createTrade(tradeDate, periodToStart, periodToEnd, buySell, notional, fixedRate, refData);
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)); LocalDate endDate = endDateOpt.get(); FraTrade trade = convention.toTrade(info, startDate, endDate, startDate, buySell, notional, fixedRate); return adjustTrade(trade, dateCnv, dateCalOpt); Period periodToStart = periodToStartOpt.get(); FraTrade trade = convention.createTrade(tradeDate, periodToStart, buySell, notional, fixedRate, resolver.getReferenceData()); trade = trade.toBuilder().info(info).build(); return adjustTrade(trade, dateCnv, dateCalOpt);
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)); }
return toTrade(tradeInfo, startDate, endDate, paymentDate, buySell, notional, fixedRate);
/** * Obtains an instance from the specified unique name. * * @param uniqueName the unique name * @return the convention * @throws IllegalArgumentException if the name is not known */ @FromString public static FraConvention of(String uniqueName) { ArgChecker.notNull(uniqueName, "uniqueName"); return extendedEnum().lookup(uniqueName); }
@Override public FraConvention lookup(String name) { FraConvention value = BY_NAME.get(name); if (value == null) { FraConvention created = createByName(name); if (created != null) { String correctName = created.getName(); value = BY_NAME.computeIfAbsent(correctName, k -> created); BY_NAME.putIfAbsent(correctName.toUpperCase(Locale.ENGLISH), value); } } return value; }
/** * Calculates the spot date from the trade date. * * @param tradeDate the trade date * @param refData the reference data, used to resolve the date * @return the spot date * @throws ReferenceDataNotFoundException if an identifier cannot be resolved in the reference data */ public default LocalDate calculateSpotDateFromTradeDate(LocalDate tradeDate, ReferenceData refData) { return getSpotDateOffset().adjust(tradeDate, refData); }
@ImmutablePreBuild private static void preBuild(Builder builder) { if (builder.periodToEnd == null && builder.convention != null && builder.periodToStart != null) { builder.periodToEnd = builder.periodToStart.plus(builder.convention.getIndex().getTenor().getPeriod()); } }
public void test_toTrade_dates() { FraConvention base = ImmutableFraConvention.builder() .index(GBP_LIBOR_3M) .spotDateOffset(NEXT_SAME_BUS_DAY) .build(); LocalDate tradeDate = LocalDate.of(2015, 5, 5); LocalDate startDate = date(2015, 8, 5); LocalDate endDate = date(2015, 11, 5); LocalDate paymentDate = startDate; FraTrade test = base.toTrade(tradeDate, startDate, endDate, startDate, BUY, NOTIONAL_2M, 0.25d); Fra expected = Fra.builder() .buySell(BUY) .notional(NOTIONAL_2M) .startDate(startDate) .endDate(endDate) .paymentDate(AdjustableDate.of(paymentDate)) .fixedRate(0.25d) .index(GBP_LIBOR_3M) .build(); assertEquals(test.getInfo().getTradeDate(), Optional.of(tradeDate)); assertEquals(test.getProduct(), expected); }
/** * 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) { ArgChecker.notNull(index, "index"); return extendedEnum().lookup(index.getName()); }
@Test(dataProvider = "name") public void test_name(FraConvention convention, String name) { assertEquals(convention.getName(), name); }
@Test(dataProvider = "name") public void test_of_lookup(FraConvention convention, String name) { assertEquals(FraConvention.of(name), convention); }
public void test_createTrade_period() { FraConvention base = ImmutableFraConvention.builder() .index(GBP_LIBOR_3M) .spotDateOffset(NEXT_SAME_BUS_DAY) .build(); LocalDate tradeDate = LocalDate.of(2015, 5, 5); FraTrade test = base.createTrade(tradeDate, Period.ofMonths(3), BUY, NOTIONAL_2M, 0.25d, REF_DATA); Fra expected = Fra.builder() .buySell(BUY) .notional(NOTIONAL_2M) .startDate(date(2015, 8, 5)) .endDate(date(2015, 11, 5)) .fixedRate(0.25d) .index(GBP_LIBOR_3M) .build(); assertEquals(test.getInfo().getTradeDate(), Optional.of(tradeDate)); assertEquals(test.getProduct(), expected); }
public void test_toTrade_dates_paymentOffset() { FraConvention base = ImmutableFraConvention.builder() .index(GBP_LIBOR_3M) .spotDateOffset(NEXT_SAME_BUS_DAY) .paymentDateOffset(PLUS_TWO_DAYS) .build(); LocalDate tradeDate = LocalDate.of(2015, 5, 5); LocalDate startDate = date(2015, 8, 5); LocalDate endDate = date(2015, 11, 5); LocalDate paymentDate = date(2015, 8, 7); FraTrade test = base.toTrade(tradeDate, startDate, endDate, paymentDate, BUY, NOTIONAL_2M, 0.25d); Fra expected = Fra.builder() .buySell(BUY) .notional(NOTIONAL_2M) .startDate(date(2015, 8, 5)) .endDate(date(2015, 11, 5)) .paymentDate(AdjustableDate.of(paymentDate, PLUS_TWO_DAYS.getAdjustment())) .fixedRate(0.25d) .index(GBP_LIBOR_3M) .build(); assertEquals(test.getInfo().getTradeDate(), Optional.of(tradeDate)); assertEquals(test.getProduct(), expected); }
public void test_of_lookup_null() { assertThrowsIllegalArg(() -> FraConvention.of((String) null)); }
public void test_createTrade_periods() { FraConvention base = ImmutableFraConvention.builder() .index(GBP_LIBOR_3M) .spotDateOffset(NEXT_SAME_BUS_DAY) .build(); LocalDate tradeDate = LocalDate.of(2015, 5, 5); FraTrade test = base.createTrade(tradeDate, Period.ofMonths(3), Period.ofMonths(6), BUY, NOTIONAL_2M, 0.25d, REF_DATA); Fra expected = Fra.builder() .buySell(BUY) .notional(NOTIONAL_2M) .startDate(date(2015, 8, 5)) .endDate(date(2015, 11, 5)) .fixedRate(0.25d) .index(GBP_LIBOR_3M) .build(); assertEquals(test.getInfo().getTradeDate(), Optional.of(tradeDate)); assertEquals(test.getProduct(), expected); }
public void test_of_lookup_notFound() { assertThrowsIllegalArg(() -> FraConvention.of("Rubbish")); }