Class QuotesCsvLoader


  • public final class QuotesCsvLoader
    extends 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 Detail

      • load

        public static ImmutableMap<QuoteId,​Double> load​(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:
        IllegalArgumentException - if the files contain a duplicate entry
      • load

        public static ImmutableMap<QuoteId,​Double> load​(LocalDate marketDataDate,
                                                              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:
        IllegalArgumentException - if the files contain a duplicate entry
      • load

        public static ImmutableMap<LocalDate,​ImmutableMap<QuoteId,​Double>> load​(Set<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:
        IllegalArgumentException - if the files contain a duplicate entry
      • parse

        public static ImmutableMap<LocalDate,​ImmutableMap<QuoteId,​Double>> parse​(Predicate<LocalDate> datePredicate,
                                                                                             Collection<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:
        IllegalArgumentException - if the files contain a duplicate entry