congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
Currency.of
Code IndexAdd Tabnine to your IDE (free)

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

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

origin: OpenGamma/Strata

/**
 * Ensure singleton on deserialization.
 * 
 * @return the singleton
 */
private Object readResolve() {
 return Currency.of(code);
}
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

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

/**
 * Parses a string to obtain a {@code Currency}.
 * <p>
 * The parse is identical to {@link #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.
 *
 * @param currencyCode  the three letter currency code, ASCII
 * @return the singleton instance
 * @throws IllegalArgumentException if the currency code is invalid
 */
public static Currency parse(String currencyCode) {
 ArgChecker.notNull(currencyCode, "currencyCode");
 return of(currencyCode.toUpperCase(Locale.ENGLISH));
}
origin: OpenGamma/Strata

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

private static ImmutableMap<Currency, FloatingRateName> parseIborDefaults(
  IniFile ini,
  ImmutableMap<String, FloatingRateName> names) {
 ImmutableMap.Builder<Currency, FloatingRateName> map = ImmutableMap.builder();
 PropertySet section = ini.section("currencyDefaultIbor");
 for (String key : section.keys()) {
  FloatingRateName frname = names.get(section.value(key));
  if (frname == null) {
   throw new IllegalArgumentException("Invalid default Ibor index for currency " + key);
  }
  map.put(Currency.of(key), frname);
 }
 return map.build();
}
origin: OpenGamma/Strata

@Test(expectedExceptions = IllegalArgumentException.class)
public void test_of_String_lowerCase() {
 Currency.of("gbp");
}
origin: OpenGamma/Strata

@Test(dataProvider = "ofBad", expectedExceptions = IllegalArgumentException.class)
public void test_of_String_bad(String input) {
 Currency.of(input);
}
origin: OpenGamma/Strata

 private static ImmutableMap<Currency, FloatingRateName> parseOvernightDefaults(
   IniFile ini,
   ImmutableMap<String, FloatingRateName> names) {
  ImmutableMap.Builder<Currency, FloatingRateName> map = ImmutableMap.builder();
  PropertySet section = ini.section("currencyDefaultOvernight");
  for (String key : section.keys()) {
   FloatingRateName frname = names.get(section.value(key));
   if (frname == null) {
    throw new IllegalArgumentException("Invalid default Overnight index for currency " + key);
   }
   map.put(Currency.of(key), frname);
  }
  return map.build();
 }
}
origin: OpenGamma/Strata

private static GroupAndReference createKey(
  CurveGroupName curveGroup,
  String curveTypeStr,
  String referenceStr) {
 // discount and forward curves are supported
 if (FORWARD.equalsIgnoreCase(curveTypeStr.toLowerCase(Locale.ENGLISH))) {
  Index index = LoaderUtils.findIndex(referenceStr);
  return new GroupAndReference(curveGroup, index);
 } else if (DISCOUNT.equalsIgnoreCase(curveTypeStr.toLowerCase(Locale.ENGLISH))) {
  Currency ccy = Currency.of(referenceStr);
  return new GroupAndReference(curveGroup, ccy);
 } else {
  throw new IllegalArgumentException(Messages.format("Unsupported curve type: {}", curveTypeStr));
 }
}
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

public void test_equals_hashCode() {
 Object a1 = Currency.GBP;
 Object a2 = Currency.of("GBP");
 Object b = Currency.EUR;
 assertEquals(a1.equals(a1), true);
 assertEquals(a1.equals(b), false);
 assertEquals(a1.equals(a2), true);
 assertEquals(a2.equals(a1), true);
 assertEquals(a2.equals(a2), true);
 assertEquals(a2.equals(b), false);
 assertEquals(b.equals(a1), false);
 assertEquals(b.equals(a2), false);
 assertEquals(b.equals(b), true);
 assertEquals(a1.hashCode(), a2.hashCode());
}
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

@VisibleForTesting
static ImmutableMap<Currency, HolidayCalendarId> loadDefaultsFromIni(String filename) {
 List<ResourceLocator> resources = ResourceConfig.orderedResources(filename);
 Map<Currency, HolidayCalendarId> map = new HashMap<>();
 for (ResourceLocator resource : resources) {
  try {
   IniFile ini = IniFile.of(resource.getCharSource());
   PropertySet section = ini.section("defaultByCurrency");
   for (String currencyCode : section.keys()) {
    map.put(Currency.of(currencyCode), HolidayCalendarId.of(section.value(currencyCode)));
   }
  } catch (RuntimeException ex) {
   log.log(Level.SEVERE, "Error processing resource as Holiday Calendar Defaults INI file: " + resource, ex);
   return ImmutableMap.of();
  }
 }
 return ImmutableMap.copyOf(map);
}
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

