Tabnine Logo
Currency
Code IndexAdd Tabnine to your IDE (free)

How to use
Currency
in
com.opengamma.strata.basics.currency

Best Java code snippets using com.opengamma.strata.basics.currency.Currency (Showing top 20 results out of 315)

origin: OpenGamma/Strata

/**
 * Checks if this currency pair is an identity pair.
 * <p>
 * The identity pair is one where the base and counter currency are the same..
 * 
 * @return true if this pair is an identity pair
 */
public boolean isIdentity() {
 return base.equals(counter);
}
origin: OpenGamma/Strata

public void test_parse_String_unknownCurrencyCreated() {
 Currency test = Currency.parse("zyx");
 assertEquals(test.getCode(), "ZYX");
 assertEquals(test.getMinorUnitDigits(), 0);
 assertSame(test, Currency.of("ZYX"));
}
origin: OpenGamma/Strata

@Test(expectedExceptions = NullPointerException.class)
public void test_compareTo_null() {
 Currency.EUR.compareTo(null);
}
origin: OpenGamma/Strata

public void test_minorUnits() {
 assertEquals(Currency.of("USD").getMinorUnitDigits(), 2);
 assertEquals(Currency.of("EUR").getMinorUnitDigits(), 2);
 assertEquals(Currency.of("JPY").getMinorUnitDigits(), 0);
 assertEquals(Currency.of("GBP").getMinorUnitDigits(), 2);
 assertEquals(Currency.of("CHF").getMinorUnitDigits(), 2);
 assertEquals(Currency.of("AUD").getMinorUnitDigits(), 2);
 assertEquals(Currency.of("CAD").getMinorUnitDigits(), 2);
}
origin: OpenGamma/Strata

public void test_triangulatonCurrency() {
 assertEquals(Currency.of("USD").getTriangulationCurrency(), Currency.USD);
 assertEquals(Currency.of("EUR").getTriangulationCurrency(), Currency.USD);
 assertEquals(Currency.of("JPY").getTriangulationCurrency(), Currency.USD);
 assertEquals(Currency.of("GBP").getTriangulationCurrency(), Currency.USD);
 assertEquals(Currency.of("CHF").getTriangulationCurrency(), Currency.USD);
 assertEquals(Currency.of("AUD").getTriangulationCurrency(), Currency.USD);
 assertEquals(Currency.of("CAD").getTriangulationCurrency(), Currency.USD);
}
origin: OpenGamma/Strata

public void test_of_String_historicCurrency() {
 Currency test = Currency.of("BEF");
 assertEquals(test.getCode(), "BEF");
 assertEquals(test.getMinorUnitDigits(), 2);
 assertEquals(test.getTriangulationCurrency(), Currency.EUR);
 assertSame(test, Currency.of("BEF"));
}
origin: OpenGamma/Strata

public void test_of_String_unknownCurrencyCreated() {
 Currency test = Currency.of("AAA");
 assertEquals(test.getCode(), "AAA");
 assertEquals(test.getMinorUnitDigits(), 0);
 assertSame(test, Currency.of("AAA"));
}
origin: OpenGamma/Strata

/**
 * Ensure singleton on deserialization.
 * 
 * @return the singleton
 */
private Object readResolve() {
 return Currency.of(code);
}
origin: OpenGamma/Strata

/**
 * Returns the formatted string version of the currency pair.
 * <p>
 * The format is '${baseCurrency}/${counterCurrency}'.
 * 
 * @return the formatted string
 */
@Override
@ToString
public String toString() {
 return base.getCode() + "/" + counter.getCode();
}
origin: OpenGamma/Strata

public void test_parse_String() {
 Currency test = Currency.parse("GBP");
 assertEquals(test.getCode(), "GBP");
 assertSame(test, Currency.GBP);
}
origin: OpenGamma/Strata

/**
 * Parses currency from the input string.
 * <p>
 * Parsing is case insensitive.
 * 
 * @param str  the string to parse
 * @return the parsed currency
 * @throws IllegalArgumentException if the string cannot be parsed
 */
public static Currency parseCurrency(String str) {
 try {
  return Currency.parse(str);
 } catch (RuntimeException ex) {
  throw new IllegalArgumentException(
    "Unknown Currency, must be 3 letter ISO-4217 format but was '" + str + "'");
 }
}
origin: OpenGamma/Strata

public void test_of_String() {
 Currency test = Currency.of("SEK");
 assertEquals(test.getCode(), "SEK");
 assertSame(test, Currency.of("SEK"));
}
origin: OpenGamma/Strata

/**
 * Obtains an instance that rounds to the number of minor units in the currency.
 * <p>
 * This returns a convention that rounds for the specified currency.
 * Rounding follows the normal {@link RoundingMode#HALF_UP} convention.
 * 
 * @param currency  the currency
 * @return the rounding convention
 */
public static Rounding of(Currency currency) {
 return HalfUpRounding.ofDecimalPlaces(currency.getMinorUnitDigits());
}
origin: OpenGamma/Strata

