public void test_of_PeriodIndex() { FraTemplate test = FraTemplate.of(Period.ofMonths(2), GBP_LIBOR_3M); assertEquals(test.getPeriodToStart(), Period.ofMonths(2)); assertEquals(test.getPeriodToEnd(), Period.ofMonths(5)); // defaulted assertEquals(test.getConvention(), FRA_GBP_LIBOR_3M); }
@Override public FraTrade trade(double quantity, MarketData marketData, ReferenceData refData) { double fixedRate = marketData.getValue(rateId) + additionalSpread; BuySell buySell = quantity > 0 ? BuySell.SELL : BuySell.BUY; return template.createTrade(marketData.getValuationDate(), buySell, Math.abs(quantity), fixedRate, refData); }
/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(FraTemplate beanToCopy) { this.periodToStart = beanToCopy.getPeriodToStart(); this.periodToEnd = beanToCopy.getPeriodToEnd(); this.convention = beanToCopy.getConvention(); }
public void test_builder_defaults() { FraTemplate test = FraTemplate.builder() .periodToStart(Period.ofMonths(2)) .convention(FRA_GBP_LIBOR_3M) .build(); assertEquals(test.getPeriodToStart(), Period.ofMonths(2)); assertEquals(test.getPeriodToEnd(), Period.ofMonths(5)); // defaulted assertEquals(test.getConvention(), FRA_GBP_LIBOR_3M); }
/** * 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)); }
public void test_createTrade() { FraTemplate base = FraTemplate.of(Period.ofMonths(3), Period.ofMonths(6), FRA_GBP_LIBOR_3M); LocalDate tradeDate = LocalDate.of(2015, 5, 4); // trade date is a holiday! FraTrade test = base.createTrade(tradeDate, 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); }
@ImmutablePreBuild private static void preBuild(Builder builder) { if (builder.label == null && builder.template != null) { builder.label = Tenor.of(builder.template.getPeriodToEnd()).toString(); } }
public void test_serialization() { FraTemplate test = FraTemplate.of(Period.ofMonths(2), GBP_LIBOR_3M); assertSerialization(test); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case -574688858: // periodToStart return ((FraTemplate) bean).getPeriodToStart(); case -970442977: // periodToEnd return ((FraTemplate) bean).getPeriodToEnd(); case 2039569265: // convention return ((FraTemplate) bean).getConvention(); } return super.propertyGet(bean, propertyName, quiet); }
public void test_createTrade_paymentOffset() { FraConvention convention = ((ImmutableFraConvention) FRA_GBP_LIBOR_3M).toBuilder() .paymentDateOffset(PLUS_TWO_DAYS) .build(); FraTemplate base = FraTemplate.of(Period.ofMonths(3), Period.ofMonths(6), convention); LocalDate tradeDate = LocalDate.of(2015, 5, 4); // trade date is a holiday! FraTrade test = base.createTrade(tradeDate, 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)) .paymentDate(AdjustableDate.of(date(2015, 8, 7), PLUS_TWO_DAYS.getAdjustment())) .fixedRate(0.25d) .index(GBP_LIBOR_3M) .build(); assertEquals(test.getInfo().getTradeDate(), Optional.of(tradeDate)); assertEquals(test.getProduct(), expected); }
@Override public double initialGuess(MarketData marketData, ValueType valueType) { if (ValueType.ZERO_RATE.equals(valueType) || ValueType.FORWARD_RATE.equals(valueType)) { return marketData.getValue(rateId); } if (ValueType.DISCOUNT_FACTOR.equals(valueType)) { double approximateMaturity = template.getPeriodToEnd().toTotalMonths() / 12.0d; return Math.exp(-approximateMaturity * marketData.getValue(rateId)); } return 0d; }
/** * Obtains a template based on the specified periods and convention. * <p> * The periods from the spot date to the start date and to the end date are specified. * <p> * For example, a '2 x 5' FRA has a period to the start date of 2 months and * a period to the end date of 5 months. * * @param periodToStart the period between the spot date and the start date * @param periodToEnd the period between the spot date and the end date * @param convention the market convention * @return the template */ public static FraTemplate of(Period periodToStart, Period periodToEnd, FraConvention convention) { ArgChecker.notNull(periodToStart, "periodToStart"); ArgChecker.notNull(periodToEnd, "periodToEnd"); ArgChecker.notNull(convention, "convention"); return FraTemplate.builder() .periodToStart(periodToStart) .periodToEnd(periodToEnd) .convention(convention) .build(); }
public void test_of_PeriodPeriodConvention() { FraTemplate test = FraTemplate.of(Period.ofMonths(2), Period.ofMonths(4), FRA_GBP_LIBOR_3M); assertEquals(test.getPeriodToStart(), Period.ofMonths(2)); assertEquals(test.getPeriodToEnd(), Period.ofMonths(4)); assertEquals(test.getConvention(), FRA_GBP_LIBOR_3M); }
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(); }
@Override public DatedParameterMetadata metadata(LocalDate valuationDate, ReferenceData refData) { LocalDate nodeDate = date(valuationDate, refData); if (date.isFixed()) { return LabelDateParameterMetadata.of(nodeDate, label); } Tenor tenor = Tenor.of(template.getPeriodToEnd()); return TenorDateParameterMetadata.of(nodeDate, tenor, label); }
private LocalDate calculateEnd(LocalDate valuationDate, ReferenceData refData) { FraTrade trade = template.createTrade(valuationDate, BuySell.BUY, 1, 1, refData); ResolvedFra resolvedFra = trade.getProduct().resolve(refData); return resolvedFra.getEndDate(); }
public void test_initialGuess() { FraCurveNode node = FraCurveNode.of(TEMPLATE, QUOTE_ID, SPREAD); double rate = 0.035; MarketData marketData = ImmutableMarketData.builder(VAL_DATE).addValue(QUOTE_ID, rate).build(); assertEquals(node.initialGuess(marketData, ValueType.ZERO_RATE), rate); assertEquals(node.initialGuess(marketData, ValueType.FORWARD_RATE), rate); double approximateMaturity = TEMPLATE.getPeriodToEnd().toTotalMonths() / 12.0d; double df = Math.exp(-approximateMaturity * rate); assertEquals(node.initialGuess(marketData, ValueType.DISCOUNT_FACTOR), df); assertEquals(node.initialGuess(marketData, ValueType.PRICE_INDEX), 0d); }
private LocalDate calculateLastFixingDate(LocalDate valuationDate, ReferenceData refData) { FraTrade trade = template.createTrade(valuationDate, BuySell.BUY, 1, 1, refData); ResolvedFra resolvedFra = trade.getProduct().resolve(refData); return ((IborRateComputation) resolvedFra.getFloatingRate()).getFixingDate(); }