public void createOptionFromFutureContractSpec() { assertThatThrownBy( () -> FUTURE_CONTRACT.createOption(YearMonth.of(2015, 6), EtdVariant.MONTHLY, 0, PutCall.CALL, 123.45)) .isInstanceOf(IllegalStateException.class) .hasMessage("Cannot create an EtdOptionSecurity from a contract specification of type 'Future'"); }
public void createOptionWithUnderlyingFromFutureContractSpec() { assertThatThrownBy( () -> FUTURE_CONTRACT.createOption( YearMonth.of(2015, 6), EtdVariant.MONTHLY, 0, PutCall.CALL, 123.45, YearMonth.of(2015, 9))) .isInstanceOf(IllegalStateException.class) .hasMessage("Cannot create an EtdOptionSecurity from a contract specification of type 'Future'"); }
public void createOptionAutoId() { EtdOptionSecurity security = OPTION_CONTRACT.createOption(YearMonth.of(2015, 6), EtdVariant.MONTHLY, 0, PutCall.CALL, 123.45); assertThat(security.getSecurityId()).isEqualTo(SecurityId.of(EtdIdUtils.ETD_SCHEME, "O-IFEN-BAR-201506-C123.45")); assertThat(security.getExpiry()).isEqualTo(YearMonth.of(2015, 6)); assertThat(security.getContractSpecId()).isEqualTo(OPTION_CONTRACT.getId()); assertThat(security.getVariant()).isEqualTo(EtdVariant.MONTHLY); assertThat(security.getPutCall()).isEqualTo(PutCall.CALL); assertThat(security.getStrikePrice()).isEqualTo(123.45); assertThat(security.getUnderlyingExpiryMonth()).isEmpty(); assertThat(security.getInfo().getPriceInfo()).isEqualTo(OPTION_CONTRACT.getPriceInfo()); }
public void createOptionWithUnderlyingAutoId() { EtdOptionSecurity security = OPTION_CONTRACT.createOption( YearMonth.of(2015, 6), EtdVariant.MONTHLY, 0, PutCall.CALL, 123.45, YearMonth.of(2015, 9)); assertThat(security.getSecurityId()).isEqualTo(SecurityId.of(EtdIdUtils.ETD_SCHEME, "O-IFEN-BAR-201506-C123.45-U201509")); assertThat(security.getExpiry()).isEqualTo(YearMonth.of(2015, 6)); assertThat(security.getContractSpecId()).isEqualTo(OPTION_CONTRACT.getId()); assertThat(security.getVariant()).isEqualTo(EtdVariant.MONTHLY); assertThat(security.getPutCall()).isEqualTo(PutCall.CALL); assertThat(security.getStrikePrice()).isEqualTo(123.45); assertThat(security.getUnderlyingExpiryMonth()).hasValue(YearMonth.of(2015, 9)); assertThat(security.getInfo().getPriceInfo()).isEqualTo(OPTION_CONTRACT.getPriceInfo()); }
/** * 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); }