public void test_parseYearMonth() { assertEquals(LoaderUtils.parseYearMonth("2012-06"), YearMonth.of(2012, 6)); assertEquals(LoaderUtils.parseYearMonth("201206"), YearMonth.of(2012, 6)); assertEquals(LoaderUtils.parseYearMonth("Jun-2012"), YearMonth.of(2012, 6)); assertEquals(LoaderUtils.parseYearMonth("Jun-12"), YearMonth.of(2012, 6)); assertEquals(LoaderUtils.parseYearMonth("Jun2012"), YearMonth.of(2012, 6)); assertEquals(LoaderUtils.parseYearMonth("Jun12"), YearMonth.of(2012, 6)); assertEquals(LoaderUtils.parseYearMonth("1/6/2012"), YearMonth.of(2012, 6)); assertEquals(LoaderUtils.parseYearMonth("01/6/2012"), YearMonth.of(2012, 6)); assertEquals(LoaderUtils.parseYearMonth("1/06/2012"), YearMonth.of(2012, 6)); assertEquals(LoaderUtils.parseYearMonth("01/06/2012"), YearMonth.of(2012, 6)); assertThrowsIllegalArg(() -> LoaderUtils.parseYearMonth("2/6/2012")); assertThrowsIllegalArg(() -> LoaderUtils.parseYearMonth("1/6/12")); assertThrowsIllegalArg(() -> LoaderUtils.parseYearMonth("Jun1")); assertThrowsIllegalArg(() -> LoaderUtils.parseYearMonth("12345678")); assertThrowsIllegalArg(() -> LoaderUtils.parseYearMonth("Rubbish")); }
YearMonth yearMonth = LoaderUtils.parseYearMonth(row.getValue(EXPIRY_FIELD)); int week = row.findValue(EXPIRY_WEEK_FIELD).map(s -> LoaderUtils.parseInteger(s)).orElse(0); int day = row.findValue(EXPIRY_DAY_FIELD).map(s -> LoaderUtils.parseInteger(s)).orElse(0);
/** * Parses an ETD future position from the CSV row. * <p> * This is intended to use reference data to find the ETD future security, * returning it as an instance of {@link EtdOptionPosition}. * The reference data lookup uses {@link #parseEtdContractSpec(CsvRow, EtdType)} by default, * however it could be overridden to lookup the security directly in reference data. * * @param row the CSV row * @param info the position info * @return the parsed position * @throws IllegalArgumentException if the row cannot be parsed */ public default Position parseEtdOptionPosition(CsvRow row, PositionInfo info) { EtdContractSpec contract = parseEtdContractSpec(row, EtdType.OPTION); Pair<YearMonth, EtdVariant> variant = CsvLoaderUtils.parseEtdVariant(row, EtdType.OPTION); int version = row.findValue(VERSION_FIELD).map(Integer::parseInt).orElse(DEFAULT_OPTION_VERSION_NUMBER); PutCall putCall = LoaderUtils.parsePutCall(row.getValue(PUT_CALL_FIELD)); double strikePrice = Double.parseDouble(row.getValue(EXERCISE_PRICE_FIELD)); YearMonth underlyingExpiry = row.findValue(UNDERLYING_EXPIRY_FIELD) .map(str -> LoaderUtils.parseYearMonth(str)) .orElse(null); EtdOptionSecurity security = contract.createOption( variant.getFirst(), variant.getSecond(), version, putCall, strikePrice, underlyingExpiry); DoublesPair quantity = CsvLoaderUtils.parseQuantity(row); EtdOptionPosition position = EtdOptionPosition.ofLongShort(info, security, quantity.getFirst(), quantity.getSecond()); return completePosition(row, position, contract); }
/** * Parses an ETD option position from the CSV row without using reference data. * <p> * This returns a {@link SecurityPosition} based on a standard ETD identifier from {@link EtdIdUtils}. * * @param row the CSV row to parse * @param info the position information * @return the loaded positions, position-level errors are captured in the result * @throws IllegalArgumentException if the row cannot be parsed */ public default SecurityPosition parseEtdOptionSecurityPosition(CsvRow row, PositionInfo info) { ExchangeId exchangeId = ExchangeId.of(row.getValue(EXCHANGE_FIELD)); EtdContractCode contractCode = EtdContractCode.of(row.getValue(CONTRACT_CODE_FIELD)); Pair<YearMonth, EtdVariant> variant = CsvLoaderUtils.parseEtdVariant(row, EtdType.OPTION); int version = row.findValue(VERSION_FIELD).map(Integer::parseInt).orElse(DEFAULT_OPTION_VERSION_NUMBER); PutCall putCall = LoaderUtils.parsePutCall(row.getValue(PUT_CALL_FIELD)); double strikePrice = Double.parseDouble(row.getValue(EXERCISE_PRICE_FIELD)); YearMonth underlyingExpiry = row.findValue(UNDERLYING_EXPIRY_FIELD) .map(str -> LoaderUtils.parseYearMonth(str)) .orElse(null); SecurityId securityId = EtdIdUtils.optionId( exchangeId, contractCode, variant.getFirst(), variant.getSecond(), version, putCall, strikePrice, underlyingExpiry); DoublesPair quantity = CsvLoaderUtils.parseQuantity(row); SecurityPosition position = SecurityPosition.ofLongShort(info, securityId, quantity.getFirst(), quantity.getSecond()); return completePosition(row, position); }
if (index instanceof PriceIndex) { try { YearMonth ym = LoaderUtils.parseYearMonth(dateStr); date = ym.atEndOfMonth(); } catch (RuntimeException ex) {