public void test_of_bda() { ImmutableFxSwapConvention test = ImmutableFxSwapConvention.of(EUR_USD, PLUS_TWO_DAYS, BDA_FOLLOW); assertEquals(test.getName(), EUR_USD.toString()); assertEquals(test.getCurrencyPair(), EUR_USD); assertEquals(test.getSpotDateOffset(), PLUS_TWO_DAYS); assertEquals(test.getBusinessDayAdjustment(), BDA_FOLLOW); }
@Override public ImmutableFxSwapConvention build() { return new ImmutableFxSwapConvention( currencyPair, name, spotDateOffset, businessDayAdjustment); }
/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(ImmutableFxSwapConvention beanToCopy) { this.currencyPair = beanToCopy.getCurrencyPair(); this.name = beanToCopy.name; this.spotDateOffset = beanToCopy.getSpotDateOffset(); this.businessDayAdjustment = beanToCopy.businessDayAdjustment; }
public void test_builder() { ImmutableFxSwapConvention test = ImmutableFxSwapConvention.builder() .currencyPair(EUR_USD) .name("EUR::USD") .spotDateOffset(PLUS_TWO_DAYS) .businessDayAdjustment(BDA_FOLLOW) .build(); assertEquals(test.getName(), "EUR::USD"); assertEquals(test.getCurrencyPair(), EUR_USD); assertEquals(test.getSpotDateOffset(), PLUS_TWO_DAYS); assertEquals(test.getBusinessDayAdjustment(), BDA_FOLLOW); }
@Test(dataProvider = "calendar") public void test_calendar(ImmutableFxSwapConvention convention, HolidayCalendarId cal) { assertEquals(convention.getSpotDateOffset().getCalendar(), cal); assertEquals(convention.getBusinessDayAdjustment().getCalendar(), cal); }
@Override public FxSwapTrade toTrade( TradeInfo tradeInfo, LocalDate startDate, LocalDate endDate, BuySell buySell, double notional, double nearFxRate, double farLegForwardPoints) { Optional<LocalDate> tradeDate = tradeInfo.getTradeDate(); if (tradeDate.isPresent()) { ArgChecker.inOrderOrEqual(tradeDate.get(), startDate, "tradeDate", "startDate"); } double amount1 = BuySell.BUY.normalize(notional); return FxSwapTrade.builder() .info(tradeInfo) .product(FxSwap.ofForwardPoints( CurrencyAmount.of(currencyPair.getBase(), amount1), FxRate.of(currencyPair, nearFxRate), farLegForwardPoints, startDate, endDate, getBusinessDayAdjustment())) .build(); }
@Test(dataProvider = "spotLag") public void test_spot_lag(ImmutableFxSwapConvention convention, int lag) { assertEquals(convention.getSpotDateOffset().getDays(), lag); }
public void coverage() { ImmutableFxSwapConvention test = ImmutableFxSwapConvention.of(EUR_USD, PLUS_TWO_DAYS, BDA_FOLLOW); coverImmutableBean(test); ImmutableFxSwapConvention test2 = ImmutableFxSwapConvention.builder() .name("GBP/USD") .currencyPair(GBP_USD) .spotDateOffset(PLUS_ONE_DAY) .businessDayAdjustment(BDA_MODFOLLOW) .build(); coverBeanEquals(test, test2); }
public void test_toTemplate_badDateOrder() { ImmutableFxSwapConvention base = ImmutableFxSwapConvention.of(EUR_USD, PLUS_TWO_DAYS, BDA_FOLLOW); LocalDate tradeDate = LocalDate.of(2015, 5, 5); LocalDate nearDate = date(2015, 4, 5); LocalDate farDate = date(2015, 7, 5); assertThrowsIllegalArg(() -> base.toTrade(tradeDate, nearDate, farDate, BUY, NOTIONAL_EUR, FX_RATE_NEAR, FX_RATE_PTS)); }
/** * Obtains a convention based on the specified currency pair and spot date offset. * <p> * Use the {@linkplain #builder() builder} for unusual conventions. * * @param currencyPair the currency pair associated to the convention * @param spotDateOffset the spot date offset * @return the convention */ public static ImmutableFxSwapConvention of(CurrencyPair currencyPair, DaysAdjustment spotDateOffset) { return ImmutableFxSwapConvention.builder() .currencyPair(currencyPair) .spotDateOffset(spotDateOffset) .build(); }
@Override public String toString() { return getName(); }
@Test(dataProvider = "currencyPair") public void test_currency_pair(ImmutableFxSwapConvention convention, CurrencyPair ccys) { assertEquals(convention.getCurrencyPair(), ccys); }
public void test_toTrade_periods() { ImmutableFxSwapConvention base = ImmutableFxSwapConvention.of(EUR_USD, PLUS_TWO_DAYS, BDA_FOLLOW); Period startPeriod = Period.ofMonths(3); Period endPeriod = Period.ofMonths(6); LocalDate tradeDate = LocalDate.of(2015, 5, 5); LocalDate spotDate = PLUS_TWO_DAYS.adjust(tradeDate, REF_DATA); LocalDate nearDate = spotDate.plus(startPeriod); LocalDate farDate = spotDate.plus(endPeriod); FxSwapTrade test = base.createTrade(tradeDate, startPeriod, endPeriod, BUY, NOTIONAL_EUR, FX_RATE_NEAR, FX_RATE_PTS, REF_DATA); FxSwap expected = FxSwap.ofForwardPoints( CurrencyAmount.of(EUR, NOTIONAL_EUR), FxRate.of(EUR, USD, FX_RATE_NEAR), FX_RATE_PTS, nearDate, farDate, BDA_FOLLOW); assertEquals(test.getInfo().getTradeDate(), Optional.of(tradeDate)); assertEquals(test.getProduct(), expected); }
public void test_serialization() { ImmutableFxSwapConvention test = ImmutableFxSwapConvention.of(EUR_USD, PLUS_TWO_DAYS, BDA_FOLLOW); assertSerialization(test); }
public void test_metadata_end() { FxSwapCurveNode node = FxSwapCurveNode.of(TEMPLATE, QUOTE_ID_PTS); LocalDate valuationDate = LocalDate.of(2015, 1, 22); LocalDate endDate = CONVENTION.getBusinessDayAdjustment() .adjust(CONVENTION.getSpotDateOffset().adjust(valuationDate, REF_DATA).plus(FAR_PERIOD), REF_DATA); ParameterMetadata metadata = node.metadata(valuationDate, REF_DATA); assertEquals(((TenorDateParameterMetadata) metadata).getDate(), endDate); assertEquals(((TenorDateParameterMetadata) metadata).getTenor(), Tenor.of(FAR_PERIOD)); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 1005147787: // currencyPair return ((ImmutableFxSwapConvention) bean).getCurrencyPair(); case 3373707: // name return ((ImmutableFxSwapConvention) bean).name; case 746995843: // spotDateOffset return ((ImmutableFxSwapConvention) bean).getSpotDateOffset(); case -1065319863: // businessDayAdjustment return ((ImmutableFxSwapConvention) bean).businessDayAdjustment; } return super.propertyGet(bean, propertyName, quiet); }
public void test_createTrade() { FxSwapTemplate base = FxSwapTemplate.of(NEAR_PERIOD, FAR_PERIOD, CONVENTION); LocalDate tradeDate = LocalDate.of(2015, 10, 29); FxSwapTrade test = base.createTrade(tradeDate, BUY, NOTIONAL_EUR, FX_RATE_NEAR, FX_RATE_PTS, REF_DATA); LocalDate spotDate = PLUS_TWO_DAYS.adjust(tradeDate, REF_DATA); LocalDate nearDate = spotDate.plus(NEAR_PERIOD); LocalDate farDate = spotDate.plus(FAR_PERIOD); BusinessDayAdjustment bda = CONVENTION.getBusinessDayAdjustment(); FxSwap expected = FxSwap.ofForwardPoints( CurrencyAmount.of(EUR, NOTIONAL_EUR), FxRate.of(EUR, USD, FX_RATE_NEAR), FX_RATE_PTS, nearDate, farDate, bda); assertEquals(test.getInfo().getTradeDate(), Optional.of(tradeDate)); assertEquals(test.getProduct(), expected); }
public void test_toTrade_dates() { ImmutableFxSwapConvention base = ImmutableFxSwapConvention.of(EUR_USD, PLUS_TWO_DAYS, BDA_FOLLOW); LocalDate tradeDate = LocalDate.of(2015, 5, 5); LocalDate nearDate = LocalDate.of(2015, 7, 5); LocalDate nearDateAdj = LocalDate.of(2015, 7, 6); // Adjusted: 5 is Sunday LocalDate farDate = LocalDate.of(2015, 9, 5); LocalDate farDateAdj = LocalDate.of(2015, 9, 7); // Adjusted: 5 is Saturday FxSwapTrade test = base.toTrade(tradeDate, nearDate, farDate, BUY, NOTIONAL_EUR, FX_RATE_NEAR, FX_RATE_PTS); FxSwap expected = FxSwap.ofForwardPoints( CurrencyAmount.of(EUR, NOTIONAL_EUR), FxRate.of(EUR, USD, FX_RATE_NEAR), FX_RATE_PTS, nearDate, farDate, BDA_FOLLOW); assertEquals(test.getInfo().getTradeDate(), Optional.of(tradeDate)); assertEquals(test.getProduct(), expected); ResolvedFxSwap resolvedExpected = ResolvedFxSwap.ofForwardPoints( CurrencyAmount.of(EUR, NOTIONAL_EUR), USD, FX_RATE_NEAR, FX_RATE_PTS, nearDateAdj, farDateAdj); assertEquals(test.getProduct().resolve(REF_DATA), resolvedExpected); }
/** * Obtains a convention based on the specified currency pair, spot date offset and adjustment. * <p> * Use the {@linkplain #builder() builder} for unusual conventions. * * @param currencyPair the currency pair associated to the convention * @param spotDateOffset the spot date offset * @param businessDayAdjustment the business day adjustment to apply * @return the convention */ public static ImmutableFxSwapConvention of( CurrencyPair currencyPair, DaysAdjustment spotDateOffset, BusinessDayAdjustment businessDayAdjustment) { ArgChecker.notNull(businessDayAdjustment, "businessDayAdjustment"); return ImmutableFxSwapConvention.builder() .currencyPair(currencyPair) .spotDateOffset(spotDateOffset) .businessDayAdjustment(businessDayAdjustment) .build(); }
public void test_of_nobda() { ImmutableFxSwapConvention test = ImmutableFxSwapConvention.of(EUR_USD, PLUS_TWO_DAYS); assertEquals(test.getName(), EUR_USD.toString()); assertEquals(test.getCurrencyPair(), EUR_USD); assertEquals(test.getSpotDateOffset(), PLUS_TWO_DAYS); assertEquals(test.getBusinessDayAdjustment(), BusinessDayAdjustment.of(MODIFIED_FOLLOWING, EUTA_USNY)); }