Class CsvLoaderUtils

    • Method Detail

      • parseEtdVariant

        public static Pair<YearMonth,​EtdVariant> parseEtdVariant​(CsvRow row,
                                                                       EtdType type)
        Parses the year-month and variant.
        Parameters:
        row - the CSV row to parse
        type - the ETD type
        Returns:
        the expiry year-month and variant
        Throws:
        ParseFailureException - if the row cannot be parsed
      • parseEtdSettlementType

        public static EtdSettlementType parseEtdSettlementType​(String str)
        Parses the ETD settlement type from the short code or full name.
        Parameters:
        str - the string to parse
        Returns:
        the settlement type
        Throws:
        ParseFailureException - if the string cannot be parsed
      • parseEtdOptionType

        public static EtdOptionType parseEtdOptionType​(String str)
        Parses the ETD option type from the short code or full name.
        Parameters:
        str - the string to parse
        Returns:
        the option type
        Throws:
        ParseFailureException - if the string cannot be parsed
      • parseQuantity

        public static DoublesPair parseQuantity​(CsvRow row)
        Parses the quantity.
        Parameters:
        row - the CSV row to parse
        Returns:
        the quantity, long first, short second
        Throws:
        ParseFailureException - if the row cannot be parsed
      • parseZonedDateTime

        public static ZonedDateTime parseZonedDateTime​(CsvRow row,
                                                       String dateField,
                                                       String timeField,
                                                       String zoneField)
        Parse a ZonedDateTime from the provided fields.
        Parameters:
        row - the CSV row
        dateField - the date field
        timeField - the time field
        zoneField - the zone field
        Returns:
        the zoned date time
        Throws:
        ParseFailureException - if the row cannot be parsed
      • parseAdjustableDate

        public static AdjustableDate parseAdjustableDate​(CsvRow row,
                                                         String dateField,
                                                         String conventionField,
                                                         String calendarField)
        Parses a business day adjustment, without defaulting the adjustment.
        Parameters:
        row - the CSV row to parse
        dateField - the date field
        conventionField - the convention field
        calendarField - the calendar field
        Returns:
        the adjustment
        Throws:
        ParseFailureException - if the row cannot be parsed
      • parseAdjustableDate

        public static AdjustableDate parseAdjustableDate​(CsvRow row,
                                                         String dateField,
                                                         String conventionField,
                                                         String calendarField,
                                                         BusinessDayConvention defaultConvention,
                                                         Currency currency)
        Parses a business day adjustment, defaulting the adjustment using the currency.
        Parameters:
        row - the CSV row to parse
        dateField - the date field
        conventionField - the convention field
        calendarField - the calendar field
        defaultConvention - the default convention
        currency - the applicable currency, used for defaulting
        Returns:
        the adjustment
        Throws:
        ParseFailureException - if the row cannot be parsed
      • parseAdjustablePayment

        public static AdjustablePayment parseAdjustablePayment​(CsvRow row,
                                                               String currencyField,
                                                               String amountField,
                                                               String directionField,
                                                               String dateField,
                                                               String conventionField,
                                                               String calendarField)
        Parses an adjustable payment.
        Parameters:
        row - the CSV row to parse
        currencyField - the currency field
        amountField - the amount field
        directionField - the direction field
        dateField - the date field
        conventionField - the convention field
        calendarField - the calendar field
        Returns:
        the adjustable payment
        Throws:
        ParseFailureException - if the row cannot be parsed
      • parseBarrier

        public static Barrier parseBarrier​(CsvRow row,
                                           String barrierTypeField,
                                           String knockTypeField,
                                           String barrierLevelField)
        Parses a barrier from the csv row.
        Parameters:
        row - the CSV row to parse
        barrierTypeField - the barrier type field
        knockTypeField - the knock type field
        barrierLevelField - the barrier level field
        Returns:
        the barrier
        Throws:
        ParseFailureException - if the row cannot be parsed
      • parseBarrierFromDefaultFields

        public static Barrier parseBarrierFromDefaultFields​(CsvRow row)
        Parses a barrier using the default barrier fields.
        Parameters:
        row - the CSV row to parse
        Returns:
        the barrier
        Throws:
        ParseFailureException - if the row cannot be parsed
      • parsePremiumFromDefaultFields

        public static AdjustablePayment parsePremiumFromDefaultFields​(CsvRow row)
        Parses the premium using the default premium fields.
        Parameters:
        row - the CSV row to parse
        Returns:
        the adjustable payment
        Throws:
        ParseFailureException - if the row cannot be parsed
      • parseBusinessDayAdjustment

        public static Optional<BusinessDayAdjustment> parseBusinessDayAdjustment​(CsvRow row,
                                                                                 String conventionField,
                                                                                 String calendarField)
        Parses a business day adjustment.
        Parameters:
        row - the CSV row to parse
        conventionField - the convention field
        calendarField - the calendar field
        Returns:
        the adjustment
        Throws:
        ParseFailureException - if the row cannot be parsed
      • parseDaysAdjustment

        public static DaysAdjustment parseDaysAdjustment​(CsvRow row,
                                                         String daysField,
                                                         String daysCalField,
                                                         String cnvField,
                                                         String calField)
        Parses days adjustment from CSV.
        Parameters:
        row - the CSV row to parse
        daysField - the days field
        daysCalField - the days calendar field
        cnvField - the convention field
        calField - the calendar field
        Returns:
        the adjustment
        Throws:
        ParseFailureException - if the row cannot be parsed
      • parseCurrencyAmount

        public static CurrencyAmount parseCurrencyAmount​(CsvRow row,
                                                         String currencyField,
                                                         String amountField)
        Parses a currency amount.
        Parameters:
        row - the CSV row to parse
        currencyField - the currency field
        amountField - the amount field
        Returns:
        the currency amount
        Throws:
        ParseFailureException - if the row cannot be parsed
      • parseCurrencyAmountWithDirection

        public static CurrencyAmount parseCurrencyAmountWithDirection​(CsvRow row,
                                                                      String currencyField,
                                                                      String amountField,
                                                                      String directionField)
        Parses a currency amount with direction.
        Parameters:
        row - the CSV row to parse
        currencyField - the currency field
        amountField - the amount field
        directionField - the direction field
        Returns:
        the currency amount
        Throws:
        ParseFailureException - if the row cannot be parsed
      • tryParseAdjustableDate

        public static Optional<AdjustableDate> tryParseAdjustableDate​(CsvRow row,
                                                                      String dateField,
                                                                      String conventionField,
                                                                      String calendarField)
        Tries parsing an adjustable date from the mentioned fields in the csv row.
        Parameters:
        row - the CSV row to parse
        dateField - the date field
        conventionField - the convention field
        calendarField - the calendar field
        Returns:
        the adjustable date option
      • tryParseCurrencyAmountWithDirection

        public static Optional<CurrencyAmount> tryParseCurrencyAmountWithDirection​(CsvRow row,
                                                                                   String currencyField,
                                                                                   String amountField,
                                                                                   String directionField)
        Tries parsing a currency amount from the mentioned fields in the csv row.
        Parameters:
        row - the CSV row to parse
        currencyField - the currency field
        amountField - the amount field
        directionField - the direction field
        Returns:
        the currency amount option
      • tryParsePremiumFromDefaultFields

        public static Optional<AdjustablePayment> tryParsePremiumFromDefaultFields​(CsvRow row)
        Tries parsing the premium using the default premium fields.
        Parameters:
        row - the CSV row to parse
        Returns:
        the premium option
      • tryParseAdjustablePayment

        public static Optional<AdjustablePayment> tryParseAdjustablePayment​(CsvRow row,
                                                                            String currencyField,
                                                                            String amountField,
                                                                            String directionField,
                                                                            String dateField)
        Tries parsing an adjustable payment, defaulting the AdjustableDate to no BusinessDayAdjustment.
        Parameters:
        row - the CSV row to parse
        currencyField - the currency field
        amountField - the amount field
        directionField - the direction field
        dateField - the date field
        Returns:
        the adjustable payment option
      • tryParseAdjustablePayment

        public static Optional<AdjustablePayment> tryParseAdjustablePayment​(CsvRow row,
                                                                            String currencyField,
                                                                            String amountField,
                                                                            String directionField,
                                                                            String dateField,
                                                                            String conventionField,
                                                                            String calendarField)
        Tries parsing an adjustable payment using the mentioned fields.

        Defaults to tryParseAdjustablePayment(CsvRow,String,String,String,String) if the adjustable date parsing fails as it is often due to a missing calendar or convention.

        Parameters:
        row - the CSV row to parse
        currencyField - the currency field
        amountField - the amount field
        directionField - the direction field
        dateField - the date field
        conventionField - the date convention field
        calendarField - the date calendar field
        Returns:
        the adjustable payment option
      • formattedPercentage

        public static String formattedPercentage​(double value)
        Returns a value formatted as a percentage.

        Using this method avoids nasty effects from floating point arithmetic.

        Parameters:
        value - the value in decimal format (to be multiplied by 100)
        Returns:
        the formatted percentage value
      • formattedDouble

        public static String formattedDouble​(double value)
        Returns a value formatted as a double.

        Using this method avoids nasty effects from floating point arithmetic.

        Parameters:
        value - the value
        Returns:
        the formatted value