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

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

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

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

/**
 * 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

/**
 * Parses a currency pair from a string with format AAA/BBB.
 * <p>
 * The parsed format is '${baseCurrency}/${counterCurrency}'.
 * Currency parsing is case insensitive.
 * 
 * @param pairStr  the currency pair as a string AAA/BBB
 * @return the currency pair
 * @throws IllegalArgumentException if the pair cannot be parsed
 */
@FromString
public static CurrencyPair parse(String pairStr) {
 ArgChecker.notNull(pairStr, "pairStr");
 Matcher matcher = REGEX_FORMAT.matcher(pairStr.toUpperCase(Locale.ENGLISH));
 if (!matcher.matches()) {
  throw new IllegalArgumentException("Invalid currency pair: " + pairStr);
 }
 Currency base = Currency.parse(matcher.group(1));
 Currency counter = Currency.parse(matcher.group(2));
 return new CurrencyPair(base, counter);
}
origin: OpenGamma/Strata

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

/**
 * Parses a rate from a string with format AAA/BBB RATE.
 * <p>
 * The parsed format is '${baseCurrency}/${counterCurrency} ${rate}'.
 * Currency parsing is case insensitive.
 * 
 * @param rateStr  the rate as a string AAA/BBB RATE
 * @return the FX rate
 * @throws IllegalArgumentException if the FX rate cannot be parsed
 */
public static FxRate parse(String rateStr) {
 ArgChecker.notNull(rateStr, "rateStr");
 Matcher matcher = REGEX_FORMAT.matcher(rateStr.toUpperCase(Locale.ENGLISH));
 if (!matcher.matches()) {
  throw new IllegalArgumentException("Invalid rate: " + rateStr);
 }
 try {
  Currency base = Currency.parse(matcher.group(1));
  Currency counter = Currency.parse(matcher.group(2));
  double rate = Double.parseDouble(matcher.group(3));
  return new FxRate(CurrencyPair.of(base, counter), rate);
 } catch (RuntimeException ex) {
  throw new IllegalArgumentException("Unable to parse rate: " + rateStr, ex);
 }
}
origin: OpenGamma/Strata

/**
 * Parses the string to produce a {@link Money}.
 * <p>
 * This parses the {@code toString} format of '${currency} ${amount}'.
 *
 * @param amountStr  the amount string
 * @return the currency amount
 * @throws IllegalArgumentException if the amount cannot be parsed
 */
@FromString
public static Money parse(String amountStr) {
 ArgChecker.notNull(amountStr, "amountStr");
 List<String> split = Splitter.on(' ').splitToList(amountStr);
 if (split.size() != 2) {
  throw new IllegalArgumentException("Unable to parse amount, invalid format: " + amountStr);
 }
 try {
  Currency cur = Currency.parse(split.get(0));
  return new Money(cur, new BigDecimal(split.get(1)));
 } catch (RuntimeException ex) {
  throw new IllegalArgumentException("Unable to parse amount: " + amountStr, ex);
 }
}
origin: OpenGamma/Strata

/**
 * Parses the string to produce a {@code CurrencyAmount}.
 * <p>
 * This parses the {@code toString} format of '${currency} ${amount}'.
 *
 * @param amountStr  the amount string
 * @return the currency amount
 * @throws IllegalArgumentException if the amount cannot be parsed
 */
@FromString
public static CurrencyAmount parse(String amountStr) {
 ArgChecker.notNull(amountStr, "amountStr");
 List<String> split = Splitter.on(' ').splitToList(amountStr);
 if (split.size() != 2) {
  throw new IllegalArgumentException("Unable to parse amount, invalid format: " + amountStr);
 }
 try {
  Currency cur = Currency.parse(split.get(0));
  double amount = Double.parseDouble(split.get(1));
  return new CurrencyAmount(cur, amount);
 } catch (RuntimeException ex) {
  throw new IllegalArgumentException("Unable to parse amount: " + amountStr, ex);
 }
}
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

public void test_parse_String() {
 Currency test = Currency.parse("GBP");
 assertEquals(test.getCode(), "GBP");
 assertSame(test, Currency.GBP);
}
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

