@ImmutableValidator private void validate() { if (!currencyPair.contains(referenceCurrency)) { throw new IllegalArgumentException(Messages.format( "Reference currency {} must be one of those in the currency pair {}", referenceCurrency, currencyPair)); } }
@Override public PointSensitivityBuilder ratePointSensitivity(Currency baseCurrency, LocalDate referenceDate) { ArgChecker.isTrue( currencyPair.contains(baseCurrency), "Currency {} invalid for CurrencyPair {}", baseCurrency, currencyPair); return FxForwardSensitivity.of(currencyPair, baseCurrency, referenceDate, 1d); }
@ImmutableValidator private void validate() { if (!index.getCurrencyPair().contains(referenceCurrency)) { throw new IllegalArgumentException( Messages.format("Reference currency {} must be one of those in the FxIndex {}", referenceCurrency, index)); } }
@ImmutableValidator private void validate() { FxIndex index = observation.getIndex(); if (!index.getCurrencyPair().contains(referenceCurrency)) { throw new IllegalArgumentException( Messages.format("Reference currency {} must be one of those in the FxIndex {}", referenceCurrency, index)); } }
@ImmutableValidator private void validate() { CurrencyPair pair = index.getCurrencyPair(); if (!pair.contains(settlementCurrencyNotional.getCurrency())) { throw new IllegalArgumentException("FxIndex and settlement notional currency are incompatible"); } if (!(pair.equals(agreedFxRate.getPair()) || pair.isInverse(agreedFxRate.getPair()))) { throw new IllegalArgumentException("FxIndex and agreed FX rate are incompatible"); } }
@ImmutableValidator private void validate() { FxIndex index = observation.getIndex(); if (!index.getCurrencyPair().contains(notionalAmount.getCurrency())) { throw new IllegalArgumentException( Messages.format( "Reference currency {} must be one of those in the FxIndex {}", notionalAmount.getCurrency(), index)); } }
@ImmutableValidator private void validate() { CurrencyPair pair = observation.getIndex().getCurrencyPair(); if (!pair.contains(settlementCurrencyNotional.getCurrency())) { throw new IllegalArgumentException("FxIndex and settlement notional currency are incompatible"); } if (!(pair.equals(agreedFxRate.getPair()) || pair.isInverse(agreedFxRate.getPair()))) { throw new IllegalArgumentException("FxIndex and agreed FX rate are incompatible"); } }
@Override public double rateFxSpotSensitivity(Currency baseCurrency, LocalDate referenceDate) { ArgChecker.isTrue( currencyPair.contains(baseCurrency), "Currency {} invalid for CurrencyPair {}", baseCurrency, currencyPair); boolean inverse = baseCurrency.equals(currencyPair.getCounter()); double dfCcyBaseAtMaturity = baseCurrencyDiscountFactors.discountFactor(referenceDate); double dfCcyCounterAtMaturity = counterCurrencyDiscountFactors.discountFactor(referenceDate); double forwardRateDelta = dfCcyBaseAtMaturity / dfCcyCounterAtMaturity; return inverse ? 1d / forwardRateDelta : forwardRateDelta; }
public void test_contains_Currency_null() { CurrencyPair test = CurrencyPair.of(GBP, USD); assertThrowsIllegalArg(() -> test.contains(null)); }
@ImmutableValidator private void validate() { if (fxReset != null) { Currency notionalCcy = fxReset.getReferenceCurrency(); if (fxReset.getReferenceCurrency().equals(currency)) { throw new IllegalArgumentException(Messages.format( "Payment currency {} must not equal notional currency {} when FX reset applies", currency, notionalCcy)); } if (!fxReset.getIndex().getCurrencyPair().contains(currency)) { throw new IllegalArgumentException(Messages.format( "Payment currency {} must be one of those in the FxReset index {}", currency, fxReset.getIndex())); } } }
@Override public double rate(Currency baseCurrency, LocalDate referenceDate) { ArgChecker.isTrue( currencyPair.contains(baseCurrency), "Currency {} invalid for CurrencyPair {}", baseCurrency, currencyPair); boolean inverse = baseCurrency.equals(currencyPair.getCounter()); double dfCcyBaseAtMaturity = baseCurrencyDiscountFactors.discountFactor(referenceDate); double dfCcyCounterAtMaturity = counterCurrencyDiscountFactors.discountFactor(referenceDate); double forwardRate = fxRateProvider.fxRate(currencyPair) * (dfCcyBaseAtMaturity / dfCcyCounterAtMaturity); return inverse ? 1d / forwardRate : forwardRate; }
@ImmutableValidator private void validate() { if (rebate != null) { ArgChecker.isTrue(rebate.getAmount() > 0d, "rebate must be positive"); ArgChecker.isTrue(underlyingOption.getUnderlying().getCurrencyPair().contains(rebate.getCurrency()), "The rebate currency must be one of underlying currency pair"); } }
@ImmutableValidator private void validate() { if (rebate != null) { ArgChecker.isTrue(rebate.getAmount() > 0d, "rebate must be positive"); ArgChecker.isTrue(underlyingOption.getUnderlying().getCurrencyPair().contains(rebate.getCurrency()), "The rebate currency must be one of underlying currency pair"); } }
private static FxRate computeCross(FxRate fx1, FxRate fx2, CurrencyPair crossPairAC) { // aim is to convert AAA/BBB and BBB/CCC to AAA/CCC Currency currA = crossPairAC.getBase(); Currency currC = crossPairAC.getCounter(); // given the conventional cross rate pair, order the two rates to match boolean crossBaseCurrencyInFx1 = fx1.pair.contains(currA); FxRate fxABorBA = crossBaseCurrencyInFx1 ? fx1 : fx2; FxRate fxBCorCB = crossBaseCurrencyInFx1 ? fx2 : fx1; // extract the rates, taking the inverse if the pair is in the inverse order double rateAB = fxABorBA.getPair().getBase().equals(currA) ? fxABorBA.rate : 1d / fxABorBA.rate; double rateBC = fxBCorCB.getPair().getCounter().equals(currC) ? fxBCorCB.rate : 1d / fxBCorCB.rate; return FxRate.of(crossPairAC, rateAB * rateBC); }
@Override public double rate(FxIndexObservation observation, Currency baseCurrency) { ArgChecker.isTrue( index.getCurrencyPair().contains(baseCurrency), "Currency {} invalid for FxIndex {}", baseCurrency, index); LocalDate fixingDate = observation.getFixingDate(); double fxIndexRate = !fixingDate.isAfter(getValuationDate()) ? historicRate(observation) : forwardRate(observation); boolean inverse = baseCurrency.equals(index.getCurrencyPair().getCounter()); return (inverse ? 1d / fxIndexRate : fxIndexRate); }
@Override public PointSensitivityBuilder ratePointSensitivity(FxIndexObservation observation, Currency baseCurrency) { ArgChecker.isTrue( index.getCurrencyPair().contains(baseCurrency), "Currency {} invalid for FxIndex {}", baseCurrency, index); LocalDate fixingDate = observation.getFixingDate(); if (fixingDate.isBefore(getValuationDate()) || (fixingDate.equals(getValuationDate()) && fixings.get(fixingDate).isPresent())) { return PointSensitivityBuilder.none(); } return FxIndexSensitivity.of(observation, baseCurrency, 1d); }
private static FxSingle create( CurrencyAmount amount, FxRate fxRate, LocalDate paymentDate, BusinessDayAdjustment paymentDateAdjustment) { ArgChecker.notNull(amount, "amount"); ArgChecker.notNull(fxRate, "fxRate"); ArgChecker.notNull(paymentDate, "paymentDate"); CurrencyPair pair = fxRate.getPair(); if (!pair.contains(amount.getCurrency())) { throw new IllegalArgumentException(Messages.format( "FxRate '{}' and CurrencyAmount '{}' must have a currency in common", fxRate, amount)); } Currency currency2 = pair.getBase().equals(amount.getCurrency()) ? pair.getCounter() : pair.getBase(); CurrencyAmount amountCurrency2 = amount.convertedTo(currency2, fxRate).negated(); return create(amount, amountCurrency2, paymentDate, paymentDateAdjustment); }
private FxRateScenarioArray computeCross(FxRateScenarioArray other, CurrencyPair crossPairAC) { // aim is to convert AAA/BBB and BBB/CCC to AAA/CCC Currency currA = crossPairAC.getBase(); Currency currC = crossPairAC.getCounter(); // given the conventional cross rate pair, order the two rates to match boolean crossBaseCurrencyInFx1 = pair.contains(currA); FxRateScenarioArray fxABorBA = crossBaseCurrencyInFx1 ? this : other; FxRateScenarioArray fxBCorCB = crossBaseCurrencyInFx1 ? other : this; // extract the rates, taking the inverse if the pair is in the inverse order DoubleArray ratesAB = fxABorBA.getPair().getBase().equals(currA) ? fxABorBA.rates : fxABorBA.rates.map(v -> 1 / v); DoubleArray ratesBC = fxBCorCB.getPair().getCounter().equals(currC) ? fxBCorCB.rates : fxBCorCB.rates.map(v -> 1 / v); return FxRateScenarioArray.of(crossPairAC, ratesAB.multipliedBy(ratesBC)); }