Class LoaderUtils


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

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static Index findIndex​(java.lang.String reference)
      Attempts to locate a rate index by reference name.
      static boolean parseBoolean​(java.lang.String str)
      Parses a boolean from the input string.
      static BusinessDayConvention parseBusinessDayConvention​(java.lang.String str)
      Parses business day convention from the input string.
      static BuySell parseBuySell​(java.lang.String str)
      Parses buy/sell from the input string.
      static Currency parseCurrency​(java.lang.String str)
      Parses currency from the input string.
      static java.time.LocalDate parseDate​(java.lang.String str)
      Parses a date from the input string.
      static DayCount parseDayCount​(java.lang.String str)
      Parses day count from the input string.
      static double parseDouble​(java.lang.String str)
      Parses a double from the input string.
      static double parseDoublePercent​(java.lang.String str)
      Parses a double from the input string, converting it from a percentage to a decimal values.
      static int parseInteger​(java.lang.String str)
      Parses an integer from the input string.
      static PayReceive parsePayReceive​(java.lang.String str)
      Parses pay/receive from the input string.
      static java.time.Period parsePeriod​(java.lang.String str)
      Parses a period from the input string.
      static PutCall parsePutCall​(java.lang.String str)
      Parses put/call from the input string.
      static RollConvention parseRollConvention​(java.lang.String str)
      Parses roll convention from the input string.
      static Tenor parseTenor​(java.lang.String str)
      Parses a tenor from the input string.
      static java.time.LocalTime parseTime​(java.lang.String str)
      Parses time from the input string.
      static java.time.YearMonth parseYearMonth​(java.lang.String str)
      Parses a year-month from the input string.
      static java.util.Optional<Currency> tryParseCurrency​(java.lang.String str)
      Tries to parse a currency from the input string.
      static java.util.Optional<Tenor> tryParseTenor​(java.lang.String str)
      Tries to parse a tenor from the input string.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • DEFAULT_TRADE_SCHEME

        public static final java.lang.String DEFAULT_TRADE_SCHEME
        Default scheme for trades.
        See Also:
        Constant Field Values
      • DEFAULT_POSITION_SCHEME

        public static final java.lang.String DEFAULT_POSITION_SCHEME
        Default scheme for positions.
        See Also:
        Constant Field Values
      • DEFAULT_SECURITY_SCHEME

        public static final java.lang.String DEFAULT_SECURITY_SCHEME
        Default scheme for securities.
        See Also:
        Constant Field Values
    • Method Detail

      • findIndex

        public static Index findIndex​(java.lang.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​(java.lang.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:
        java.lang.IllegalArgumentException - if the string cannot be parsed
      • parseInteger

        public static int parseInteger​(java.lang.String str)
        Parses an integer from the input string.
        Parameters:
        str - the string to parse
        Returns:
        the parsed value
        Throws:
        java.lang.NumberFormatException - if the string cannot be parsed
      • parseDouble

        public static double parseDouble​(java.lang.String str)
        Parses a double from the input string.
        Parameters:
        str - the string to parse
        Returns:
        the parsed value
        Throws:
        java.lang.NumberFormatException - if the string cannot be parsed
      • parseDoublePercent

        public static double parseDoublePercent​(java.lang.String str)
        Parses a double from the input string, converting it from a percentage to a decimal values.
        Parameters:
        str - the string to parse
        Returns:
        the parsed value
        Throws:
        java.lang.NumberFormatException - if the string cannot be parsed
      • parseDate

        public static java.time.LocalDate parseDate​(java.lang.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:
        java.lang.IllegalArgumentException - if the string cannot be parsed
      • parseYearMonth

        public static java.time.YearMonth parseYearMonth​(java.lang.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:
        java.lang.IllegalArgumentException - if the string cannot be parsed
      • parseTime

        public static java.time.LocalTime parseTime​(java.lang.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:
        java.lang.IllegalArgumentException - if the string cannot be parsed
      • parsePeriod

        public static java.time.Period parsePeriod​(java.lang.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:
        java.lang.IllegalArgumentException - if the string cannot be parsed
      • parseTenor

        public static Tenor parseTenor​(java.lang.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:
        java.lang.IllegalArgumentException - if the string cannot be parsed
      • tryParseTenor

        public static java.util.Optional<Tenor> tryParseTenor​(java.lang.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
      • parseCurrency

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

        Parsing is case insensitive.

        Parameters:
        str - the string to parse
        Returns:
        the parsed currency
        Throws:
        java.lang.IllegalArgumentException - if the string cannot be parsed
      • tryParseCurrency

        public static java.util.Optional<Currency> tryParseCurrency​(java.lang.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​(java.lang.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:
        java.lang.IllegalArgumentException - if the string cannot be parsed
      • parseBusinessDayConvention

        public static BusinessDayConvention parseBusinessDayConvention​(java.lang.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:
        java.lang.IllegalArgumentException - if the string cannot be parsed
      • parseRollConvention

        public static RollConvention parseRollConvention​(java.lang.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:
        java.lang.IllegalArgumentException - if the string cannot be parsed
      • parseBuySell

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

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

        Parameters:
        str - the string to parse
        Returns:
        the parsed value
        Throws:
        java.lang.IllegalArgumentException - if the string cannot be parsed
      • parsePayReceive

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

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

        Parameters:
        str - the string to parse
        Returns:
        the parsed value
        Throws:
        java.lang.IllegalArgumentException - if the string cannot be parsed
      • parsePutCall

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

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

        Parameters:
        str - the string to parse
        Returns:
        the parsed value
        Throws:
        java.lang.IllegalArgumentException - if the string cannot be parsed