public final class Currency extends Object implements Comparable<Currency>, Serializable
This class represents a unit of currency such as the British Pound, Euro or US Dollar. The currency is represented by a three letter code, intended to be ISO-4217.
It is recommended to define currencies in advance using the Currency.ini
file.
Standard configuration includes many commonly used currencies.
Only currencies listed in configuration will be returned by getAvailableCurrencies()
.
If a currency is requested that is not defined in configuration, it will still be created,
however it will have the default value of zero for the minor units and 'USD' for
the triangulation currency.
This class is immutable and thread-safe.
Modifier and Type | Field and Description |
---|---|
static Currency |
AED
The currency 'AED' - UAE Dirham.
|
static Currency |
ARS
The currency 'ARS' - Argentine Peso.
|
static Currency |
AUD
The currency 'AUD' - Australian Dollar.
|
static Currency |
BGN
The currency 'BGN' - Bulgarian Lev.
|
static Currency |
BHD
The currency 'BHD' - Bahraini Dinar.
|
static Currency |
BRL
The currency 'BRL' - Brazilian Real.
|
static Currency |
CAD
The currency 'CAD' - Canadian Dollar.
|
static Currency |
CHF
The currency 'CHF' - Swiss Franc.
|
static Currency |
CLP
The currency 'CLP' - Chilean Peso.
|
static Currency |
CNH
The currency 'CNH' - Chinese Offshore Yuan.
|
static Currency |
CNY
The currency 'CNY' - Chinese Onshore Yuan.
|
static Currency |
COP
The currency 'COP' - Colombian Peso.
|
static Currency |
CZK
The currency 'CZK' - Czeck Krona.
|
static Currency |
DKK
The currency 'DKK' - Danish Krone.
|
static Currency |
EGP
The currency 'EGP' - Egyptian Pound.
|
static Currency |
EUR
The currency 'EUR' - Euro.
|
static Currency |
GBP
The currency 'GBP' - British pound.
|
static Currency |
HKD
The currency 'HKD' - Hong Kong Dollar.
|
static Currency |
HRK
The currency 'HRK' - Croatian Kuna.
|
static Currency |
HUF
The currency 'HUF' = Hugarian Forint.
|
static Currency |
IDR
The currency 'IDR' = Indonesian Rupiah.
|
static Currency |
ILS
The currency 'ILS' = Israeli Shekel.
|
static Currency |
INR
The currency 'INR' = Indian Rupee.
|
static Currency |
ISK
The currency 'ISK' = Icelandic Krone.
|
static Currency |
JPY
The currency 'JPY' - Japanese Yen.
|
static Currency |
KRW
The currency 'KRW' = South Korean Won.
|
static Currency |
KZT
The currency 'KZT' = Kazakhstani Tenge.
|
static Currency |
MAD
The currency 'MAD' - Moroccan Dirham.
|
static Currency |
MXN
The currency 'MXN' - Mexican Peso.
|
static Currency |
MYR
The currency 'MYR' - Malaysian Ringgit.
|
static Currency |
NOK
The currency 'NOK' - Norwegian Krone.
|
static Currency |
NZD
The currency 'NZD' - New Zealand Dollar.
|
static Currency |
OMR
The currency 'OMR' - Omani Rial.
|
static Currency |
PEN
The currency 'PEN' - Peruvian Nuevo Sol.
|
static Currency |
PHP
The currency 'PHP' - Philippine Peso.
|
static Currency |
PKR
The currency 'PKR' - Pakistani Rupee.
|
static Currency |
PLN
The currency 'PLN' - Polish Zloty.
|
static Currency |
QAR
The currency 'QAR' - Qatari Riyal.
|
static Currency |
RON
The currency 'RON' - Romanian New Leu.
|
static Currency |
RUB
The currency 'RUB' - Russian Ruble.
|
static Currency |
SAR
The currency 'SAR' - Saudi Riyal.
|
static Currency |
SEK
The currency 'SEK' - Swedish Krona.
|
static Currency |
SGD
The currency 'SGD' - Singapore Dollar.
|
static Currency |
THB
The currency 'THB' - Thai Baht.
|
static Currency |
TRY
The currency 'TRY' - Turkish Lira.
|
static Currency |
TWD
The currency 'TWD' - New Taiwan Dollar.
|
static Currency |
UAH
The currency 'UAH' - Ukrainian Hryvnia.
|
static Currency |
USD
The currency 'USD' - United States Dollar.
|
static Currency |
VND
The currency 'VND' - Vietnamese Dong.
|
static Currency |
XAG
The currency 'XAG' - Silver (troy ounce).
|
static Currency |
XAU
The currency 'XAU' - Gold (troy ounce).
|
static Currency |
XPD
The currency 'XPD' - Paladium (troy ounce).
|
static Currency |
XPT
The currency 'XPT' - Platinum (troy ounce).
|
static Currency |
XXX
The currency 'XXX' - No applicable currency.
|
static Currency |
ZAR
The currency 'ZAR' - South African Rand.
|
Modifier and Type | Method and Description |
---|---|
int |
compareTo(Currency other)
Compares this currency to another.
|
boolean |
equals(Object obj)
Checks if this currency equals another currency.
|
static Set<Currency> |
getAvailableCurrencies()
Obtains the set of configured currencies.
|
String |
getCode()
Gets the three letter ISO code.
|
int |
getMinorUnitDigits()
Gets the number of digits in the minor unit.
|
Currency |
getTriangulationCurrency()
Gets the preferred triangulation currency.
|
int |
hashCode()
Returns a suitable hash code for the currency.
|
static Currency |
of(String currencyCode)
Obtains an instance for the specified ISO-4217 three letter currency code.
|
static Currency |
parse(String currencyCode)
Parses a string to obtain a
Currency . |
BigDecimal |
roundMinorUnits(BigDecimal amount)
Rounds the specified amount according to the minor units.
|
double |
roundMinorUnits(double amount)
Rounds the specified amount according to the minor units.
|
String |
toString()
Returns a string representation of the currency, which is the three letter code.
|
public static final Currency USD
public static final Currency EUR
public static final Currency JPY
public static final Currency GBP
public static final Currency CHF
public static final Currency AUD
public static final Currency CAD
public static final Currency NZD
public static final Currency AED
public static final Currency ARS
public static final Currency BGN
public static final Currency BHD
public static final Currency BRL
public static final Currency CLP
public static final Currency CNH
public static final Currency CNY
public static final Currency COP
public static final Currency CZK
public static final Currency DKK
public static final Currency EGP
public static final Currency HKD
public static final Currency HRK
public static final Currency HUF
public static final Currency IDR
public static final Currency ILS
public static final Currency INR
public static final Currency ISK
public static final Currency KRW
public static final Currency KZT
public static final Currency MAD
public static final Currency MXN
public static final Currency MYR
public static final Currency NOK
public static final Currency OMR
public static final Currency PEN
public static final Currency PHP
public static final Currency PKR
public static final Currency PLN
public static final Currency QAR
public static final Currency RON
public static final Currency RUB
public static final Currency SAR
public static final Currency SEK
public static final Currency SGD
public static final Currency THB
public static final Currency TRY
public static final Currency TWD
public static final Currency UAH
public static final Currency VND
public static final Currency ZAR
public static final Currency XXX
public static final Currency XAG
public static final Currency XAU
public static final Currency XPD
public static final Currency XPT
public static Set<Currency> getAvailableCurrencies()
This contains all the currencies that have been defined in configuration. Any currency instances that have been dynamically created are not included.
public static Currency of(String currencyCode)
A currency is uniquely identified by ISO-4217 three letter code. Currencies should be defined in configuration before they can be used. If the requested currency is not defined in configuration, it will still be created, however it will have the default value of zero for the minor units and 'USD' for the triangulation currency.
currencyCode
- the three letter currency code, ASCII and upper caseIllegalArgumentException
- if the currency code is invalidpublic static Currency parse(String currencyCode)
Currency
.
The parse is identical to of(String)
except that it will convert
letters to upper case first.
If the requested currency is not defined in configuration, it will still be created,
however it will have the default value of zero for the minor units and 'USD' for
the triangulation currency.
currencyCode
- the three letter currency code, ASCIIIllegalArgumentException
- if the currency code is invalidpublic String getCode()
public int getMinorUnitDigits()
For example, 'USD' will return 2, indicating that there are two digits, corresponding to cents in the dollar.
public Currency getTriangulationCurrency()
When obtaining a market quote for a currency, the triangulation currency is used if no direct rate can be found. For example, there is no direct rate for 'CZK/SGD'. Instead 'CZK' might be defined to triangulate via 'EUR' and 'SGD' with 'USD'. Since the three rates, 'CZK/EUR', 'EUR/USD' and 'USD/SGD' can be obtained, a rate can be determined for 'CZK/SGD'. Note that most currencies triangulate via 'USD'.
public double roundMinorUnits(double amount)
For example, 'USD' has 2 minor digits, so 63.347 will be rounded to 63.35.
amount
- the amount to roundpublic BigDecimal roundMinorUnits(BigDecimal amount)
For example, 'USD' has 2 minor digits, so 63.347 will be rounded to 63.35.
amount
- the amount to roundpublic int compareTo(Currency other)
The comparison sorts alphabetically by the three letter currency code.
compareTo
in interface Comparable<Currency>
other
- the other currencypublic boolean equals(Object obj)
The comparison checks the three letter currency code.
public int hashCode()
Copyright 2009-Present by OpenGamma Inc. and individual contributors
Apache v2 licensed
Additional documentation can be found at strata.opengamma.io.