static Position parseNonEtdPosition(CsvRow row, PositionInfo info, PositionCsvInfoResolver resolver) {
 SecurityPosition base = parseSecurityPosition(row, info, resolver);
 Optional<Double> tickSizeOpt = row.findValue(TICK_SIZE).map(str -> LoaderUtils.parseDouble(str));
 Optional<Currency> currencyOpt = row.findValue(CURRENCY).map(str -> Currency.of(str));
 Optional<Double> tickValueOpt = row.findValue(TICK_VALUE).map(str -> LoaderUtils.parseDouble(str));
 double contractSize = row.findValue(CONTRACT_SIZE).map(str -> LoaderUtils.parseDouble(str)).orElse(1d);
 if (tickSizeOpt.isPresent() && currencyOpt.isPresent() && tickValueOpt.isPresent()) {
  SecurityPriceInfo priceInfo =
    SecurityPriceInfo.of(tickSizeOpt.get(), CurrencyAmount.of(currencyOpt.get(), tickValueOpt.get()), contractSize);
  GenericSecurity sec = GenericSecurity.of(SecurityInfo.of(base.getSecurityId(), priceInfo));
  return GenericSecurityPosition.ofLongShort(base.getInfo(), sec, base.getLongQuantity(), base.getShortQuantity());
 }
 return base;
}
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

static SecurityQuantityTrade parseTrade(CsvRow row, TradeInfo info, TradeCsvInfoResolver resolver) {
 SecurityTrade trade = parseSecurityTrade(row, info, resolver);
 SecurityTrade base = resolver.completeTrade(row, trade);
 Optional<Double> tickSizeOpt = row.findValue(TICK_SIZE).map(str -> LoaderUtils.parseDouble(str));
 Optional<Currency> currencyOpt = row.findValue(CURRENCY).map(str -> Currency.of(str));
 Optional<Double> tickValueOpt = row.findValue(TICK_VALUE).map(str -> LoaderUtils.parseDouble(str));
 double contractSize = row.findValue(CONTRACT_SIZE).map(str -> LoaderUtils.parseDouble(str)).orElse(1d);
 if (tickSizeOpt.isPresent() && currencyOpt.isPresent() && tickValueOpt.isPresent()) {
  SecurityPriceInfo priceInfo =
    SecurityPriceInfo.of(tickSizeOpt.get(), CurrencyAmount.of(currencyOpt.get(), tickValueOpt.get()), contractSize);
  GenericSecurity sec = GenericSecurity.of(SecurityInfo.of(base.getSecurityId(), priceInfo));
  return GenericSecurityTrade.of(base.getInfo(), sec, base.getQuantity(), base.getPrice());
 }
 return base;
}
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"));
}
com.opengamma.strata.basics.currencyCurrencyof

Javadoc

Obtains an instance for the specified ISO-4217 three letter currency code.

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.

Popular methods of Currency

  • 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
  • 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
  • hashCode
    Returns a suitable hash code for the currency.
  • getAvailableCurrencies,
  • hashCode

Popular in Java

  • Reactive rest calls using spring rest template
  • requestLocationUpdates (LocationManager)
  • findViewById (Activity)
  • setRequestProperty (URLConnection)
  • Point (java.awt)
    A point representing a location in (x,y) coordinate space, specified in integer precision.
  • HttpURLConnection (java.net)
    An URLConnection for HTTP (RFC 2616 [http://tools.ietf.org/html/rfc2616]) used to send and receive d
  • Proxy (java.net)
    This class represents proxy server settings. A created instance of Proxy stores a type and an addres
  • ImageIO (javax.imageio)
  • Response (javax.ws.rs.core)
    Defines the contract between a returned instance and the runtime when an application needs to provid
  • DateTimeFormat (org.joda.time.format)
    Factory that creates instances of DateTimeFormatter from patterns and styles. Datetime formatting i
  • Top 12 Jupyter Notebook Extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

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