Optional<LocalDate> startDateOpt = row.findValue(START_DATE_FIELD).map(s -> LoaderUtils.parseDate(s));
Optional<LocalDate> endDateOpt = row.findValue(END_DATE_FIELD).map(s -> LoaderUtils.parseDate(s));
Optional<Currency> currencyOpt = row.findValue(CURRENCY_FIELD).map(s -> Currency.parse(s));
Optional<DayCount> dayCountOpt = row.findValue(DAY_COUNT_FIELD).map(s -> LoaderUtils.parseDayCount(s));
BusinessDayConvention dateCnv = row.findValue(DATE_ADJ_CNV_FIELD)
origin: OpenGamma/Strata

private static FxIndex parseFxIndex(CsvRow row) {
 String name = row.getField(NAME_FIELD);
 Currency baseCurrency = Currency.parse(row.getField(BASE_CURRENCY_FIELD));
 Currency counterCurrency = Currency.parse(row.getField(COUNTER_CURRENCY_FIELD));
 HolidayCalendarId fixingCal = HolidayCalendarId.of(row.getField(FIXING_CALENDAR_FIELD));
 int maturityDays = Integer.parseInt(row.getField(MATURITY_DAYS_FIELD));
 HolidayCalendarId maturityCal = HolidayCalendarId.of(row.getField(MATURITY_CALENDAR_FIELD));
 // build result
 return ImmutableFxIndex.builder()
   .name(name)
   .currencyPair(CurrencyPair.of(baseCurrency, counterCurrency))
   .fixingCalendar(fixingCal)
   .maturityDateOffset(DaysAdjustment.ofBusinessDays(maturityDays, maturityCal))
   .build();
}
origin: OpenGamma/Strata

private static FxSingleTrade parseConvention(CsvRow row, TradeInfo info) {
 CurrencyPair pair = CurrencyPair.parse(row.getValue(CONVENTION_FIELD));
 BuySell buySell = LoaderUtils.parseBuySell(row.getValue(BUY_SELL_FIELD));
 Currency currency = Currency.parse(row.getValue(CURRENCY_FIELD));
 double notional = LoaderUtils.parseDouble(row.getValue(NOTIONAL_FIELD));
 double fxRate = LoaderUtils.parseDouble(row.getValue(FX_RATE_FIELD));
 LocalDate paymentDate = LoaderUtils.parseDate(row.getValue(PAYMENT_DATE_FIELD));
 Optional<BusinessDayAdjustment> paymentAdj = parsePaymentDateAdjustment(row);
 CurrencyAmount amount = CurrencyAmount.of(currency, buySell.normalize(notional));
 FxSingle fx = paymentAdj
   .map(adj -> FxSingle.of(amount, FxRate.of(pair, fxRate), paymentDate, adj))
   .orElseGet(() -> FxSingle.of(amount, FxRate.of(pair, fxRate), paymentDate));
 return FxSingleTrade.of(info, fx);
}
origin: OpenGamma/Strata

private static PriceIndex parsePriceIndex(CsvRow row) {
 String name = row.getField(NAME_FIELD);
 Currency currency = Currency.parse(row.getField(CURRENCY_FIELD));
 Country region = Country.of(row.getField(COUNTRY_FIELD));
 boolean active = Boolean.parseBoolean(row.getField(ACTIVE_FIELD));
 Frequency frequency = Frequency.parse(row.getField(PUBLICATION_FREQUENCY_FIELD));
 // build result
 return ImmutablePriceIndex.builder()
   .name(name)
   .currency(currency)
   .region(region)
   .active(active)
   .publicationFrequency(frequency)
   .build();
}
origin: OpenGamma/Strata