/**
 * Gets the preferred triangulation currency.
 * <p>
 * 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'.
 * 
 * @return the triangulation currency
 */
public Currency getTriangulationCurrency() {
 return Currency.of(triangulationCurrency);
}
origin: OpenGamma/Strata

@Override
public Set<String> tokens(CurrencyParameterSensitivity sensitivity) {
 return ImmutableSet.of(
   sensitivity.getCurrency().getCode().toLowerCase(Locale.ENGLISH),
   sensitivity.getMarketDataName().getName().toLowerCase(Locale.ENGLISH));
}
origin: OpenGamma/Strata

public void test_parse_String_lowerCase() {
 Currency test = Currency.parse("gbp");
 assertEquals(test.getCode(), "GBP");
 assertSame(test, Currency.GBP);
}
origin: OpenGamma/Strata

/**
 * Tries to parse a currency from the input string.
 * <p>
 * Parsing is case insensitive.
 * 
 * @param str  the string to parse, may be null
 * @return the parsed currency, empty if unable to parse
 */
public static Optional<Currency> tryParseCurrency(String str) {
 if (str != null && str.length() == 3 && CURRENCY_MATCHER.matchesAllOf(str)) {
  try {
   return Optional.of(Currency.parse(str));
  } catch (RuntimeException ex) {
   // ignore
  }
 }
 return Optional.empty();
}
origin: OpenGamma/Strata

/**
 * Gets the number of digits in the rate.
 * <p>
 * If this rate is a conventional currency pair defined in configuration,
 * then the number of digits in a market FX rate quote is returned.
 * <p>
 * If the currency pair is not defined in configuration the sum of the
 * {@link Currency#getMinorUnitDigits() minor unit digits} from the two currencies is returned.
 * 
 * @return the number of digits in the FX rate
 */
public int getRateDigits() {
 Integer digits = CONFIGURED.get(this);
 if (digits != null) {
  return digits;
 }
 Integer inverseDigits = CONFIGURED.get(inverse());
 if (inverseDigits != null) {
  return inverseDigits;
 }
 return base.getMinorUnitDigits() + counter.getMinorUnitDigits();
}
origin: OpenGamma/Strata

/**
 * 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);
}
origin: OpenGamma/Strata

/**
 * Obtains an instance of {@code CurrencyAmount} for the specified ISO-4217
 * three letter currency code and amount.
 * <p>
 * A currency is uniquely identified by ISO-4217 three letter code.
 * This method creates the currency if it is not known.
 *
 * @param currencyCode  the three letter currency code, ASCII and upper case
 * @param amount  the amount of the currency to represent
 * @return the currency amount
 * @throws IllegalArgumentException if the currency code is invalid
 */
public static CurrencyAmount of(String currencyCode, double amount) {
 return of(Currency.of(currencyCode), amount);
}
com.opengamma.strata.basics.currencyCurrency

Javadoc

A unit of currency.

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.

Most used methods

  • equals
    Checks if this currency equals another currency. The comparison checks the three letter currency cod
  • getCode
    Gets the three letter ISO code.
  • getMinorUnitDigits
    Gets the number of digits in the minor unit. For example, 'USD' will return 2, indicating that there
  • of
    Obtains an instance for the specified ISO-4217 three letter currency code. A currency is uniquely id
  • parse
    Parses a string to obtain a Currency. The parse is identical to #of(String) except that it will conv
  • compareTo
    Compares this currency to another. The comparison sorts alphabetically by the three letter currency
  • getTriangulationCurrency
    Gets the preferred triangulation currency. When obtaining a market quote for a currency, the triangu
  • roundMinorUnits
    Rounds the specified amount according to the minor units. For example, 'USD' has 2 minor digits, so
  • toString
    Returns a string representation of the currency, which is the three letter code.
  • <init>
    Restricted constructor, called only by CurrencyProperties.
  • addCode
  • getAvailableCurrencies
    Obtains the set of configured currencies. This contains all the currencies that have been defined in
  • addCode,
  • getAvailableCurrencies,
  • hashCode

Popular in Java

  • Parsing JSON documents to java classes using gson
  • getSystemService (Context)
  • requestLocationUpdates (LocationManager)
  • notifyDataSetChanged (ArrayAdapter)
  • FlowLayout (java.awt)
    A flow layout arranges components in a left-to-right flow, much like lines of text in a paragraph. F
  • InputStream (java.io)
    A readable source of bytes.Most clients will use input streams that read data from the file system (
  • Dictionary (java.util)
    Note: Do not use this class since it is obsolete. Please use the Map interface for new implementatio
  • PriorityQueue (java.util)
    A PriorityQueue holds elements on a priority heap, which orders the elements according to their natu
  • TimeZone (java.util)
    TimeZone represents a time zone offset, and also figures out daylight savings. Typically, you get a
  • Timer (java.util)
    Timers schedule one-shot or recurring TimerTask for execution. Prefer java.util.concurrent.Scheduled
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now