Package com.opengamma.strata.loader.csv
Class CsvLoaderUtils
- java.lang.Object
-
- com.opengamma.strata.loader.csv.CsvLoaderUtils
-
public final class CsvLoaderUtils extends Object
CSV information resolver helper.This simplifies implementations of
TradeCsvInfoResolver
andPositionCsvInfoResolver
.
-
-
Field Summary
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
formattedDouble(double value)
Returns a value formatted as a double.static String
formattedPercentage(double value)
Returns a value formatted as a percentage.static AdjustableDate
parseAdjustableDate(CsvRow row, String dateField, String conventionField, String calendarField)
Parses a business day adjustment, without defaulting the adjustment.static AdjustableDate
parseAdjustableDate(CsvRow row, String dateField, String conventionField, String calendarField, BusinessDayConvention defaultConvention, Currency currency)
Parses a business day adjustment, defaulting the adjustment using the currency.static AdjustablePayment
parseAdjustablePayment(CsvRow row, String currencyField, String amountField, String directionField, String dateField, String conventionField, String calendarField)
Parses an adjustable payment.static Barrier
parseBarrier(CsvRow row, String barrierTypeField, String knockTypeField, String barrierLevelField)
Parses a barrier from the csv row.static Barrier
parseBarrierFromDefaultFields(CsvRow row)
Parses a barrier using the default barrier fields.static Optional<BusinessDayAdjustment>
parseBusinessDayAdjustment(CsvRow row, String conventionField, String calendarField)
Parses a business day adjustment.static CurrencyAmount
parseCurrencyAmount(CsvRow row, String currencyField, String amountField)
Parses a currency amount.static CurrencyAmount
parseCurrencyAmountWithDirection(CsvRow row, String currencyField, String amountField, String directionField)
Parses a currency amount with direction.static DaysAdjustment
parseDaysAdjustment(CsvRow row, String daysField, String daysCalField, String cnvField, String calField)
Parses days adjustment from CSV.static EtdOptionType
parseEtdOptionType(String str)
Parses the ETD option type from the short code or full name.static EtdSettlementType
parseEtdSettlementType(String str)
Parses the ETD settlement type from the short code or full name.static Pair<YearMonth,EtdVariant>
parseEtdVariant(CsvRow row, EtdType type)
Parses the year-month and variant.static AdjustablePayment
parsePremiumFromDefaultFields(CsvRow row)
Parses the premium using the default premium fields.static DoublesPair
parseQuantity(CsvRow row)
Parses the quantity.static ZonedDateTime
parseZonedDateTime(CsvRow row, String dateField, String timeField, String zoneField)
Parse a ZonedDateTime from the provided fields.static Optional<AdjustableDate>
tryParseAdjustableDate(CsvRow row, String dateField, String conventionField, String calendarField)
Tries parsing an adjustable date from the mentioned fields in the csv row.static Optional<AdjustablePayment>
tryParseAdjustablePayment(CsvRow row, String currencyField, String amountField, String directionField, String dateField)
Tries parsing an adjustable payment, defaulting the AdjustableDate to no BusinessDayAdjustment.static Optional<AdjustablePayment>
tryParseAdjustablePayment(CsvRow row, String currencyField, String amountField, String directionField, String dateField, String conventionField, String calendarField)
Tries parsing an adjustable payment using the mentioned fields.static Optional<CurrencyAmount>
tryParseCurrencyAmountWithDirection(CsvRow row, String currencyField, String amountField, String directionField)
Tries parsing a currency amount from the mentioned fields in the csv row.static Optional<AdjustablePayment>
tryParsePremiumFromDefaultFields(CsvRow row)
Tries parsing the premium using the default premium fields.
-
-
-
Field Detail
-
SECURITY_ID_SCHEME_FIELD
@Deprecated public static final String SECURITY_ID_SCHEME_FIELD
Deprecated.UseCsvLoaderColumns
.The column name for the security ID scheme/symbology.- See Also:
- Constant Field Values
-
SECURITY_ID_FIELD
@Deprecated public static final String SECURITY_ID_FIELD
Deprecated.UseCsvLoaderColumns
.The column name for the security ID.- See Also:
- Constant Field Values
-
EXCHANGE_FIELD
@Deprecated public static final String EXCHANGE_FIELD
Deprecated.UseCsvLoaderColumns
.The column name for the exchange.- See Also:
- Constant Field Values
-
CONTRACT_CODE_FIELD
@Deprecated public static final String CONTRACT_CODE_FIELD
Deprecated.UseCsvLoaderColumns
.The column name for the contract code.- See Also:
- Constant Field Values
-
LONG_QUANTITY_FIELD
@Deprecated public static final String LONG_QUANTITY_FIELD
Deprecated.UseCsvLoaderColumns
.The column name for the long quantity.- See Also:
- Constant Field Values
-
SHORT_QUANTITY_FIELD
@Deprecated public static final String SHORT_QUANTITY_FIELD
Deprecated.UseCsvLoaderColumns
.The column name for the short quantity.- See Also:
- Constant Field Values
-
QUANTITY_FIELD
@Deprecated public static final String QUANTITY_FIELD
Deprecated.UseCsvLoaderColumns
.The column name for the quantity.- See Also:
- Constant Field Values
-
PRICE_FIELD
@Deprecated public static final String PRICE_FIELD
Deprecated.UseCsvLoaderColumns
.The column name for the price.- See Also:
- Constant Field Values
-
EXPIRY_FIELD
@Deprecated public static final String EXPIRY_FIELD
Deprecated.UseCsvLoaderColumns
.The column name for the expiry month/year.- See Also:
- Constant Field Values
-
EXPIRY_WEEK_FIELD
@Deprecated public static final String EXPIRY_WEEK_FIELD
Deprecated.UseCsvLoaderColumns
.The column name for the expiry week.- See Also:
- Constant Field Values
-
EXPIRY_DAY_FIELD
@Deprecated public static final String EXPIRY_DAY_FIELD
Deprecated.UseCsvLoaderColumns
.The column name for the expiry day.- See Also:
- Constant Field Values
-
SETTLEMENT_TYPE_FIELD
@Deprecated public static final String SETTLEMENT_TYPE_FIELD
Deprecated.UseCsvLoaderColumns
.The column name for the settlement type.- See Also:
- Constant Field Values
-
EXERCISE_STYLE_FIELD
@Deprecated public static final String EXERCISE_STYLE_FIELD
Deprecated.UseCsvLoaderColumns
.The column name for the exercise style.- See Also:
- Constant Field Values
-
VERSION_FIELD
@Deprecated public static final String VERSION_FIELD
Deprecated.UseCsvLoaderColumns
.The column name for the option version.- See Also:
- Constant Field Values
-
PUT_CALL_FIELD
@Deprecated public static final String PUT_CALL_FIELD
Deprecated.UseCsvLoaderColumns
.The column name for the put/call flag.- See Also:
- Constant Field Values
-
EXERCISE_PRICE_FIELD
@Deprecated public static final String EXERCISE_PRICE_FIELD
Deprecated.UseCsvLoaderColumns
.The column name for the option strike price.- See Also:
- Constant Field Values
-
UNDERLYING_EXPIRY_FIELD
@Deprecated public static final String UNDERLYING_EXPIRY_FIELD
Deprecated.UseCsvLoaderColumns
.The column name for the underlying expiry month/year.- See Also:
- Constant Field Values
-
CURRENCY
@Deprecated public static final String CURRENCY
Deprecated.UseCsvLoaderColumns
.The column name for the currency.- See Also:
- Constant Field Values
-
TICK_SIZE
@Deprecated public static final String TICK_SIZE
Deprecated.UseCsvLoaderColumns
.The column name for the tick size.- See Also:
- Constant Field Values
-
TICK_VALUE
@Deprecated public static final String TICK_VALUE
Deprecated.UseCsvLoaderColumns
.The column name for the tick value.- See Also:
- Constant Field Values
-
CONTRACT_SIZE
@Deprecated public static final String CONTRACT_SIZE
Deprecated.UseCsvLoaderColumns
.The column name for the contract size.- See Also:
- Constant Field Values
-
DEFAULT_OPTION_VERSION_NUMBER
public static final int DEFAULT_OPTION_VERSION_NUMBER
Default version used as an option might not specify a version number.- See Also:
- Constant Field Values
-
SETTLEMENT_BY_CODE
public static final ImmutableMap<String,EtdSettlementType> SETTLEMENT_BY_CODE
Lookup settlement by code.
-
-
Method Detail
-
parseEtdVariant
public static Pair<YearMonth,EtdVariant> parseEtdVariant(CsvRow row, EtdType type)
Parses the year-month and variant.- Parameters:
row
- the CSV row to parsetype
- the ETD type- Returns:
- the expiry year-month and variant
- Throws:
ParseFailureException
- if the row cannot be parsed
-
parseEtdSettlementType
public static EtdSettlementType parseEtdSettlementType(String str)
Parses the ETD settlement type from the short code or full name.- Parameters:
str
- the string to parse- Returns:
- the settlement type
- Throws:
ParseFailureException
- if the string cannot be parsed
-
parseEtdOptionType
public static EtdOptionType parseEtdOptionType(String str)
Parses the ETD option type from the short code or full name.- Parameters:
str
- the string to parse- Returns:
- the option type
- Throws:
ParseFailureException
- if the string cannot be parsed
-
parseQuantity
public static DoublesPair parseQuantity(CsvRow row)
Parses the quantity.- Parameters:
row
- the CSV row to parse- Returns:
- the quantity, long first, short second
- Throws:
ParseFailureException
- if the row cannot be parsed
-
parseZonedDateTime
public static ZonedDateTime parseZonedDateTime(CsvRow row, String dateField, String timeField, String zoneField)
Parse a ZonedDateTime from the provided fields.- Parameters:
row
- the CSV rowdateField
- the date fieldtimeField
- the time fieldzoneField
- the zone field- Returns:
- the zoned date time
- Throws:
ParseFailureException
- if the row cannot be parsed
-
parseAdjustableDate
public static AdjustableDate parseAdjustableDate(CsvRow row, String dateField, String conventionField, String calendarField)
Parses a business day adjustment, without defaulting the adjustment.- Parameters:
row
- the CSV row to parsedateField
- the date fieldconventionField
- the convention fieldcalendarField
- the calendar field- Returns:
- the adjustment
- Throws:
ParseFailureException
- if the row cannot be parsed
-
parseAdjustableDate
public static AdjustableDate parseAdjustableDate(CsvRow row, String dateField, String conventionField, String calendarField, BusinessDayConvention defaultConvention, Currency currency)
Parses a business day adjustment, defaulting the adjustment using the currency.- Parameters:
row
- the CSV row to parsedateField
- the date fieldconventionField
- the convention fieldcalendarField
- the calendar fielddefaultConvention
- the default conventioncurrency
- the applicable currency, used for defaulting- Returns:
- the adjustment
- Throws:
ParseFailureException
- if the row cannot be parsed
-
parseAdjustablePayment
public static AdjustablePayment parseAdjustablePayment(CsvRow row, String currencyField, String amountField, String directionField, String dateField, String conventionField, String calendarField)
Parses an adjustable payment.- Parameters:
row
- the CSV row to parsecurrencyField
- the currency fieldamountField
- the amount fielddirectionField
- the direction fielddateField
- the date fieldconventionField
- the convention fieldcalendarField
- the calendar field- Returns:
- the adjustable payment
- Throws:
ParseFailureException
- if the row cannot be parsed
-
parseBarrier
public static Barrier parseBarrier(CsvRow row, String barrierTypeField, String knockTypeField, String barrierLevelField)
Parses a barrier from the csv row.- Parameters:
row
- the CSV row to parsebarrierTypeField
- the barrier type fieldknockTypeField
- the knock type fieldbarrierLevelField
- the barrier level field- Returns:
- the barrier
- Throws:
ParseFailureException
- if the row cannot be parsed
-
parseBarrierFromDefaultFields
public static Barrier parseBarrierFromDefaultFields(CsvRow row)
Parses a barrier using the default barrier fields.- Parameters:
row
- the CSV row to parse- Returns:
- the barrier
- Throws:
ParseFailureException
- if the row cannot be parsed
-
parsePremiumFromDefaultFields
public static AdjustablePayment parsePremiumFromDefaultFields(CsvRow row)
Parses the premium using the default premium fields.- Parameters:
row
- the CSV row to parse- Returns:
- the adjustable payment
- Throws:
ParseFailureException
- if the row cannot be parsed
-
parseBusinessDayAdjustment
public static Optional<BusinessDayAdjustment> parseBusinessDayAdjustment(CsvRow row, String conventionField, String calendarField)
Parses a business day adjustment.- Parameters:
row
- the CSV row to parseconventionField
- the convention fieldcalendarField
- the calendar field- Returns:
- the adjustment
- Throws:
ParseFailureException
- if the row cannot be parsed
-
parseDaysAdjustment
public static DaysAdjustment parseDaysAdjustment(CsvRow row, String daysField, String daysCalField, String cnvField, String calField)
Parses days adjustment from CSV.- Parameters:
row
- the CSV row to parsedaysField
- the days fielddaysCalField
- the days calendar fieldcnvField
- the convention fieldcalField
- the calendar field- Returns:
- the adjustment
- Throws:
ParseFailureException
- if the row cannot be parsed
-
parseCurrencyAmount
public static CurrencyAmount parseCurrencyAmount(CsvRow row, String currencyField, String amountField)
Parses a currency amount.- Parameters:
row
- the CSV row to parsecurrencyField
- the currency fieldamountField
- the amount field- Returns:
- the currency amount
- Throws:
ParseFailureException
- if the row cannot be parsed
-
parseCurrencyAmountWithDirection
public static CurrencyAmount parseCurrencyAmountWithDirection(CsvRow row, String currencyField, String amountField, String directionField)
Parses a currency amount with direction.- Parameters:
row
- the CSV row to parsecurrencyField
- the currency fieldamountField
- the amount fielddirectionField
- the direction field- Returns:
- the currency amount
- Throws:
ParseFailureException
- if the row cannot be parsed
-
tryParseAdjustableDate
public static Optional<AdjustableDate> tryParseAdjustableDate(CsvRow row, String dateField, String conventionField, String calendarField)
Tries parsing an adjustable date from the mentioned fields in the csv row.- Parameters:
row
- the CSV row to parsedateField
- the date fieldconventionField
- the convention fieldcalendarField
- the calendar field- Returns:
- the adjustable date option
-
tryParseCurrencyAmountWithDirection
public static Optional<CurrencyAmount> tryParseCurrencyAmountWithDirection(CsvRow row, String currencyField, String amountField, String directionField)
Tries parsing a currency amount from the mentioned fields in the csv row.- Parameters:
row
- the CSV row to parsecurrencyField
- the currency fieldamountField
- the amount fielddirectionField
- the direction field- Returns:
- the currency amount option
-
tryParsePremiumFromDefaultFields
public static Optional<AdjustablePayment> tryParsePremiumFromDefaultFields(CsvRow row)
Tries parsing the premium using the default premium fields.- Parameters:
row
- the CSV row to parse- Returns:
- the premium option
-
tryParseAdjustablePayment
public static Optional<AdjustablePayment> tryParseAdjustablePayment(CsvRow row, String currencyField, String amountField, String directionField, String dateField)
Tries parsing an adjustable payment, defaulting the AdjustableDate to no BusinessDayAdjustment.- Parameters:
row
- the CSV row to parsecurrencyField
- the currency fieldamountField
- the amount fielddirectionField
- the direction fielddateField
- the date field- Returns:
- the adjustable payment option
-
tryParseAdjustablePayment
public static Optional<AdjustablePayment> tryParseAdjustablePayment(CsvRow row, String currencyField, String amountField, String directionField, String dateField, String conventionField, String calendarField)
Tries parsing an adjustable payment using the mentioned fields.Defaults to
tryParseAdjustablePayment(CsvRow,String,String,String,String)
if the adjustable date parsing fails as it is often due to a missing calendar or convention.- Parameters:
row
- the CSV row to parsecurrencyField
- the currency fieldamountField
- the amount fielddirectionField
- the direction fielddateField
- the date fieldconventionField
- the date convention fieldcalendarField
- the date calendar field- Returns:
- the adjustable payment option
-
formattedPercentage
public static String formattedPercentage(double value)
Returns a value formatted as a percentage.Using this method avoids nasty effects from floating point arithmetic.
- Parameters:
value
- the value in decimal format (to be multiplied by 100)- Returns:
- the formatted percentage value
-
formattedDouble
public static String formattedDouble(double value)
Returns a value formatted as a double.Using this method avoids nasty effects from floating point arithmetic.
- Parameters:
value
- the value- Returns:
- the formatted value
-
-