Class LoaderUtils


  • public final class LoaderUtils
    extends Object
    Contains utilities for loading market data from input files.
    • Method Detail

      • findIndex

        public static Index findIndex​(String reference)
        Attempts to locate a rate index by reference name.

        This utility searches IborIndex, OvernightIndex, FxIndex and PriceIndex.

        Parameters:
        reference - the reference name
        Returns:
        the resolved rate index
      • parseBoolean

        public static boolean parseBoolean​(String str)
        Parses a boolean from the input string.

        Parsing is case insensitive. True is parsed as 'TRUE', 'T', 'YES', 'Y'. False is parsed as 'FALSE', 'F', 'NO', 'N'. Other strings are rejected.

        Parameters:
        str - the string to parse
        Returns:
        the parsed value
        Throws:
        ParseFailureException - if the string cannot be parsed
      • parseInteger

        public static int parseInteger​(String str)
        Parses an integer from the input string.

        If input value is bracketed, it will be parsed as a negative value. Comma separated values will be parsed assuming American decimal format. Values in European decimal formats (thus "12456789" formatted as "12.456.789") will not be parsed.

        For example "12,300" and "12300" will be parsed as integer "12300" and similarly "(12,300)", "-12,300" and "-12300" will be parsed as integer "-12300".

        Note: Comma separated values such as "1,234,5,6" will be parsed as integer "123456".

        Parameters:
        str - the string to parse
        Returns:
        the parsed value
        Throws:
        ParseFailureException - if the string cannot be parsed
      • parseDouble

        public static double parseDouble​(String str)
        Parses a double from the input string.

        If input value is bracketed, it will be parsed as a negative value. Comma separated values will be parsed assuming American decimal format. Values in European decimal formats (thus "12456789.444" formatted as "12.456.789,444") will not be parsed.

        For example "12,300.12" and "12300.12" will be parsed as "12300.12d" and similarly "(12,300.12)", "-12,300.12" and "-12300.12" will be parsed as "-12300.12d".

        Note: Comma separated values such as "1,234,5,6.12" will be parsed as "123456.12d".

        Parameters:
        str - the string to parse
        Returns:
        the parsed value
        Throws:
        ParseFailureException - if the string cannot be parsed
      • parseDoublePercent

        public static double parseDoublePercent​(String str)
        Parses a double from the input string, converting it from a percentage to a decimal values.

        If input value is bracketed, it will be parsed as a negative decimal percentage. For example '(12.34)' will be parsed as -0.1234d.

        Parameters:
        str - the string to parse
        Returns:
        the parsed value
        Throws:
        ParseFailureException - if the string cannot be parsed
      • parseBigDecimal

        public static BigDecimal parseBigDecimal​(String str)
        Parses a decimal from the input string.

        If input value is bracketed, it will be parsed as a negative value. Comma separated values will be parsed assuming American decimal format. Values in European decimal formats (thus "12456789.444" formatted as "12.456.789,444") will not be parsed.

        For example "12,300.12" and "12300.12" will be parsed as big decimal "12300.12" and similarly "(12,300.12)", "-12,300.12" and "-12300.12" will be parsed as big decimal "-12300.12".

        Note: Comma separated values such as "1,234,5,6.12" will be parsed as big decimal "123456.12".

        Parameters:
        str - the string to parse
        Returns:
        the parsed value
        Throws:
        ParseFailureException - if the string cannot be parsed
      • parseBigDecimalPercent

        public static BigDecimal parseBigDecimalPercent​(String str)
        Parses a decimal from the input string, converting it from a percentage to decimal form.

        If input value is bracketed, it will be parsed as a negative value. For example '(12.3456789)' will be parsed as a big decimal -0.123456789.

        Parameters:
        str - the string to parse
        Returns:
        the parsed value in decimal form
        Throws:
        ParseFailureException - if the string cannot be parsed
      • parseBigDecimalBasisPoint

        public static BigDecimal parseBigDecimalBasisPoint​(String str)
        Parses a decimal from the input string, converting it from a basis points to decimal form.

        If input value is bracketed, it will be parsed as a negative value. For example '(12.3456789)' will be parsed as a big decimal -0.00123456789.

        Parameters:
        str - the string to parse
        Returns:
        the parsed value in decimal form
        Throws:
        ParseFailureException - if the string cannot be parsed
      • parseDecimal

        public static Decimal parseDecimal​(String str)
        Parses a decimal from the input string.

        If input value is bracketed, it will be parsed as a negative value. Comma separated values will be parsed assuming American decimal format. Values in European decimal formats (thus "12456789.444" formatted as "12.456.789,444") will not be parsed.

        For example "12,300.12" and "12300.12" will be parsed as big decimal "12300.12" and similarly "(12,300.12)", "-12,300.12" and "-12300.12" will be parsed as big decimal "-12300.12".

        Note: Comma separated values such as "1,234,5,6.12" will be parsed as big decimal "123456.12".

        Parameters:
        str - the string to parse
        Returns:
        the parsed value
        Throws:
        ParseFailureException - if the string cannot be parsed
      • parseDecimalPercent

        public static Decimal parseDecimalPercent​(String str)
        Parses a decimal from the input string, converting it from a percentage to decimal form.

        If input value is bracketed, it will be parsed as a negative value. For example '(12.3456789)' will be parsed as a big decimal -0.123456789.

        Parameters:
        str - the string to parse
        Returns:
        the parsed value in decimal form
        Throws:
        ParseFailureException - if the string cannot be parsed
      • parseDecimalBasisPoint

        public static Decimal parseDecimalBasisPoint​(String str)
        Parses a decimal from the input string, converting it from a basis points to decimal form.

        If input value is bracketed, it will be parsed as a negative value. For example '(12.3456789)' will be parsed as a big decimal -0.00123456789.

        Parameters:
        str - the string to parse
        Returns:
        the parsed value in decimal form
        Throws:
        ParseFailureException - if the string cannot be parsed
      • parsePercentage

        public static Percentage parsePercentage​(String str)
        Parses a percentage from the input string.

        If input value is bracketed, it will be parsed as a negative value. For example. '(12.3456789)' will be parsed as '-12.3456789%'.

        Parameters:
        str - the string to parse
        Returns:
        the parsed value
        Throws:
        ParseFailureException - if the string cannot be parsed
      • parseBasisPoints

        public static BasisPoints parseBasisPoints​(String str)
        Parses basis points from the input string.

        If input value is bracketed, it will be parsed as a negative value. For example. '(12.3456789)' will be parsed as '12.3456789bps'.

        Parameters:
        str - the string to parse
        Returns:
        the parsed value
        Throws:
        ParseFailureException - if the string cannot be parsed
      • parseDate

        public static LocalDate parseDate​(String str,
                                          DateTimeFormatter... formatters)
        Parses a date from the input string using the specified formatters.

        Each formatter is tried in order.

        Parameters:
        str - the string to parse
        formatters - the date formats
        Returns:
        the parsed value
        Throws:
        ParseFailureException - if the string cannot be parsed
      • parseDate

        public static LocalDate parseDate​(String str)
        Parses a date from the input string.

        Parsing is case insensitive. It accepts formats 'yyyy-MM-dd', 'yyyyMMdd', 'yyyy/M/d', 'd/M/yyyy', 'd-MMM-yyyy' or 'dMMMyyyy'. Some formats also accept two-digits years (use is not recommended): 'd/M/yy', 'd-MMM-yy' or 'dMMMyy'.

        Parameters:
        str - the string to parse
        Returns:
        the parsed value
        Throws:
        ParseFailureException - if the string cannot be parsed
      • parseYearMonth

        public static YearMonth parseYearMonth​(String str)
        Parses a year-month from the input string.

        Parsing is case insensitive. It accepts formats 'yyyy-MM', 'yyyyMM', 'MMM-yyyy' or 'MMMyyyy'. Some formats also accept two-digits years (use is not recommended): 'MMM-yy' or 'MMMyy'.

        Parameters:
        str - the string to parse
        Returns:
        the parsed value
        Throws:
        ParseFailureException - if the string cannot be parsed
      • parseTime

        public static LocalTime parseTime​(String str)
        Parses time from the input string.

        It accepts formats 'HH[:mm[:ss.SSS]]'.

        Parameters:
        str - the string to parse
        Returns:
        the parsed value
        Throws:
        ParseFailureException - if the string cannot be parsed
      • parseZoneId

        public static ZoneId parseZoneId​(String str)
        Parses time-zone from the input string.
        Parameters:
        str - the string to parse
        Returns:
        the parsed value
        Throws:
        ParseFailureException - if the string cannot be parsed
      • parsePeriod

        public static Period parsePeriod​(String str)
        Parses a period from the input string.

        It accepts the same formats as Period, but the "P" at the start is optional.

        Parameters:
        str - the string to parse
        Returns:
        the parsed value
        Throws:
        ParseFailureException - if the string cannot be parsed
      • tryParsePeriod

        public static Optional<Period> tryParsePeriod​(String str)
        Tries to parse a period from the input string.
        Parameters:
        str - the string to parse, may be null
        Returns:
        the parsed period, empty if unable to parse
      • parseMarketTenor

        public static MarketTenor parseMarketTenor​(String str)
        Parses a market tenor from the input string.
        Parameters:
        str - the string to parse
        Returns:
        the parsed value
        Throws:
        ParseFailureException - if the string cannot be parsed
      • tryParseMarketTenor

        public static Optional<MarketTenor> tryParseMarketTenor​(String str)
        Tries to parse a market tenor from the input string.
        Parameters:
        str - the string to parse, may be null
        Returns:
        the parsed market tenor, empty if unable to parse
      • parseTenor

        public static Tenor parseTenor​(String str)
        Parses a tenor from the input string.

        A tenor cannot be zero or negative.

        Parameters:
        str - the string to parse
        Returns:
        the parsed value
        Throws:
        ParseFailureException - if the string cannot be parsed
      • tryParseTenor

        public static Optional<Tenor> tryParseTenor​(String str)
        Tries to parse a tenor from the input string.

        Parsing is case insensitive.

        Parameters:
        str - the string to parse, may be null
        Returns:
        the parsed tenor, empty if unable to parse
      • parseFrequency

        public static Frequency parseFrequency​(String str)
        Parses a frequency from the input string.
        Parameters:
        str - the string to parse
        Returns:
        the parsed value
        Throws:
        ParseFailureException - if the string cannot be parsed
      • tryParseFrequency

        public static Optional<Frequency> tryParseFrequency​(String str)
        Tries to parse a frequency from the input string.
        Parameters:
        str - the string to parse, may be null
        Returns:
        the parsed frequency, empty if unable to parse
      • parseCurrency

        public static Currency parseCurrency​(String str)
        Parses currency from the input string.

        Parsing is case insensitive.

        Parameters:
        str - the string to parse
        Returns:
        the parsed currency
        Throws:
        ParseFailureException - if the string cannot be parsed
      • tryParseCurrency

        public static Optional<Currency> tryParseCurrency​(String str)
        Tries to parse a currency from the input string.

        Parsing is case insensitive.

        Parameters:
        str - the string to parse, may be null
        Returns:
        the parsed currency, empty if unable to parse
      • parseDayCount

        public static DayCount parseDayCount​(String str)
        Parses day count from the input string.

        Parsing is case insensitive. It leniently handles a variety of known variants of day counts.

        Parameters:
        str - the string to parse
        Returns:
        the parsed value
        Throws:
        ParseFailureException - if the string cannot be parsed
      • parseBusinessDayConvention

        public static BusinessDayConvention parseBusinessDayConvention​(String str)
        Parses business day convention from the input string.

        Parsing is case insensitive. It leniently handles a variety of known variants of business day conventions.

        Parameters:
        str - the string to parse
        Returns:
        the parsed value
        Throws:
        ParseFailureException - if the string cannot be parsed
      • parseRollConvention

        public static RollConvention parseRollConvention​(String str)
        Parses roll convention from the input string.

        Parsing is case insensitive. It leniently handles a variety of known variants of roll conventions.

        Parameters:
        str - the string to parse
        Returns:
        the parsed value
        Throws:
        ParseFailureException - if the string cannot be parsed
      • parseBuySell

        public static BuySell parseBuySell​(String str)
        Parses buy/sell from the input string.

        Parsing is case insensitive. Buy is parsed as 'BUY' or 'B'. Sell is parsed as 'SELL' or 'S'. Other strings are rejected.

        Parameters:
        str - the string to parse
        Returns:
        the parsed value
        Throws:
        ParseFailureException - if the string cannot be parsed
      • parseCapFloor

        public static CapFloor parseCapFloor​(String str)
        Parses cap/floor from the input string.

        Parsing is case insensitive. Cap is parsed as 'CAP' or 'C'. Floor is parsed as 'FLOOR' or 'F'. Other strings are rejected.

        Parameters:
        str - the string to parse
        Returns:
        the parsed value
        Throws:
        ParseFailureException - if the string cannot be parsed
      • parsePayReceive

        public static PayReceive parsePayReceive​(String str)
        Parses pay/receive from the input string.

        Parsing is case insensitive. Pay is parsed as 'PAY' or 'P'. Receive is parsed as 'RECEIVE', 'REC' or 'R'. Other strings are rejected.

        Parameters:
        str - the string to parse
        Returns:
        the parsed value
        Throws:
        ParseFailureException - if the string cannot be parsed
      • parsePutCall

        public static PutCall parsePutCall​(String str)
        Parses put/call from the input string.

        Parsing is case insensitive. Put is parsed as 'PUT' or 'P'. Call is parsed as 'CALL' or 'C'. Other strings are rejected.

        Parameters:
        str - the string to parse
        Returns:
        the parsed value
        Throws:
        ParseFailureException - if the string cannot be parsed
      • parseLongShort

        public static LongShort parseLongShort​(String str)
        Parses long/short from the input string.

        Parsing is case insensitive. Long is parsed as 'LONG' or 'L'. Short is parsed as 'SHORT' or 'S'. Other strings are rejected.

        Parameters:
        str - the string to parse
        Returns:
        the parsed value
        Throws:
        ParseFailureException - if the string cannot be parsed
      • parseBarrierType

        public static BarrierType parseBarrierType​(String str)
        Parses barrier type from the input string.

        Parsing is case insensitive. Up is parsed as 'UP' or 'U'. Down is parsed as 'DOWN' or 'D'. Other strings are rejected.

        Parameters:
        str - the string to parse
        Returns:
        the parsed value
        Throws:
        ParseFailureException - if the string cannot be parsed
      • parseKnockType

        public static KnockType parseKnockType​(String str)
        Parses knock type from the input string.

        Parsing is case insensitive. KnockIn is parsed as 'KNOCKIN', 'IN'. KnockOut is parsed as 'KNOCKOUT', 'OUT'. Other strings are rejected.

        Parameters:
        str - the string to parse
        Returns:
        the parsed value
        Throws:
        ParseFailureException - if the string cannot be parsed
      • parseRedCode

        public static StandardId parseRedCode​(String str)
        Parses a RED code from the input string.

        The input string but be 6 or 9 characters long to be valid.

        Parameters:
        str - the string to parse
        Returns:
        the parsed value
        Throws:
        ParseFailureException - if the string cannot be parsed