Class FxRatesCsvLoader


  • public final class FxRatesCsvLoader
    extends Object
    Loads a set of FX rates into memory from CSV resources.

    The rates are expected to be in a CSV format, with the following header row:
    Valuation Date, Currency Pair, Value.

    • The 'Valuation Date' column provides the valuation date, allowing data from different days to be stored in the same file
    • The 'Currency Pair' column is the currency pair in the format 'EUR/USD'.
    • The 'Value' column is the value of the rate.

    Each file may contain entries for many different dates.

    For example:

     Valuation Date, Currency Pair, Value
     2014-01-22, EUR/USD, 1.10
     2014-01-22, GBP/USD, 1.50
     2014-01-23, EUR/USD, 1.11
     
    Note that Microsoft Excel prefers the CSV file to have no space after the comma.

    CSV files sometimes contain a Unicode Byte Order Mark. Callers are responsible for handling this, such as by using UnicodeBom.

    • Method Detail

      • load

        public static ImmutableMap<FxRateId,​FxRate> load​(LocalDate marketDataDate,
                                                               ResourceLocator... resources)
        Loads one or more CSV format FX rate files for a specific date.

        Only those rates that match the specified date will be loaded.

        If the files contain a duplicate entry an exception will be thrown.

        Parameters:
        marketDataDate - the date to load
        resources - the CSV resources
        Returns:
        the loaded FX rates, mapped by rate ID
        Throws:
        IllegalArgumentException - if the files contain a duplicate entry
      • load

        public static ImmutableMap<FxRateId,​FxRate> load​(LocalDate marketDataDate,
                                                               Collection<ResourceLocator> resources)
        Loads one or more CSV format FX rate files for a specific date.

        Only those rates that match the specified date will be loaded.

        If the files contain a duplicate entry an exception will be thrown.

        Parameters:
        marketDataDate - the date to load
        resources - the CSV resources
        Returns:
        the loaded FX rates, mapped by rate ID
        Throws:
        IllegalArgumentException - if the files contain a duplicate entry
      • load

        public static ImmutableMap<LocalDate,​ImmutableMap<FxRateId,​FxRate>> load​(Set<LocalDate> marketDataDates,
                                                                                             ResourceLocator... resources)
        Loads one or more CSV format FX rate files for a set of dates.

        Only those rates that match one of the specified dates will be loaded.

        If the files contain a duplicate entry an exception will be thrown.

        Parameters:
        marketDataDates - the set of dates to load
        resources - the CSV resources
        Returns:
        the loaded FX rates, mapped by LocalDate and rate ID
        Throws:
        IllegalArgumentException - if the files contain a duplicate entry
      • parse

        public static ImmutableMap<LocalDate,​ImmutableMap<FxRateId,​FxRate>> parse​(Predicate<LocalDate> datePredicate,
                                                                                              Collection<CharSource> charSources)
        Parses one or more CSV format FX rate files.

        A predicate is specified that is used to filter the dates that are returned. This could match a single date, a set of dates or all dates.

        If the files contain a duplicate entry an exception will be thrown.

        Parameters:
        datePredicate - the predicate used to select the dates
        charSources - the CSV character sources
        Returns:
        the loaded FX rates, mapped by LocalDate and rate ID
        Throws:
        IllegalArgumentException - if the files contain a duplicate entry