public final class CurrencyPair extends Object implements Serializable
This could be used to identify a pair of currencies for quoting rates in FX deals.
See FxRate for the representation that contains a rate.
It is recommended to define currencies in advance using the CurrencyPair.ini file.
Standard configuration includes many commonly used currency pairs.
Only currencies listed in configuration will be returned by getAvailablePairs().
If a pair is requested that is not defined in configuration, it will still be created,
however the market convention information will be generated.
This class is immutable and thread-safe.
| Modifier and Type | Method and Description |
|---|---|
boolean |
contains(Currency currency)
Checks if the currency pair contains the supplied currency as either its base or counter.
|
Optional<CurrencyPair> |
cross(CurrencyPair other)
Finds the currency pair that is a cross between this pair and the other pair.
|
boolean |
equals(Object obj)
Checks if this currency pair equals another.
|
static Set<CurrencyPair> |
getAvailablePairs()
Obtains the set of configured currency pairs.
|
Currency |
getBase()
Gets the base currency of the pair.
|
Currency |
getCounter()
Gets the counter currency of the pair.
|
int |
getRateDigits()
Gets the number of digits in the rate.
|
int |
hashCode()
Returns a suitable hash code for the currency.
|
CurrencyPair |
inverse()
Gets the inverse currency pair.
|
boolean |
isConventional()
Checks if this currency pair is a conventional currency pair.
|
boolean |
isIdentity()
Checks if this currency pair is an identity pair.
|
boolean |
isInverse(CurrencyPair other)
Checks if this currency pair is the inverse of the specified pair.
|
static CurrencyPair |
of(Currency base,
Currency counter)
Obtains an instance from two currencies.
|
Currency |
other(Currency currency)
Finds the other currency in the pair.
|
static CurrencyPair |
parse(String pairStr)
Parses a currency pair from a string with format AAA/BBB.
|
CurrencyPair |
toConventional()
Returns the market convention currency pair for the currencies in the pair.
|
ImmutableSet<Currency> |
toSet()
Returns the set of currencies contains in the pair.
|
String |
toString()
Returns the formatted string version of the currency pair.
|
public static Set<CurrencyPair> getAvailablePairs()
This contains all the currency pairs that have been defined in configuration. Any currency pair instances that have been dynamically created are not included.
public static CurrencyPair of(Currency base, Currency counter)
The first currency is the base and the second is the counter. The two currencies may be the same.
base - the base currencycounter - the counter currencypublic static CurrencyPair parse(String pairStr)
The parsed format is '${baseCurrency}/${counterCurrency}'. Currency parsing is case insensitive.
pairStr - the currency pair as a string AAA/BBBIllegalArgumentException - if the pair cannot be parsedpublic CurrencyPair inverse()
The inverse pair has the same currencies but in reverse order.
public boolean contains(Currency currency)
currency - the currency to check against the pairpublic Currency other(Currency currency)
If the pair is AAA/BBB, then passing in AAA will return BBB, and passing in BBB will return AAA. Passing in CCC will throw an exception.
currency - the currency to checkIllegalArgumentException - if the specified currency is not one of those in the pairpublic boolean isIdentity()
The identity pair is one where the base and counter currency are the same..
public boolean isInverse(CurrencyPair other)
This could be used to check if an FX rate specified in one currency pair needs inverting.
other - the other currency pairpublic Optional<CurrencyPair> cross(CurrencyPair other)
The cross is only returned if the two pairs contains three currencies in total, such as AAA/BBB and BBB/CCC and neither pair is an identity such as AAA/AAA.
other - the other currency pairpublic boolean isConventional()
A market convention determines that 'EUR/USD' should be used and not 'USD/EUR'. This knowledge is encoded in configuration for a standard set of pairs.
It is possible to create two different currency pairs from any two currencies, and it is guaranteed that exactly one of the pairs will be the market convention pair.
If a currency pair is not explicitly listed in the configuration, a priority ordering of currencies is used to choose base currency of the pair that is treated as conventional.
If there is no configuration available to determine which pair is the market convention, a pair will
be chosen arbitrarily but deterministically. This ensures the same pair will be chosen for any two
currencies even if the CurrencyPair instances are created independently.
public CurrencyPair toConventional()
If isConventional() is true this method returns this, otherwise
it returns the inverse() pair.
public ImmutableSet<Currency> toSet()
public int getRateDigits()
If this rate is a conventional currency pair defined in configuration, then the number of digits in a market FX rate quote is returned.
If the currency pair is not defined in configuration the sum of the
minor unit digits from the two currencies is returned.
public Currency getBase()
In the pair 'AAA/BBB' the base is 'AAA'.
public Currency getCounter()
In the pair 'AAA/BBB' the counter is 'BBB'.
The counter currency is also known as the quote currency or the variable currency.
public boolean equals(Object obj)
The comparison checks the two currencies.
public int hashCode()
Copyright 2009-Present by OpenGamma Inc. and individual contributors
Apache v2 licensed
Additional documentation can be found at strata.opengamma.io.