/** * Returns the set of currencies contains in the pair. * * @return the set of currencies, with iteration in conventional order */ public ImmutableSet<Currency> toSet() { if (isConventional()) { return ImmutableSet.of(base, counter); } else { return ImmutableSet.of(counter, base); } }
/** * Returns the market convention currency pair for the currencies in the pair. * <p> * If {@link #isConventional()} is {@code true} this method returns {@code this}, otherwise * it returns the {@link #inverse} pair. * * @return the market convention currency pair for the currencies in the pair */ public CurrencyPair toConventional() { return isConventional() ? this : inverse(); }
/** * Returns an FX rate object representing the market convention rate between the two currencies. * <p> * If the currency pair is the market convention pair, this method returns {@code this}, otherwise * it returns an {@code FxRate} with the inverse currency pair and reciprocal rate. * * @return an FX rate object representing the market convention rate between the two currencies */ public FxRate toConventional() { return pair.isConventional() ? this : FxRate.of(pair.toConventional(), 1 / rate); }
public void test_isConventional() { assertEquals(CurrencyPair.of(GBP, USD).isConventional(), true); assertEquals(CurrencyPair.of(USD, GBP).isConventional(), false); // There is no configuration for GBP/BRL or BRL/GBP so the ordering list is used to choose a convention pair // GBP is in the currency order list and BRL isn't so GBP is the base assertEquals(CurrencyPair.of(GBP, BRL).isConventional(), true); assertEquals(CurrencyPair.of(BRL, GBP).isConventional(), false); // There is no configuration for BHD/BRL or BRL/BHD and neither are in the list specifying currency priority order. // Lexicographical ordering is used assertEquals(CurrencyPair.of(BHD, BRL).isConventional(), true); assertEquals(CurrencyPair.of(BRL, BHD).isConventional(), false); assertEquals(CurrencyPair.of(GBP, GBP).isConventional(), true); }
@ImmutablePreBuild private static void preBuild(Builder builder) { // swap order to be base/counter if reverse is conventional // this handles deserialization where the base/counter rules differ from those applicable at serialization Payment base = builder.baseCurrencyPayment; Payment counter = builder.counterCurrencyPayment; CurrencyPair pair = CurrencyPair.of(counter.getCurrency(), base.getCurrency()); if (pair.isConventional()) { builder.baseCurrencyPayment = counter; builder.counterCurrencyPayment = base; } }
@ImmutablePreBuild private static void preBuild(Builder builder) { // swap order to be base/counter if reverse is conventional // this handled deserialization where the base/counter rules differ from those applicable at serialization Payment base = builder.baseCurrencyPayment; Payment counter = builder.counterCurrencyPayment; CurrencyPair pair = CurrencyPair.of(counter.getCurrency(), base.getCurrency()); if (pair.isConventional()) { builder.baseCurrencyPayment = counter; builder.counterCurrencyPayment = base; } }
/** * Creates an {@code ResolvedFxSingle} from two equivalent payments in different currencies. * <p> * The payments must be of the correct type, one pay and one receive. * 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. * * @param payment1 the first payment * @param payment2 the second payment * @return the resolved foreign exchange transaction */ public static ResolvedFxSingle of(Payment payment1, Payment payment2) { CurrencyPair pair = CurrencyPair.of(payment2.getCurrency(), payment1.getCurrency()); if (pair.isConventional()) { return new ResolvedFxSingle(payment2, payment1); } else { return new ResolvedFxSingle(payment1, payment2); } }
private static FxSingle create( Payment payment1, Payment payment2, BusinessDayAdjustment paymentDateAdjustment) { ArgChecker.notNull(payment1, "payment1"); ArgChecker.notNull(payment2, "payment2"); CurrencyPair pair = CurrencyPair.of(payment1.getCurrency(), payment2.getCurrency()); if (pair.isConventional()) { return new FxSingle(payment1, payment2, paymentDateAdjustment); } else { return new FxSingle(payment2, payment1, paymentDateAdjustment); } }