private static OvernightIndex parseOvernightIndex(CsvRow row) {
 String name = row.getValue(NAME_FIELD);
 Currency currency = Currency.parse(row.getValue(CURRENCY_FIELD));
 boolean active = Boolean.parseBoolean(row.getValue(ACTIVE_FIELD));
 DayCount dayCount = DayCount.of(row.getValue(DAY_COUNT_FIELD));
 HolidayCalendarId fixingCal = HolidayCalendarId.of(row.getValue(FIXING_CALENDAR_FIELD));
 int publicationDays = Integer.parseInt(row.getValue(PUBLICATION_DAYS_FIELD));
 int effectiveDays = Integer.parseInt(row.getValue(EFFECTIVE_DAYS_FIELD));
 DayCount fixedLegDayCount = DayCount.of(row.getValue(FIXED_LEG_DAY_COUNT));
 // build result
 return ImmutableOvernightIndex.builder()
   .name(name)
   .currency(currency)
   .active(active)
   .dayCount(dayCount)
   .fixingCalendar(fixingCal)
   .publicationDateOffset(publicationDays)
   .effectiveDateOffset(effectiveDays)
   .defaultFixedLegDayCount(fixedLegDayCount)
   .build();
}
origin: OpenGamma/Strata

private static FxSwapTrade parseConvention(CsvRow row, TradeInfo info) {
 CurrencyPair pair = CurrencyPair.parse(row.getValue(CONVENTION_FIELD));
 BuySell buySell = LoaderUtils.parseBuySell(row.getValue(BUY_SELL_FIELD));
 Currency currency = Currency.parse(row.getValue(CURRENCY_FIELD));
 double notional = LoaderUtils.parseDouble(row.getValue(NOTIONAL_FIELD));
 double nearFxRate = LoaderUtils.parseDouble(row.getValue(FX_RATE_FIELD));
 double farFxRate = LoaderUtils.parseDouble(row.getValue(FAR_FX_RATE_DATE_FIELD));
 LocalDate nearPaymentDate = LoaderUtils.parseDate(row.getValue(PAYMENT_DATE_FIELD));
 LocalDate farPaymentDate = LoaderUtils.parseDate(row.getValue(FAR_PAYMENT_DATE_FIELD));
 Optional<BusinessDayAdjustment> paymentAdj = FxSingleTradeCsvLoader.parsePaymentDateAdjustment(row);
 CurrencyAmount amount = CurrencyAmount.of(currency, buySell.normalize(notional));
 FxRate nearRate = FxRate.of(pair, nearFxRate);
 FxRate farRate = FxRate.of(pair, farFxRate);
 FxSwap fx = paymentAdj
   .map(adj -> FxSwap.of(amount, nearRate, nearPaymentDate, farRate, farPaymentDate, adj))
   .orElseGet(() -> FxSwap.of(amount, nearRate, nearPaymentDate, farRate, farPaymentDate));
 return FxSwapTrade.of(info, fx);
}
origin: OpenGamma/Strata

private static IborIndex parseIborIndex(CsvRow row) {
 String name = row.getValue(NAME_FIELD);
 Currency currency = Currency.parse(row.getValue(CURRENCY_FIELD));
 boolean active = Boolean.parseBoolean(row.getValue(ACTIVE_FIELD));
 DayCount dayCount = DayCount.of(row.getValue(DAY_COUNT_FIELD));
com.opengamma.strata.basics.currencyCurrencyparse

Javadoc

Parses a string to obtain a 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.

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
  • of
    Obtains an instance for the specified ISO-4217 three letter currency code. A currency is uniquely id
  • 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

  • Making http requests using okhttp
  • scheduleAtFixedRate (ScheduledExecutorService)
  • getSupportFragmentManager (FragmentActivity)
  • startActivity (Activity)
  • Font (java.awt)
    The Font class represents fonts, which are used to render text in a visible way. A font provides the
  • Kernel (java.awt.image)
  • Selector (java.nio.channels)
    A controller for the selection of SelectableChannel objects. Selectable channels can be registered w
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • SimpleDateFormat (java.text)
    Formats and parses dates in a locale-sensitive manner. Formatting turns a Date into a String, and pa
  • CountDownLatch (java.util.concurrent)
    A synchronization aid that allows one or more threads to wait until a set of operations being perfor
  • Github Copilot alternatives
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