public void createFutureFromOptionContractSpec() { assertThatThrownBy(() -> OPTION_CONTRACT.createFuture(YearMonth.of(2015, 6), EtdVariant.MONTHLY)) .isInstanceOf(IllegalStateException.class) .hasMessage("Cannot create an EtdFutureSecurity from a contract specification of type 'Option'"); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 3355: // id return ((EtdContractSpec) bean).getId(); case 3575610: // type return ((EtdContractSpec) bean).getType(); case 913218206: // exchangeId return ((EtdContractSpec) bean).getExchangeId(); case -1402840545: // contractCode return ((EtdContractSpec) bean).getContractCode(); case -1724546052: // description return ((EtdContractSpec) bean).getDescription(); case -2126070377: // priceInfo return ((EtdContractSpec) bean).getPriceInfo(); case 405645655: // attributes return ((EtdContractSpec) bean).getAttributes(); } return super.propertyGet(bean, propertyName, quiet); }
@Override public EtdContractSpec build() { return new EtdContractSpec( id, type, exchangeId, contractCode, description, priceInfo, attributes); }
/** * Obtains an instance from a contract specification, expiry year-month and variant. * <p> * The security identifier will be automatically created using {@link EtdIdUtils}. * The specification must be for a future. * * @param spec the future contract specification * @param expiry the expiry year-month of the future * @param variant the variant of the ETD, such as 'Monthly', 'Weekly, 'Daily' or 'Flex' * @return a future security based on this contract specification * @throws IllegalStateException if the product type of the contract specification is not {@code FUTURE} */ public static EtdFutureSecurity of(EtdContractSpec spec, YearMonth expiry, EtdVariant variant) { if (spec.getType() != EtdType.FUTURE) { throw new IllegalStateException( Messages.format("Cannot create an EtdFutureSecurity from a contract specification of type '{}'", spec.getType())); } SecurityId securityId = EtdIdUtils.futureId(spec.getExchangeId(), spec.getContractCode(), expiry, variant); return EtdFutureSecurity.builder() .info(SecurityInfo.of(securityId, spec.getPriceInfo())) .contractSpecId(spec.getId()) .expiry(expiry) .variant(variant) .build(); }
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 createFutureAutoId() { EtdFutureSecurity security = FUTURE_CONTRACT.createFuture(YearMonth.of(2015, 6), EtdVariant.MONTHLY); assertThat(security.getSecurityId()).isEqualTo(SecurityId.of(EtdIdUtils.ETD_SCHEME, "F-ECAG-FOO-201506")); assertThat(security.getExpiry()).isEqualTo(YearMonth.of(2015, 6)); assertThat(security.getContractSpecId()).isEqualTo(FUTURE_CONTRACT.getId()); assertThat(security.getVariant()).isEqualTo(EtdVariant.MONTHLY); assertThat(security.getInfo().getPriceInfo()).isEqualTo(FUTURE_CONTRACT.getPriceInfo()); }
public void test_load_invalidNoQuantity() { EtdContractSpecId specId = EtdContractSpecId.of("OG-ETD", "F-ECAG-FGBL"); EtdContractSpec contract = EtdContractSpec.builder() .id(specId) .type(EtdType.FUTURE) .exchangeId(ExchangeIds.ECAG) .contractCode(FGBL) .description("Dummy") .priceInfo(SecurityPriceInfo.of(Currency.GBP, 100)) .build(); ReferenceData refData = ImmutableReferenceData.of(specId, contract); PositionCsvLoader test = PositionCsvLoader.of(refData); ValueWithFailures<List<Position>> trades = test.parse( ImmutableList.of(CharSource.wrap("Strata Position Type,Exchange,Contract Code,Expiry\nFUT,ECAG,FGBL,2017-06"))); assertEquals(trades.getFailures().size(), 1); FailureItem failure = trades.getFailures().get(0); assertEquals(failure.getReason(), FailureReason.PARSING); assertEquals(failure.getMessage(), "CSV file position could not be parsed at line 2: " + "Security must contain a quantity column, either 'Quantity' or 'Long Quantity' and 'Short Quantity'"); }
public void test_attributes() { assertEquals(sut2().getAttribute(AttributeType.NAME), "NAME"); assertEquals(sut2().findAttribute(AttributeType.NAME).get(), "NAME"); assertThrows(IllegalArgumentException.class, () -> sut2().getAttribute(AttributeType.of("Foo"))); EtdContractSpec updated = sut2().withAttribute(AttributeType.NAME, "FOO"); assertEquals(updated.getAttribute(AttributeType.NAME), "FOO"); }
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'"); }
YearMonth underlyingExpiryMonth) { if (spec.getType() != EtdType.OPTION) { throw new IllegalStateException( Messages.format("Cannot create an EtdOptionSecurity from a contract specification of type '{}'", spec.getType())); spec.getExchangeId(), spec.getContractCode(), expiry, variant, version, putCall, strikePrice, underlyingExpiryMonth); return EtdOptionSecurity.builder() .info(SecurityInfo.of(securityId, spec.getPriceInfo())) .contractSpecId(spec.getId()) .expiry(expiry) .variant(variant)
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()); }
static EtdContractSpec sut2() { return EtdContractSpec.builder() .type(EtdType.OPTION) .exchangeId(ExchangeIds.IFEN) .contractCode(EtdContractCode.of("BAR")) .description("A test option template") .priceInfo(SecurityPriceInfo.of(Currency.EUR, 10)) .addAttribute(AttributeType.NAME, "NAME") .build(); }
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'"); }
static EtdContractSpec sut() { return EtdContractSpec.builder() .id(EtdContractSpecId.of("test", "123")) .type(EtdType.FUTURE) .exchangeId(ExchangeIds.ECAG) .contractCode(EtdContractCode.of("FOO")) .description("A test future template") .priceInfo(SecurityPriceInfo.of(Currency.GBP, 100)) .build(); }
/** * 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 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 EtdFuturePosition}. * 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 to parse * @param info the position information * @return the parsed position * @throws IllegalArgumentException if the row cannot be parsed */ public default Position parseEtdFuturePosition(CsvRow row, PositionInfo info) { EtdContractSpec contract = parseEtdContractSpec(row, EtdType.FUTURE); Pair<YearMonth, EtdVariant> variant = CsvLoaderUtils.parseEtdVariant(row, EtdType.FUTURE); EtdFutureSecurity security = contract.createFuture(variant.getFirst(), variant.getSecond()); DoublesPair quantity = CsvLoaderUtils.parseQuantity(row); EtdFuturePosition position = EtdFuturePosition.ofLongShort(info, security, quantity.getFirst(), quantity.getSecond()); return completePosition(row, position, contract); }
@Override public <T> EtdContractSpec withAttribute(AttributeType<T> type, T value) { // ImmutableMap.Builder would not provide Map.put semantics Map<AttributeType<?>, Object> updatedAttributes = new HashMap<>(attributes); updatedAttributes.put(type, value); return new EtdContractSpec(id, this.type, exchangeId, contractCode, description, priceInfo, updatedAttributes); }
public void test_parse_option() { EtdContractSpecId specId = EtdContractSpecId.of("OG-ETD", "O-ECAG-OGBL"); EtdContractSpec contract = EtdContractSpec.builder() .id(specId) .type(EtdType.OPTION)
/** * Builds a new specification from the data in this builder. * * @return a specification instance built from the data in this builder */ public EtdContractSpec build() { if (id == null) { id = EtdIdUtils.contractSpecId(type, exchangeId, contractCode); } return new EtdContractSpec(id, type, exchangeId, contractCode, description, priceInfo, attributes); }
public void test_parse_future() { EtdContractSpecId specId = EtdContractSpecId.of("OG-ETD", "F-ECAG-FGBL"); EtdContractSpec contract = EtdContractSpec.builder() .id(specId) .type(EtdType.FUTURE)