/** * Gets the currency pair of the FX index. * * @return the currency pair of the index */ public CurrencyPair getCurrencyPair() { return index.getCurrencyPair(); }
/** * Creates an instance from an index and fixing date. * <p> * The reference data is used to find the maturity date from the fixing date. * * @param index the index * @param fixingDate the fixing date * @param refData the reference data to use when resolving holiday calendars * @return the rate observation */ public static FxIndexObservation of(FxIndex index, LocalDate fixingDate, ReferenceData refData) { LocalDate maturityDate = index.calculateMaturityFromFixing(fixingDate, refData); return new FxIndexObservation(index, fixingDate, maturityDate); }
@ImmutablePreBuild private static void preBuild(Builder builder) { if (builder.fixingDateOffset == null && builder.index != null) { builder.fixingDateOffset = builder.index.getFixingDateOffset(); } }
public void test_ecb_eur_gbp_dates() { FxIndex test = FxIndices.EUR_GBP_ECB; assertEquals(test.getFixingDateOffset(), DaysAdjustment.ofBusinessDays(-2, EUTA.combinedWith(GBLO))); assertEquals(test.getMaturityDateOffset(), DaysAdjustment.ofBusinessDays(2, EUTA.combinedWith(GBLO))); assertEquals(test.calculateMaturityFromFixing(date(2014, 10, 13), REF_DATA), date(2014, 10, 15)); assertEquals(test.calculateFixingFromMaturity(date(2014, 10, 15), REF_DATA), date(2014, 10, 13)); // weekend assertEquals(test.calculateMaturityFromFixing(date(2014, 10, 16), REF_DATA), date(2014, 10, 20)); assertEquals(test.calculateFixingFromMaturity(date(2014, 10, 20), REF_DATA), date(2014, 10, 16)); assertEquals(test.calculateMaturityFromFixing(date(2014, 10, 17), REF_DATA), date(2014, 10, 21)); assertEquals(test.calculateFixingFromMaturity(date(2014, 10, 21), REF_DATA), date(2014, 10, 17)); // input date is Sunday assertEquals(test.calculateMaturityFromFixing(date(2014, 10, 19), REF_DATA), date(2014, 10, 22)); assertEquals(test.calculateFixingFromMaturity(date(2014, 10, 19), REF_DATA), date(2014, 10, 16)); // skip maturity over EUR (1st May) and GBP (5th May) holiday assertEquals(test.calculateMaturityFromFixing(date(2014, 4, 30), REF_DATA), date(2014, 5, 6)); assertEquals(test.calculateFixingFromMaturity(date(2014, 5, 6), REF_DATA), date(2014, 4, 30)); // resolve assertEquals(test.resolve(REF_DATA).apply(date(2014, 5, 6)), FxIndexObservation.of(test, date(2014, 5, 6), REF_DATA)); }
builder.amount(ValueSchedule.of(LoaderUtils.parseDouble(getValueWithFallback(row, leg, NOTIONAL_FIELD)))); Optional<FxIndex> fxIndexOpt = findValue(row, leg, FX_RESET_INDEX_FIELD).map(s -> FxIndex.of(s)); Optional<Currency> notionalCurrencyOpt = findValue(row, leg, NOTIONAL_CURRENCY_FIELD).map(s -> Currency.of(s)); Optional<FxResetFixingRelativeTo> fxFixingRelativeToOpt = findValue(row, leg, FX_RESET_RELATIVE_TO_FIELD) FxResetCalculation.Builder fxResetBuilder = FxResetCalculation.builder(); fxResetBuilder.index(fxIndex); fxResetBuilder.referenceCurrency(notionalCurrencyOpt.orElse(fxIndex.getCurrencyPair().other(currency))); fxFixingRelativeToOpt.ifPresent(v -> fxResetBuilder.fixingRelativeTo(v)); fxResetAdjOpt.ifPresent(v -> fxResetBuilder.fixingDateOffset(v));
public void test_dates() { FxIndex test = ImmutableFxIndex.builder() .name("Test") .currencyPair(CurrencyPair.of(EUR, GBP)) .fixingCalendar(NO_HOLIDAYS) .maturityDateOffset(DaysAdjustment.ofCalendarDays(2)) .build(); assertEquals(test.calculateMaturityFromFixing(date(2014, 10, 13), REF_DATA), date(2014, 10, 15)); assertEquals(test.calculateFixingFromMaturity(date(2014, 10, 15), REF_DATA), date(2014, 10, 13)); // weekend assertEquals(test.calculateMaturityFromFixing(date(2014, 10, 16), REF_DATA), date(2014, 10, 18)); assertEquals(test.calculateFixingFromMaturity(date(2014, 10, 18), REF_DATA), date(2014, 10, 16)); assertEquals(test.calculateMaturityFromFixing(date(2014, 10, 17), REF_DATA), date(2014, 10, 19)); assertEquals(test.calculateFixingFromMaturity(date(2014, 10, 19), REF_DATA), date(2014, 10, 17)); // input date is Sunday assertEquals(test.calculateMaturityFromFixing(date(2014, 10, 19), REF_DATA), date(2014, 10, 21)); assertEquals(test.calculateFixingFromMaturity(date(2014, 10, 19), REF_DATA), date(2014, 10, 17)); }
@Override public ResolvedFxNdf resolve(ReferenceData refData) { LocalDate fixingDate = index.calculateFixingFromMaturity(paymentDate, refData); return ResolvedFxNdf.builder() .settlementCurrencyNotional(settlementCurrencyNotional) .agreedFxRate(agreedFxRate) .observation(FxIndexObservation.of(index, fixingDate, refData)) .paymentDate(paymentDate) .build(); }
@Test(dataProvider = "name") public void test_of_lookup(FxIndex convention, String name) { assertEquals(FxIndex.of(name), convention); }
@Test(dataProvider = "name") public void test_extendedEnum(FxIndex convention, String name) { ImmutableMap<String, FxIndex> map = FxIndex.extendedEnum().lookupAll(); assertEquals(map.get(name), convention); }
private static ImmutableMap<String, FxIndex> loadFromCsv() { List<ResourceLocator> resources = ResourceConfig.orderedResources("FxIndexData.csv"); Map<String, FxIndex> map = new HashMap<>(); for (ResourceLocator resource : resources) { try { CsvFile csv = CsvFile.of(resource.getCharSource(), true); for (CsvRow row : csv.rows()) { FxIndex parsed = parseFxIndex(row); map.put(parsed.getName(), parsed); map.putIfAbsent(parsed.getName().toUpperCase(Locale.ENGLISH), parsed); } } catch (RuntimeException ex) { log.log(Level.SEVERE, "Error processing resource as FX Index CSV file: " + resource, ex); return ImmutableMap.of(); } } return ImmutableMap.copyOf(map); }
/** * Resolves this adjustment using the specified reference data. * <p> * Calling this method resolves the holiday calendar, returning a function that * can convert a {@code SchedulePeriod} and period index pair to an optional {@code FxReset}. * * The conversion locks the fixing date based on the specified schedule period * and the data held in this object. * * @param refData the reference data to use when resolving * @return the resolved function * @throws ReferenceDataNotFoundException if an identifier cannot be resolved in the reference data * @throws RuntimeException if the calculation is invalid */ BiFunction<Integer, SchedulePeriod, Optional<FxReset>> resolve(ReferenceData refData) { DateAdjuster fixingDateAdjuster = fixingDateOffset.resolve(refData); Function<LocalDate, FxIndexObservation> obsFn = index.resolve(refData); return (periodIndex, period) -> buildFxReset(periodIndex, period, fixingDateAdjuster, obsFn); }
/** * Create a yield curve bundle with three curves. * One called "Discounting EUR" with a constant rate of 2.50%, one called "Discounting USD" * with a constant rate of 1.00% and one called "Discounting GBP" with a constant rate of 2.00%; * "Discounting KRW" with a constant rate of 3.21%; * * @param valuationDate the valuation date * @param fxIndex the FX index * @param spotRate the spot rate for the index * @return the provider */ public static RatesProvider createProvider(LocalDate valuationDate, FxIndex fxIndex, double spotRate) { return ImmutableRatesProvider.builder(valuationDate) .discountCurve(EUR, EUR_DSC) .discountCurve(USD, USD_DSC) .discountCurve(GBP, GBP_DSC) .discountCurve(KRW, KRW_DSC) .fxRateProvider(FX_MATRIX) .timeSeries( fxIndex, LocalDateDoubleTimeSeries.of(fxIndex.calculateFixingFromMaturity(valuationDate, REF_DATA), spotRate)) .build(); }
public void test_of_lookup_notFound() { assertThrowsIllegalArg(() -> FxIndex.of("Rubbish")); }
/** * Obtains an instance from the specified unique name. * * @param uniqueName the unique name * @return the index * @throws IllegalArgumentException if the name is not known */ @FromString public static FxIndex of(String uniqueName) { ArgChecker.notNull(uniqueName, "uniqueName"); return extendedEnum().lookup(uniqueName); }
@Test(dataProvider = "name") public void test_name(FxIndex convention, String name) { assertEquals(convention.getName(), name); }
@Override public CurrencyPair getCurrencyPair() { return index.getCurrencyPair().toConventional(); }
public void test_toFxForwardSensitivity() { FxIndexSensitivity test = FxIndexSensitivity.of(GBP_USD_WM_OBS, GBP, USD, SENSITIVITY_VALUE); LocalDate maturityDate = GBP_USD_WM.calculateMaturityFromFixing(FIXING_DATE, REF_DATA); FxForwardSensitivity expected = FxForwardSensitivity.of(CurrencyPair.of(GBP, USD), GBP, maturityDate, USD, SENSITIVITY_VALUE); assertEquals(test.toFxForwardSensitivity(), expected); }
public void test_builder_defaults() { FxResetCalculation test = FxResetCalculation.builder() .index(EUR_GBP_ECB) .referenceCurrency(GBP) .build(); assertEquals(test.getIndex(), EUR_GBP_ECB); assertEquals(test.getReferenceCurrency(), GBP); assertEquals(test.getFixingDateOffset(), EUR_GBP_ECB.getFixingDateOffset()); assertEquals(test.getFixingRelativeTo(), FxResetFixingRelativeTo.PERIOD_START); }