Class RatesCurvesCsvLoader


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

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static com.google.common.collect.ImmutableList<RatesCurveGroup> load​(java.time.LocalDate marketDataDate, ResourceLocator groupsResource, ResourceLocator settingsResource, java.util.Collection<ResourceLocator> curveValueResources)
      Loads one or more CSV format curve files for a specific date.
      static com.google.common.collect.ImmutableListMultimap<java.time.LocalDate,​RatesCurveGroup> loadAllDates​(ResourceLocator groupsResource, ResourceLocator settingsResource, java.util.Collection<ResourceLocator> curveValueResources)
      Loads one or more CSV format curve files for all available dates.
      static com.google.common.collect.ImmutableListMultimap<java.time.LocalDate,​RatesCurveGroup> parse​(java.util.function.Predicate<java.time.LocalDate> datePredicate, com.google.common.io.CharSource groupsCharSource, com.google.common.io.CharSource settingsCharSource, java.util.Collection<com.google.common.io.CharSource> curveValueCharSources)
      Parses one or more CSV format curve files for all available dates.
      static void writeCurveNodes​(java.io.File file, java.time.LocalDate valuationDate, RatesCurveGroup group)
      Writes the curve groups definition in a CSV format to a file.
      static void writeCurveNodes​(java.lang.Appendable underlying, java.time.LocalDate valuationDate, RatesCurveGroup group)
      Writes the curve nodes in a CSV format to an appendable.
      static void writeCurveSettings​(java.io.File file, RatesCurveGroup group)
      Writes the curve settings in a CSV format to a file.
      static void writeCurveSettings​(java.lang.Appendable underlying, RatesCurveGroup group)
      Writes the curve settings in a CSV format to an appendable.
      • 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.ImmutableList<RatesCurveGroup> load​(java.time.LocalDate marketDataDate,
                                                                                    ResourceLocator groupsResource,
                                                                                    ResourceLocator settingsResource,
                                                                                    java.util.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:
        java.lang.IllegalArgumentException - if the files contain a duplicate entry
      • loadAllDates

        public static com.google.common.collect.ImmutableListMultimap<java.time.LocalDate,​RatesCurveGroup> loadAllDates​(ResourceLocator groupsResource,
                                                                                                                              ResourceLocator settingsResource,
                                                                                                                              java.util.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:
        java.lang.IllegalArgumentException - if the files contain a duplicate entry
      • parse

        public static com.google.common.collect.ImmutableListMultimap<java.time.LocalDate,​RatesCurveGroup> parse​(java.util.function.Predicate<java.time.LocalDate> datePredicate,
                                                                                                                       com.google.common.io.CharSource groupsCharSource,
                                                                                                                       com.google.common.io.CharSource settingsCharSource,
                                                                                                                       java.util.Collection<com.google.common.io.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:
        java.lang.IllegalArgumentException - if the files contain a duplicate entry
      • writeCurveSettings

        public static void writeCurveSettings​(java.io.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​(java.lang.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​(java.io.File file,
                                           java.time.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​(java.lang.Appendable underlying,
                                           java.time.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