Class PositionCsvLoader


  • public final class PositionCsvLoader
    extends Object
    Loads positions from CSV files.

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

    Common

    The following standard columns are supported:

    • The 'Strata Position Type' column is optional, but mandatory when checking headers to see if the file is a known format. It defines the instrument type, 'SEC' or'Security' for standard securities, 'FUT' or 'Future' for ETD futures, and 'OPT' or 'Option' for ETD options. If absent, the type is derived based on the presence or absence of the 'Expiry' column.
    • The 'Id Scheme' column is optional, and is the name of the scheme that the position identifier is unique within, such as 'OG-Position'.
    • The 'Id' column is optional, and is the identifier of the position, such as 'POS12345'.

    SEC/Security

    The following columns are supported:

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

    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.

    FUT/Future

    The following columns are supported:

    • 'Exchange' - mandatory, the MIC code of the exchange where the ETD is traded
    • 'Contract Code' - mandatory, the contract code of the ETD at the exchange
    • 'Quantity' - see below
    • 'Long Quantity' - see below
    • 'Short Quantity' - see below
    • 'Expiry' - mandatory, the year-month of the expiry, in the format 'yyyy-MM'
    • 'Expiry Week' - optional, only used to obtain a weekly-expiring ETD
    • 'Expiry Day' - optional, only used to obtain a daily-expiring ETD, or Flex
    • 'Settlement Type' - optional, only used for Flex, see EtdSettlementType

    The exchange and contract code are combined to form an EtdContractSpecId which is resolved in ReferenceData to find additional details about the ETD. This process can be changed by providing an alternative PositionCsvInfoResolver.

    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.

    The expiry is normally controlled using just the 'Expiry' column. Flex options will also set the 'Expiry Day' and 'Settlement Type'.

    OPT/Option

    The following columns are supported:

    • 'Exchange' - mandatory, the MIC code of the exchange where the ETD is traded
    • 'Contract Code' - mandatory, the contract code of the ETD at the exchange
    • 'Quantity' - see below
    • 'Long Quantity' - see below
    • 'Short Quantity' - see below
    • 'Expiry' - mandatory, the year-month of the expiry, in the format 'yyyy-MM'
    • 'Expiry Week' - optional, only used to obtain a weekly-expiring ETD
    • 'Expiry Day' - optional, only used to obtain a daily-expiring ETD, or Flex
    • 'Settlement Type' - optional, only used for Flex, see EtdSettlementType
    • 'Exercise Style' - optional, only used for Flex, see EtdOptionType
    • 'Put Call' - mandatory, 'Put', 'P', 'Call' or 'C'
    • 'Exercise Price' - mandatory, the strike price, such as 1.23
    • 'Version' - optional, the version of the contract, not widely used, defaults to zero
    • 'Underlying Expiry' - optional, the expiry year-month of the underlying instrument if applicable, in the format 'yyyy-MM'

    The exchange and contract code are combined to form an EtdContractSpecId which is resolved in ReferenceData to find additional details about the ETD. This process can be changed by providing an alternative PositionCsvInfoResolver.

    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.

    The expiry is normally controlled using just the 'Expiry' column. Flex options will also set the 'Expiry Day', 'Settlement Type' and 'Exercise Style'.

    • Method Detail

      • standard

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

        public static PositionCsvLoader 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 PositionCsvLoader of​(PositionCsvInfoResolver 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<Position>> load​(ResourceLocator... resources)
        Loads one or more CSV format position 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 positions, position-level errors are captured in the result
      • load

        public ValueWithFailures<List<Position>> load​(Collection<ResourceLocator> resources)
        Loads one or more CSV format position 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 positions, all errors are captured in the result
      • isKnownFormat

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

        This parses the headers as CSV and checks that mandatory headers are present. This is determined entirely from the 'Strata Position 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<Position>> parse​(Collection<CharSource> charSources)
        Parses one or more CSV format position files, returning ETD futures and options using information from reference data.

        When an ETD row is found, reference data is used to find the correct security. This uses EtdContractSpec by default, although this can be overridden in the resolver. Futures and options will be returned as EtdFuturePosition and EtdOptionPosition.

        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 positions, all errors are captured in the result
      • parseLightweight

        @Deprecated
        public ValueWithFailures<List<SecurityPosition>> parseLightweight​(Collection<CharSource> charSources)
        Deprecated.
        Parses one or more CSV format position files, returning ETD futures and options by identifier without using reference data.

        When an ETD row is found, EtdIdUtils is used to create an identifier. The identifier is used to create a SecurityPosition, with no call to reference data.

        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 positions, all errors are captured in the result
      • parse

        public <T extends PositionValueWithFailures<List<T>> parse​(Collection<CharSource> charSources,
                                                                     Class<T> positionType)
        Parses one or more CSV format position files.

        A type is specified to filter the positions. If the type is SecurityPosition, then ETD parsing will proceed as per parseLightweight(Collection). Otherwise, ETD parsing will proceed as per parse(Collection).

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

        Type Parameters:
        T - the position type
        Parameters:
        charSources - the CSV character sources
        positionType - the position type to return
        Returns:
        the loaded positions, all errors are captured in the result