@Override public void collectIndices(ImmutableSet.Builder<Index> builder) { calculation.collectIndices(builder); notionalSchedule.getFxReset().ifPresent(fxReset -> builder.add(fxReset.getIndex())); }
/** * 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())); } } }
@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); }
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_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); }
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); }