Class FxRatesCsvLoader


  • public final class FxRatesCsvLoader
    extends java.lang.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 Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static com.google.common.collect.ImmutableMap<FxRateId,​FxRate> load​(java.time.LocalDate marketDataDate, ResourceLocator... resources)
      Loads one or more CSV format FX rate files for a specific date.
      static com.google.common.collect.ImmutableMap<FxRateId,​FxRate> load​(java.time.LocalDate marketDataDate, java.util.Collection<ResourceLocator> resources)
      Loads one or more CSV format FX rate files for a specific date.
      static com.google.common.collect.ImmutableMap<java.time.LocalDate,​com.google.common.collect.ImmutableMap<FxRateId,​FxRate>> load​(java.util.Set<java.time.LocalDate> marketDataDates, ResourceLocator... resources)
      Loads one or more CSV format FX rate files for a set of dates.
      static com.google.common.collect.ImmutableMap<java.time.LocalDate,​com.google.common.collect.ImmutableMap<FxRateId,​FxRate>> load​(java.util.Set<java.time.LocalDate> marketDataDates, java.util.Collection<ResourceLocator> resources)
      Loads one or more CSV format FX rate files for a set of dates.
      static com.google.common.collect.ImmutableMap<java.time.LocalDate,​com.google.common.collect.ImmutableMap<FxRateId,​FxRate>> loadAllDates​(ResourceLocator... resources)
      Loads one or more CSV format FX rate files.
      static com.google.common.collect.ImmutableMap<java.time.LocalDate,​com.google.common.collect.ImmutableMap<FxRateId,​FxRate>> loadAllDates​(java.util.Collection<ResourceLocator> resources)
      Loads one or more CSV format FX rate files.
      static com.google.common.collect.ImmutableMap<java.time.LocalDate,​com.google.common.collect.ImmutableMap<FxRateId,​FxRate>> parse​(java.util.function.Predicate<java.time.LocalDate> datePredicate, java.util.Collection<com.google.common.io.CharSource> charSources)
      Parses one or more CSV format FX rate files.
      • Methods inherited from class java.lang.Object

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

      • load

        public static com.google.common.collect.ImmutableMap<FxRateId,​FxRate> load​(java.time.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:
        java.lang.IllegalArgumentException - if the files contain a duplicate entry
      • load

        public static com.google.common.collect.ImmutableMap<FxRateId,​FxRate> load​(java.time.LocalDate marketDataDate,
                                                                                         java.util.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:
        java.lang.IllegalArgumentException - if the files contain a duplicate entry
      • load

        public static com.google.common.collect.ImmutableMap<java.time.LocalDate,​com.google.common.collect.ImmutableMap<FxRateId,​FxRate>> load​(java.util.Set<java.time.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:
        java.lang.IllegalArgumentException - if the files contain a duplicate entry
      • load

        public static com.google.common.collect.ImmutableMap<java.time.LocalDate,​com.google.common.collect.ImmutableMap<FxRateId,​FxRate>> load​(java.util.Set<java.time.LocalDate> marketDataDates,
                                                                                                                                                           java.util.Collection<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 dates to load
        resources - the CSV resources
        Returns:
        the loaded FX rates, mapped by LocalDate and rate ID
        Throws:
        java.lang.IllegalArgumentException - if the files contain a duplicate entry
      • loadAllDates

        public static com.google.common.collect.ImmutableMap<java.time.LocalDate,​com.google.common.collect.ImmutableMap<FxRateId,​FxRate>> loadAllDates​(ResourceLocator... resources)
        Loads one or more CSV format FX rate files.

        All dates that are found will be returned.

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

        Parameters:
        resources - the CSV resources
        Returns:
        the loaded FX rates, mapped by LocalDate and rate ID
        Throws:
        java.lang.IllegalArgumentException - if the files contain a duplicate entry
      • loadAllDates

        public static com.google.common.collect.ImmutableMap<java.time.LocalDate,​com.google.common.collect.ImmutableMap<FxRateId,​FxRate>> loadAllDates​(java.util.Collection<ResourceLocator> resources)
        Loads one or more CSV format FX rate files.

        All dates that are found will be returned.

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

        Parameters:
        resources - the CSV resources
        Returns:
        the loaded FX rates, mapped by LocalDate and rate ID
        Throws:
        java.lang.IllegalArgumentException - if the files contain a duplicate entry
      • parse

        public static com.google.common.collect.ImmutableMap<java.time.LocalDate,​com.google.common.collect.ImmutableMap<FxRateId,​FxRate>> parse​(java.util.function.Predicate<java.time.LocalDate> datePredicate,
                                                                                                                                                            java.util.Collection<com.google.common.io.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:
        java.lang.IllegalArgumentException - if the files contain a duplicate entry