Class RatesCurvesCsvLoader


  • public final class RatesCurvesCsvLoader
    extends Object
    Loads a set of rates curves into memory by reading from CSV resources.

    There are three type of CSV files.

    The first file is the curve group metadata file. This file has the following header row:
    Group Name, Curve Type, Reference, Curve Name.

    • The 'Group Name' column is the name of the group of curves.
    • The 'Curve Type' column is the type of the curve, "forward" or "discount".
    • The 'Reference' column is the reference the curve is used for, such as "USD" or "USD-LIBOR-3M".
    • The 'Curve Name' column is the name of the curve.

    The second file is the curve settings metadata file. This file has the following header row:
    Curve Name, Value Type, Day Count, Interpolator, Left Extrapolator, Right Extrapolator.

    • The 'Curve Name' column is the name of the curve.
    • The 'Value Type' column is the type of data in the curve, "zero" for zero rates, or "df" for discount factors.
    • The 'Day Count' column is the name of the day count, such as "Act/365F".
    • The 'Interpolator' and extrapolator columns define the interpolator to use.

    The third file is the curve values file. This file has the following header row:
    Valuation Date, Curve Name, Date, Value, Label.

    • The 'Valuation Date' column provides the valuation date, allowing data from different days to be stored in the same file
    • The 'Curve Name' column is the name of the curve.
    • The 'Date' column is the date associated with the node.
    • The 'Value' column is value of the curve at the date.
    • The 'Label' column is the label used to refer to the node.

    Each curve must be contained entirely within a single file, but each file may contain more than one curve. The curve points do not need to be ordered.

    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 ImmutableList<RatesCurveGroup> load​(LocalDate marketDataDate,
                                                          ResourceLocator groupsResource,
                                                          ResourceLocator settingsResource,
                                                          Collection<ResourceLocator> curveValueResources)
        Loads one or more CSV format curve 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 curve date to load
        groupsResource - the curve groups CSV resource
        settingsResource - the curve settings CSV resource
        curveValueResources - the CSV resources for curves
        Returns:
        the loaded curves, mapped by an identifying key
        Throws:
        IllegalArgumentException - if the files contain a duplicate entry
      • loadAllDates

        public static ImmutableListMultimap<LocalDate,​RatesCurveGroup> loadAllDates​(ResourceLocator groupsResource,
                                                                                          ResourceLocator settingsResource,
                                                                                          Collection<ResourceLocator> curveValueResources)
        Loads one or more CSV format curve files for all available dates.

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

        Parameters:
        groupsResource - the curve groups CSV resource
        settingsResource - the curve settings CSV resource
        curveValueResources - the CSV resources for curves
        Returns:
        the loaded curves, mapped by date and identifier
        Throws:
        IllegalArgumentException - if the files contain a duplicate entry
      • parse

        public static ImmutableListMultimap<LocalDate,​RatesCurveGroup> parse​(Predicate<LocalDate> datePredicate,
                                                                                   CharSource groupsCharSource,
                                                                                   CharSource settingsCharSource,
                                                                                   Collection<CharSource> curveValueCharSources)
        Parses one or more CSV format curve files for all available dates.

        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
        groupsCharSource - the curve groups CSV character source
        settingsCharSource - the curve settings CSV character source
        curveValueCharSources - the CSV character sources for curves
        Returns:
        the loaded curves, mapped by date and identifier
        Throws:
        IllegalArgumentException - if the files contain a duplicate entry
      • writeCurveSettings

        public static void writeCurveSettings​(File file,
                                              RatesCurveGroup group)
        Writes the curve settings in a CSV format to a file.
        Parameters:
        file - the file
        group - the curve group
      • writeCurveSettings

        public static void writeCurveSettings​(Appendable underlying,
                                              RatesCurveGroup group)
        Writes the curve settings in a CSV format to an appendable.
        Parameters:
        underlying - the underlying appendable destination
        group - the curve group
      • writeCurveNodes

        public static void writeCurveNodes​(File file,
                                           LocalDate valuationDate,
                                           RatesCurveGroup group)
        Writes the curve groups definition in a CSV format to a file.
        Parameters:
        file - the file
        valuationDate - the valuation date
        group - the curve group
      • writeCurveNodes

        public static void writeCurveNodes​(Appendable underlying,
                                           LocalDate valuationDate,
                                           RatesCurveGroup group)
        Writes the curve nodes in a CSV format to an appendable.
        Parameters:
        underlying - the underlying appendable destination
        valuationDate - the valuation date
        group - the curve group