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); }
@Override public FxResetCalculation build() { preBuild(this); return new FxResetCalculation( index, referenceCurrency, fixingRelativeTo, fixingDateOffset, initialNotionalValue); }
/** * 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); }
/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(FxResetCalculation beanToCopy) { this.index = beanToCopy.getIndex(); this.referenceCurrency = beanToCopy.getReferenceCurrency(); this.fixingRelativeTo = beanToCopy.getFixingRelativeTo(); this.fixingDateOffset = beanToCopy.getFixingDateOffset(); this.initialNotionalValue = beanToCopy.initialNotionalValue; }
@ImmutableValidator private void validate() { if (fxReset != null) { if (fxReset.getReferenceCurrency().equals(currency)) { throw new IllegalArgumentException( Messages.format("Currency {} must not equal FxResetCalculation reference currency {}", currency, fxReset.getReferenceCurrency())); } if (!fxReset.getIndex().getCurrencyPair().contains(currency)) { throw new IllegalArgumentException( Messages.format("Currency {} must be one of those in the FxResetCalculation index {}", currency, fxReset.getIndex())); } if (!(initialExchange || intermediateExchange || finalExchange)) { throw new IllegalArgumentException( Messages.format( "FxResetCalculation index {} was specified but schedule does not include any notional exchanges", fxReset.getIndex())); } } }
private IntFunction<CurrencyAmount> getNotionalSupplierFunction( NotionalSchedule notionalSchedule, DoubleArray notionals, PayReceive payReceive) { boolean hasInitialFxNotional = notionalSchedule.getFxReset().isPresent() && notionalSchedule.getFxReset().get().getInitialNotionalValue().isPresent(); return index -> { if (hasInitialFxNotional && index == 0) { FxResetCalculation fxReset = notionalSchedule.getFxReset().get(); //If Fx reset leg with fixed initial notional then return the fixed amount in the payment currency double notional = payReceive.normalize(fxReset.getInitialNotionalValue().getAsDouble()); Currency currency = fxReset.getIndex().getCurrencyPair().other(fxReset.getReferenceCurrency()); return CurrencyAmount.of(currency, notional); } else { double notional = payReceive.normalize(notionals.get(index)); return CurrencyAmount.of(notionalSchedule.getCurrency(), notional); } }; }
public void test_resolve_initial_notional_override() { FxResetCalculation base = FxResetCalculation.builder() .index(EUR_GBP_ECB) .referenceCurrency(GBP) .fixingDateOffset(MINUS_TWO_DAYS) .initialNotionalValue(100000d) .build(); Optional<FxReset> fxResetFirstPeriod = base.resolve(REF_DATA).apply(0, SchedulePeriod.of(DATE_2014_03_31, DATE_2014_06_30)); assertFalse(fxResetFirstPeriod.isPresent()); Optional<FxReset> fxResetSecondPeriod = base.resolve(REF_DATA).apply(1, SchedulePeriod.of(DATE_2014_03_31, DATE_2014_06_30)); assertTrue(fxResetSecondPeriod.isPresent()); }
if (fxIndexOpt.isPresent()) { FxIndex fxIndex = fxIndexOpt.get(); FxResetCalculation.Builder fxResetBuilder = FxResetCalculation.builder(); fxResetBuilder.index(fxIndex); fxResetBuilder.referenceCurrency(notionalCurrencyOpt.orElse(fxIndex.getCurrencyPair().other(currency)));
@Override public void collectCurrencies(ImmutableSet.Builder<Currency> builder) { builder.add(getCurrency()); calculation.collectCurrencies(builder); notionalSchedule.getFxReset().ifPresent(fxReset -> builder.add(fxReset.getReferenceCurrency())); }
@Override public void collectIndices(ImmutableSet.Builder<Index> builder) { calculation.collectIndices(builder); notionalSchedule.getFxReset().ifPresent(fxReset -> builder.add(fxReset.getIndex())); }
notionalSchedule.getFxReset().map(calc -> calc.resolve(refData)).orElse((i, p) -> Optional.empty());
public void test_resolve_beforeStart_weekend() { FxResetCalculation base = FxResetCalculation.builder() .index(EUR_GBP_ECB) .referenceCurrency(GBP) .fixingDateOffset(MINUS_TWO_DAYS) .build(); Optional<FxReset> test = base.resolve(REF_DATA).apply(0, SchedulePeriod.of(DATE_2014_03_31, DATE_2014_06_30)); assertEquals(test, Optional.of(FxReset.of(FxIndexObservation.of(EUR_GBP_ECB, date(2014, 3, 27), REF_DATA), GBP))); }
public void test_invalidCurrency() { assertThrowsIllegalArg(() -> FxResetCalculation.builder() .index(EUR_USD_ECB) .referenceCurrency(GBP) .fixingDateOffset(MINUS_TWO_DAYS) .build()); }
private String notional(SwapLeg leg) { if (leg instanceof RateCalculationSwapLeg) { RateCalculationSwapLeg rcLeg = (RateCalculationSwapLeg) leg; NotionalSchedule notionalSchedule = rcLeg.getNotionalSchedule(); ValueSchedule amount = notionalSchedule.getAmount(); double notional = amount.getInitialValue(); String vary = !amount.getSteps().isEmpty() || amount.getStepSequence().isPresent() ? " variable" : ""; Currency currency = notionalSchedule.getFxReset().map(fxr -> fxr.getReferenceCurrency()).orElse(rcLeg.getCurrency()); return SummarizerUtils.amount(currency, notional) + vary; } if (leg instanceof RatePeriodSwapLeg) { RatePeriodSwapLeg rpLeg = (RatePeriodSwapLeg) leg; return SummarizerUtils.amount(rpLeg.getPaymentPeriods().get(0).getNotionalAmount()); } return ""; }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 100346066: // index return ((FxResetCalculation) bean).getIndex(); case 727652476: // referenceCurrency return ((FxResetCalculation) bean).getReferenceCurrency(); case 232554996: // fixingRelativeTo return ((FxResetCalculation) bean).getFixingRelativeTo(); case 873743726: // fixingDateOffset return ((FxResetCalculation) bean).getFixingDateOffset(); case -931164883: // initialNotionalValue return ((FxResetCalculation) bean).initialNotionalValue; } return super.propertyGet(bean, propertyName, quiet); }
public void test_resolve_beforeStart_threeDays() { FxResetCalculation base = FxResetCalculation.builder() .index(EUR_GBP_ECB) .referenceCurrency(GBP) .fixingDateOffset(MINUS_THREE_DAYS) .build(); Optional<FxReset> test = base.resolve(REF_DATA).apply(0, SchedulePeriod.of(DATE_2014_03_31, DATE_2014_06_30)); assertEquals(test, Optional.of(FxReset.of(FxIndexObservation.of(EUR_GBP_ECB, date(2014, 3, 26), REF_DATA), GBP))); }
public void test_serialization() { FxResetCalculation test = FxResetCalculation.builder() .index(EUR_GBP_ECB) .referenceCurrency(GBP) .fixingDateOffset(MINUS_TWO_DAYS) .build(); assertSerialization(test); }
public void test_resolve_beforeEnd_weekend() { FxResetCalculation base = FxResetCalculation.builder() .index(EUR_GBP_ECB) .referenceCurrency(GBP) .fixingDateOffset(MINUS_TWO_DAYS) .fixingRelativeTo(FxResetFixingRelativeTo.PERIOD_END) .build(); Optional<FxReset> test = base.resolve(REF_DATA).apply(0, SchedulePeriod.of(DATE_2014_03_31, DATE_2014_06_30)); assertEquals(test, Optional.of(FxReset.of(FxIndexObservation.of(EUR_GBP_ECB, date(2014, 6, 26), REF_DATA), GBP))); }
public void coverage() { FxResetCalculation test = FxResetCalculation.builder() .index(EUR_GBP_ECB) .referenceCurrency(GBP) .fixingDateOffset(MINUS_TWO_DAYS) .build(); coverImmutableBean(test); FxResetCalculation test2 = FxResetCalculation.builder() .index(EUR_USD_ECB) .referenceCurrency(Currency.EUR) .fixingDateOffset(MINUS_THREE_DAYS) .fixingRelativeTo(FxResetFixingRelativeTo.PERIOD_END) .build(); coverBeanEquals(test, test2); }
public void test_builder() { FxResetCalculation test = FxResetCalculation.builder() .index(EUR_GBP_ECB) .referenceCurrency(GBP) .fixingDateOffset(MINUS_TWO_DAYS) .fixingRelativeTo(FxResetFixingRelativeTo.PERIOD_START) .build(); assertEquals(test.getIndex(), EUR_GBP_ECB); assertEquals(test.getReferenceCurrency(), GBP); assertEquals(test.getFixingDateOffset(), MINUS_TWO_DAYS); assertEquals(test.getFixingRelativeTo(), FxResetFixingRelativeTo.PERIOD_START); }