@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 3433178: // pair return ((FxRate) bean).getPair(); case 3493088: // rate return ((FxRate) bean).getRate(); } return super.propertyGet(bean, propertyName, quiet); }
/** * 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; }
@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"); } }
/** * Creates an {@code FxSwap} using decimal forward points. * <p> * The FX rate at the near date is specified as {@code nearRate}. * The FX rate at the far date is equal to {@code nearRate + forwardPoints}. * Thus "FX forward spread" might be a better name for the concept. * <p> * The two currencies are specified by the near FX rate. * The amount must be specified using one of the currencies of the near FX rate. * The near date must be before the far date. * Conventions will be used to determine the base and counter currency. * * @param amount the amount being exchanged, positive if being received in the near leg, negative if being paid * @param nearRate the near FX rate * @param decimalForwardPoints the decimal forward points, where the far FX rate is {@code (nearRate + forwardPoints)} * @param nearDate the near value date * @param farDate the far value date * @return the FX swap * @throws IllegalArgumentException if the FX rate and amount do not have a currency in common */ public static FxSwap ofForwardPoints( CurrencyAmount amount, FxRate nearRate, double decimalForwardPoints, LocalDate nearDate, LocalDate farDate) { FxRate farRate = FxRate.of(nearRate.getPair(), nearRate.fxRate(nearRate.getPair()) + decimalForwardPoints); return of(amount, nearRate, nearDate, farRate, farDate); }
@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"); } }
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); }
if (!nearRate.getPair().contains(currency1)) { throw new IllegalArgumentException(Messages.format( "FxRate '{}' and CurrencyAmount '{}' must have a currency in common", nearRate, amount)); if (!nearRate.getPair().toConventional().equals(farRate.getPair().toConventional())) { throw new IllegalArgumentException(Messages.format( "FxRate '{}' and FxRate '{}' must contain the same currencies", nearRate, farRate));
public void test_of_CurrencyCurrencyDouble_reverseStandardOrder() { FxRate test = FxRate.of(USD, GBP, 0.8d); assertEquals(test.getPair(), CurrencyPair.of(USD, GBP)); assertEquals(test.fxRate(USD, GBP), 0.8d, 0); assertEquals(test.toString(), "USD/GBP 0.8"); }
public void test_of_CurrencyCurrencyDouble_same() { FxRate test = FxRate.of(USD, USD, 1d); assertEquals(test.getPair(), CurrencyPair.of(USD, USD)); assertEquals(test.fxRate(USD, USD), 1d, 0); assertEquals(test.toString(), "USD/USD 1"); }
public void test_of_CurrencyCurrencyDouble() { FxRate test = FxRate.of(GBP, USD, 1.5d); assertEquals(test.getPair(), CurrencyPair.of(GBP, USD)); assertEquals(test.fxRate(GBP, USD), 1.5d, 0); assertEquals(test.toString(), "GBP/USD 1.5"); }
@Override public MarketDataBox<FxRate> applyTo(MarketDataBox<FxRate> marketData, ReferenceData refData) { log.debug("Applying {} shift to FX rate '{}'", shiftType, marketData.getValue(0).getPair().toString()); return marketData.mapWithIndex( getScenarioCount(), (fxRate, scenarioIndex) -> FxRate.of( currencyPair, shiftType.applyShift(fxRate.fxRate(currencyPair), shiftAmount.get(scenarioIndex)))); }
if (!nearRate.getPair().contains(currency1)) { throw new IllegalArgumentException(Messages.format( "FxRate '{}' and CurrencyAmount '{}' must have a currency in common", nearRate, amount)); if (!nearRate.getPair().toConventional().equals(farRate.getPair().toConventional())) { throw new IllegalArgumentException(Messages.format( "FxRate '{}' and FxRate '{}' must contain the same currencies", nearRate, farRate));
public void test_of_CurrencyPairDouble() { FxRate test = FxRate.of(CurrencyPair.of(GBP, USD), 1.5d); assertEquals(test.getPair(), CurrencyPair.of(GBP, USD)); assertEquals(test.fxRate(GBP, USD), 1.5d, 0); assertEquals(test.toString(), "GBP/USD 1.5"); }
public void test_of_CurrencyPairDouble_reverseStandardOrder() { FxRate test = FxRate.of(CurrencyPair.of(USD, GBP), 0.8d); assertEquals(test.getPair(), CurrencyPair.of(USD, GBP)); assertEquals(test.fxRate(USD, GBP), 0.8d, 0); assertEquals(test.toString(), "USD/GBP 0.8"); }
public void test_of_CurrencyPairDouble_same() { FxRate test = FxRate.of(CurrencyPair.of(USD, USD), 1d); assertEquals(test.getPair(), CurrencyPair.of(USD, USD)); assertEquals(test.fxRate(USD, USD), 1d, 0); assertEquals(test.toString(), "USD/USD 1"); }
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); }
/** * Creates an {@code ResolvedFxSingle} using a rate. * <p> * This create an FX specifying a value date, notional in one currency, the second currency * and the FX rate between the two. * The currencies of the payments must differ. * <p> * This factory identifies the currency pair of the exchange and assigns the payments * to match the base or counter currency of the standardized currency pair. * For example, a EUR/USD exchange always has EUR as the base payment and USD as the counter payment. * <p> * No payment date adjustments apply. * * @param amountCurrency1 the amount of the near leg in the first currency * @param fxRate the near FX rate * @param paymentDate date that the FX settles * @return the resolved foreign exchange transaction */ public static ResolvedFxSingle of(CurrencyAmount amountCurrency1, FxRate fxRate, LocalDate paymentDate) { CurrencyPair pair = fxRate.getPair(); ArgChecker.isTrue(pair.contains(amountCurrency1.getCurrency())); Currency currency2 = pair.getBase().equals(amountCurrency1.getCurrency()) ? pair.getCounter() : pair.getBase(); CurrencyAmount amountCurrency2 = amountCurrency1.convertedTo(currency2, fxRate).negated(); return ResolvedFxSingle.of(Payment.of(amountCurrency1, paymentDate), Payment.of(amountCurrency2, paymentDate)); }