Class QuotesCsvLoader


  • public final class QuotesCsvLoader
    extends java.lang.Object
    Loads a set of quotes into memory from CSV resources.

    The quotes are expected to be in a CSV format, with the following header row:
    Valuation Date, Symbology, Ticker, Value.

    • The 'Valuation Date' column provides the valuation date, allowing data from different days to be stored in the same file
    • The 'Symbology' column is the symbology scheme applicable to the ticker.
    • The 'Ticker' column is the identifier within the symbology.
    • The 'Field Name' column is the field name, defaulted to 'MarketValue', allowing fields such as 'Bid' or 'Ask' to be specified.
    • The 'Value' column is the value of the ticker.

    Each quotes file may contain entries for many different dates.

    For example:

     Valuation Date, Symbology, Ticker, Field Name, Value
     2014-01-22, OG-Future, Eurex-FGBL-Mar14, MarketValue, 150.43
     2014-01-22, OG-FutOpt, Eurex-OGBL-Mar14-C150, MarketValue, 1.5
     2014-01-22, OG-Future, CME-ED-Mar14, MarketValue, 99.620
     
    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<QuoteId,​java.lang.Double> load​(java.time.LocalDate marketDataDate, ResourceLocator... resources)
      Loads one or more CSV format quote files for a specific date.
      static com.google.common.collect.ImmutableMap<QuoteId,​java.lang.Double> load​(java.time.LocalDate marketDataDate, java.util.Collection<ResourceLocator> resources)
      Loads one or more CSV format quote files for a specific date.
      static com.google.common.collect.ImmutableMap<java.time.LocalDate,​com.google.common.collect.ImmutableMap<QuoteId,​java.lang.Double>> load​(java.util.Set<java.time.LocalDate> marketDataDates, ResourceLocator... resources)
      Loads one or more CSV format quote files for a set of dates.
      static com.google.common.collect.ImmutableMap<java.time.LocalDate,​com.google.common.collect.ImmutableMap<QuoteId,​java.lang.Double>> load​(java.util.Set<java.time.LocalDate> marketDataDates, java.util.Collection<ResourceLocator> resources)
      Loads one or more CSV format quote files for a set of dates.
      static com.google.common.collect.ImmutableMap<java.time.LocalDate,​com.google.common.collect.ImmutableMap<QuoteId,​java.lang.Double>> loadAllDates​(ResourceLocator... resources)
      Loads one or more CSV format quote files.
      static com.google.common.collect.ImmutableMap<java.time.LocalDate,​com.google.common.collect.ImmutableMap<QuoteId,​java.lang.Double>> loadAllDates​(java.util.Collection<ResourceLocator> resources)
      Loads one or more CSV format quote files.
      static com.google.common.collect.ImmutableMap<java.time.LocalDate,​com.google.common.collect.ImmutableMap<QuoteId,​java.lang.Double>> parse​(java.util.function.Predicate<java.time.LocalDate> datePredicate, java.util.Collection<com.google.common.io.CharSource> charSources)
      Parses one or more CSV format quote 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<QuoteId,​java.lang.Double> load​(java.time.LocalDate marketDataDate,
                                                                                                  ResourceLocator... resources)
        Loads one or more CSV format quote files for a specific date.

        Only those quotes 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 quotes, mapped by quote ID
        Throws:
        java.lang.IllegalArgumentException - if the files contain a duplicate entry
      • load

        public static com.google.common.collect.ImmutableMap<QuoteId,​java.lang.Double> load​(java.time.LocalDate marketDataDate,
                                                                                                  java.util.Collection<ResourceLocator> resources)
        Loads one or more CSV format quote files for a specific date.

        Only those quotes 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 quotes, mapped by quote 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<QuoteId,​java.lang.Double>> load​(java.util.Set<java.time.LocalDate> marketDataDates,
                                                                                                                                                                    ResourceLocator... resources)
        Loads one or more CSV format quote files for a set of dates.

        Only those quotes 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 quotes, mapped by LocalDate and quote 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<QuoteId,​java.lang.Double>> load​(java.util.Set<java.time.LocalDate> marketDataDates,
                                                                                                                                                                    java.util.Collection<ResourceLocator> resources)
        Loads one or more CSV format quote files for a set of dates.

        Only those quotes 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 quotes, mapped by LocalDate and quote 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<QuoteId,​java.lang.Double>> loadAllDates​(ResourceLocator... resources)
        Loads one or more CSV format quote 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 quotes, mapped by LocalDate and quote 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<QuoteId,​java.lang.Double>> loadAllDates​(java.util.Collection<ResourceLocator> resources)
        Loads one or more CSV format quote 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 quotes, mapped by LocalDate and quote 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<QuoteId,​java.lang.Double>> parse​(java.util.function.Predicate<java.time.LocalDate> datePredicate,
                                                                                                                                                                     java.util.Collection<com.google.common.io.CharSource> charSources)
        Parses one or more CSV format quote 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 quotes, mapped by LocalDate and quote ID
        Throws:
        java.lang.IllegalArgumentException - if the files contain a duplicate entry