Class TradeCsvLoader


  • public final class TradeCsvLoader
    extends Object
    Loads trades from CSV files.

    The trades are expected to be in a CSV format known to Strata. The parser is flexible, understanding a number of different ways to define each trade. Columns may occur in any order.

    Common

    The following standard columns are supported:

    • The 'Strata Trade Type' column is required, and must be the instrument type, such as 'Fra' or 'Swap'
    • The 'Id Scheme' column is optional, and is the name of the scheme that the trade identifier is unique within, such as 'OG-Trade'
    • The 'Id' column is optional, and is the identifier of the trade, such as 'FRA12345'
    • The 'Counterparty Scheme' column is optional, and is the name of the scheme that the trade identifier is unique within, such as 'OG-Counterparty'
    • The 'Counterparty' column is optional, and is the identifier of the trade's counterparty, such as 'Bank-A'
    • The 'Trade Date' column is optional, and is the date that the trade occurred, such as '2017-08-01'
    • The 'Trade Time' column is optional, and is the time of day that the trade occurred, such as '11:30'
    • The 'Trade Zone' column is optional, and is the time-zone that the trade occurred, such as 'Europe/London'
    • The 'Settlement Date' column is optional, and is the date that the trade settles, such as '2017-08-01'

    Fra

    The following columns are supported for 'Fra' trades:

    • 'Buy Sell' - mandatory
    • 'Notional' - mandatory
    • 'Fixed Rate' - mandatory, percentage
    • 'Convention' - see below, see FraConventions
    • 'Period To Start' - see below
    • 'Start Date' - see below
    • 'End Date' - see below
    • 'Index' - see below
    • 'Interpolated Index' - see below
    • 'Day Count' - see below
    • 'Date Convention' - optional
    • 'Date Calendar' - optional

    Valid combinations to define a FRA are:

    • 'Convention', 'Trade Date', 'Period To Start'
    • 'Convention', 'Start Date', 'End Date'
    • 'Index', 'Start Date', 'End Date' plus optionally 'Interpolated Index', 'Day Count'

    Swap

    The following columns are supported for 'Swap' trades:

    • 'Buy Sell' - mandatory
    • 'Notional' - mandatory
    • 'Fixed Rate' - mandatory, percentage (treated as the spread for some swap types)
    • 'Convention' - mandatory, see SingleCurrencySwapConvention implementations
    • 'Period To Start'- see below
    • 'Tenor'- see below
    • 'Start Date'- see below
    • 'End Date'- see below
    • 'Roll Convention' - optional
    • 'Stub Convention' - optional
    • 'First Regular Start Date' - optional
    • 'Last Regular End Date' - optional
    • 'Date Convention' - optional
    • 'Date Calendar' - optional

    Valid combinations to define a Swap are:

    • 'Convention', 'Trade Date', 'Period To Start', 'Tenor'
    • 'Convention', 'Start Date', 'End Date'
    • 'Convention', 'Start Date', 'Tenor'
    • Explicitly by defining each leg (not detailed here)

    Term Deposit

    The following columns are supported for 'TermDeposit' trades:

    • 'Buy Sell' - mandatory
    • 'Notional' - mandatory
    • 'Fixed Rate' - mandatory, percentage
    • 'Convention'- see below, see TermDepositConventions implementations
    • 'Tenor'- see below
    • 'Start Date'- see below
    • 'End Date'- see below
    • 'Currency'- see below
    • 'Day Count'- see below
    • 'Date Convention' - optional
    • 'Date Calendar' - optional

    Valid combinations to define a Term Deposit are:

    • 'Convention', 'Trade Date', 'Period To Start'
    • 'Convention', 'Start Date', 'End Date'
    • 'Start Date', 'End Date', 'Currency', 'Day Count'

    FX Singles

    The following columns are supported for 'FX Singles' (FX Spots and FX Forwards) trades:

    • 'Buy Sell' - optional, if not present notional must be signed
    • 'Currency' - mandatory
    • 'Notional' - mandatory
    • 'FX Rate' - mandatory
    • 'Payment Date - mandatory'
    • 'Payment Date Convention' - optional field. See BusinessDayConventions for possible values.
    • 'Payment Date Calendar' - optional field. See HolidayCalendarIds for possible values.

    FX Swaps

    The following columns are supported for 'FxSwap' trades:

    • 'Buy Sell' - optional, if not present notional must be signed
    • 'Currency' - mandatory
    • 'Notional' - mandatory
    • 'FX Rate' - mandatory
    • Payment Date - mandatory
    • 'Far FX Rate' - mandatory
    • 'Far Payment Date' - mandatory
    • 'Payment Date Convention' - optional field. See BusinessDayConventions for possible values.
    • 'Payment Date Calendar' - optional field. See HolidayCalendarIds for possible values.

    Security

    The following columns are supported for 'Security' trades:

    • 'Security Id Scheme' - optional, defaults to 'OG-Security'
    • 'Security Id' - mandatory
    • 'Quantity' - see below
    • 'Long Quantity' - see below
    • 'Short Quantity' - see below
    • 'Price' - optional

    The quantity will normally be set from the 'Quantity' column. If that column is not found, the 'Long Quantity' and 'Short Quantity' columns will be used instead.

    • Method Detail

      • standard

        public static TradeCsvLoader standard()
        Obtains an instance that uses the standard set of reference data.
        Returns:
        the loader
      • of

        public static TradeCsvLoader of​(ReferenceData refData)
        Obtains an instance that uses the specified set of reference data.
        Parameters:
        refData - the reference data
        Returns:
        the loader
      • of

        public static TradeCsvLoader of​(TradeCsvInfoResolver resolver)
        Obtains an instance that uses the specified resolver for additional information.
        Parameters:
        resolver - the resolver used to parse additional information
        Returns:
        the loader
      • load

        public ValueWithFailures<List<Trade>> load​(ResourceLocator... resources)
        Loads one or more CSV format trade files.

        CSV files sometimes contain a Unicode Byte Order Mark. This method uses UnicodeBom to interpret it.

        Parameters:
        resources - the CSV resources
        Returns:
        the loaded trades, trade-level errors are captured in the result
      • load

        public ValueWithFailures<List<Trade>> load​(Collection<ResourceLocator> resources)
        Loads one or more CSV format trade files.

        CSV files sometimes contain a Unicode Byte Order Mark. This method uses UnicodeBom to interpret it.

        Parameters:
        resources - the CSV resources
        Returns:
        the loaded trades, all errors are captured in the result
      • isKnownFormat

        public boolean isKnownFormat​(CharSource charSource)
        Checks whether the source is a CSV format trade file.

        This parses the headers as CSV and checks that mandatory headers are present. This is determined entirely from the 'Strata Trade Type' column.

        Parameters:
        charSource - the CSV character source to check
        Returns:
        true if the source is a CSV file with known headers, false otherwise
      • parse

        public ValueWithFailures<List<Trade>> parse​(Collection<CharSource> charSources)
        Parses one or more CSV format trade files.

        CSV files sometimes contain a Unicode Byte Order Mark. Callers are responsible for handling this, such as by using UnicodeBom.

        Parameters:
        charSources - the CSV character sources
        Returns:
        the loaded trades, all errors are captured in the result
      • parse

        public ValueWithFailures<List<Trade>> parse​(Collection<CharSource> charSources,
                                                    List<Class<? extends Trade>> tradeTypes)
        Parses one or more CSV format trade files with an error-creating type filter.

        A list of types is specified to filter the trades. Trades that do not match the type will be included in the failure list.

        CSV files sometimes contain a Unicode Byte Order Mark. Callers are responsible for handling this, such as by using UnicodeBom.

        Parameters:
        charSources - the CSV character sources
        tradeTypes - the trade types to return
        Returns:
        the loaded trades, all errors are captured in the result
      • parse

        public <T extends TradeValueWithFailures<List<T>> parse​(Collection<CharSource> charSources,
                                                                  Class<T> tradeType)
        Parses one or more CSV format trade files with a quiet type filter.

        A type is specified to filter the trades. Trades that do not match the type are silently dropped.

        CSV files sometimes contain a Unicode Byte Order Mark. Callers are responsible for handling this, such as by using UnicodeBom.

        Type Parameters:
        T - the trade type
        Parameters:
        charSources - the CSV character sources
        tradeType - the trade type to return
        Returns:
        the loaded trades, all errors are captured in the result