/** * Checks if this currency pair is the inverse of the specified pair. * <p> * This could be used to check if an FX rate specified in one currency pair needs inverting. * * @param other the other currency pair * @return true if the currency is the inverse of the specified pair */ public boolean isInverse(CurrencyPair other) { ArgChecker.notNull(other, "currencyPair"); return base.equals(other.counter) && counter.equals(other.base); }
@Override public BondFutureOptionSensitivity withCurrency(Currency currency) { if (this.currency.equals(currency)) { return this; } return new BondFutureOptionSensitivity( volatilitiesName, expiry, futureExpiryDate, strikePrice, futurePrice, currency, sensitivity); }
@Override public IborCapletFloorletSensitivity withCurrency(Currency currency) { if (this.currency.equals(currency)) { return this; } return new IborCapletFloorletSensitivity(volatilitiesName, expiry, strike, forward, currency, sensitivity); }
@Override public IborRateSensitivity withCurrency(Currency currency) { if (this.currency.equals(currency)) { return this; } return new IborRateSensitivity(observation, currency, sensitivity); }
@Override public OvernightRateSensitivity withCurrency(Currency currency) { if (this.currency.equals(currency)) { return this; } return new OvernightRateSensitivity(observation, endDate, currency, sensitivity); }
@Override public SwaptionSensitivity withCurrency(Currency currency) { if (this.currency.equals(currency)) { return this; } return new SwaptionSensitivity(volatilitiesName, expiry, tenor, strike, forward, currency, sensitivity); }
@Override public IborCapletFloorletSabrSensitivity withCurrency(Currency currency) { if (this.currency.equals(currency)) { return this; } return new IborCapletFloorletSabrSensitivity(volatilitiesName, expiry, sensitivityType, currency, sensitivity); }
@Override public IborFutureOptionSensitivity withCurrency(Currency currency) { if (this.currency.equals(currency)) { return this; } return new IborFutureOptionSensitivity( volatilitiesName, expiry, fixingDate, strikePrice, futurePrice, currency, sensitivity); }
@Override public double fxRate(Currency baseCurrency, Currency counterCurrency) { if (baseCurrency.equals(counterCurrency)) { return 1d; } throw new UnsupportedOperationException("FxRate not found: " + baseCurrency + "/" + counterCurrency); }
/** * Checks if this multi-amount contains an amount for the specified currency. * * @param currency the currency to find * @return true if this amount contains a value for the currency */ public boolean contains(Currency currency) { ArgChecker.notNull(currency, "currency"); return amounts.stream().anyMatch(ca -> ca.getCurrency().equals(currency)); }
@Override public CurrencyAmountArray convertedTo(Currency resultCurrency, FxRateProvider fxRateProvider) { if (currency.equals(resultCurrency)) { return this; } double fxRate = fxRateProvider.fxRate(currency, resultCurrency); DoubleArray convertedValues = values.multipliedBy(fxRate); return new CurrencyAmountArray(resultCurrency, convertedValues); }
@Override public DummyPointSensitivity withCurrency(Currency currency) { if (this.currency.equals(currency)) { return this; } return new DummyPointSensitivity(curveCurrency, date, currency, sensitivity); }
public void test_convertedTo_rateProvider_conversionSize1() { FxRateProvider provider = (ccy1, ccy2) -> { if (ccy1.equals(CCY1) && ccy2.equals(CCY2)) { return 2.5d; } throw new IllegalArgumentException(); }; MultiCurrencyAmount test = MultiCurrencyAmount.of(CA1); assertEquals(test.convertedTo(CCY2, provider), CurrencyAmount.of(CCY2, AMT1 * 2.5d)); }
@ImmutableValidator private void validate() { if (pair.getBase().equals(pair.getCounter()) && !rates.stream().allMatch(v -> v == 1d)) { throw new IllegalArgumentException("Conversion rate between identical currencies must be one"); } }
@ImmutableValidator private void validate() { if (baseCurrencyPayment.getCurrency().equals(counterCurrencyPayment.getCurrency())) { throw new IllegalArgumentException("Payments must have different currencies"); } if ((baseCurrencyPayment.getAmount() != 0d || counterCurrencyPayment.getAmount() != 0d) && Math.signum(baseCurrencyPayment.getAmount()) != -Math.signum(counterCurrencyPayment.getAmount())) { throw new IllegalArgumentException("Payments must have different signs"); } ArgChecker.inOrderOrEqual(baseCurrencyPayment.getDate(), counterCurrencyPayment.getDate(), "baseCurrencyPayment.date", "counterCurrencyPayment.date"); }
@ImmutableValidator private void validate() { ArgChecker.inOrderNotEqual( nearLeg.getPaymentDate(), farLeg.getPaymentDate(), "nearLeg.paymentDate", "farLeg.paymentDate"); if (!nearLeg.getBaseCurrencyAmount().getCurrency().equals(farLeg.getBaseCurrencyAmount().getCurrency()) || !nearLeg.getCounterCurrencyAmount().getCurrency().equals(farLeg.getCounterCurrencyAmount().getCurrency())) { throw new IllegalArgumentException("Legs must have the same currency pair"); } if (signum(nearLeg.getBaseCurrencyAmount().getAmount()) == signum(farLeg.getBaseCurrencyAmount().getAmount())) { throw new IllegalArgumentException("Legs must have payments flowing in opposite directions"); } }
/** * Gets the non-deliverable currency. * <p> * Returns the currency that is not the settlement currency. * * @return the currency that is not to be settled */ public Currency getNonDeliverableCurrency() { Currency base = agreedFxRate.getPair().getBase(); return base.equals(getSettlementCurrency()) ? agreedFxRate.getPair().getCounter() : base; }
@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; }
@ImmutableValidator private void validate() { ArgChecker.isTrue( fixedLeg.getCurrency().equals(floatingLeg.getCurrency()), Messages.format( "Swap leg conventions must have same currency but found {} and {}, conventions {} and {}", fixedLeg.getCurrency(), floatingLeg.getCurrency(), fixedLeg, floatingLeg)); }