/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(EtdOptionSecurity beanToCopy) { this.info = beanToCopy.getInfo(); this.contractSpecId = beanToCopy.getContractSpecId(); this.expiry = beanToCopy.getExpiry(); this.variant = beanToCopy.getVariant(); this.version = beanToCopy.getVersion(); this.putCall = beanToCopy.getPutCall(); this.strikePrice = beanToCopy.getStrikePrice(); this.underlyingExpiryMonth = beanToCopy.underlyingExpiryMonth; }
/** * Gets the currency of the trade. * <p> * This is typically the same as the currency of the product. * * @return the trading currency */ public Currency getCurrency() { return security.getCurrency(); }
@Override public SecurityId getSecurityId() { return security.getSecurityId(); }
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 test() { EtdOptionSecurity test = sut(); assertEquals(test.getVariant(), EtdVariant.MONTHLY); assertEquals(test.getType(), EtdType.OPTION); assertEquals(test.getCurrency(), Currency.GBP); assertEquals(test.getUnderlyingIds(), ImmutableSet.of()); assertEquals(test.createProduct(REF_DATA), test); assertEquals( test.createTrade(TradeInfo.empty(), 1, 2, ReferenceData.empty()), EtdOptionTrade.of(TradeInfo.empty(), test, 1, 2)); assertEquals( test.createPosition(PositionInfo.empty(), 1, ReferenceData.empty()), EtdOptionPosition.ofNet(PositionInfo.empty(), test, 1)); assertEquals( test.createPosition(PositionInfo.empty(), 1, 2, ReferenceData.empty()), EtdOptionPosition.ofLongShort(PositionInfo.empty(), test, 1, 2)); }
public void test_of() { EtdOptionTrade test = EtdOptionTrade.of(TRADE_INFO, SECURITY, 1000, 20); assertEquals(test.getSecurity(), SECURITY); assertEquals(test.getQuantity(), 1000d, 0d); assertEquals(test.getPrice(), 20d, 0d); assertEquals(test.getSecurityId(), SECURITY.getSecurityId()); assertEquals(test.getCurrency(), SECURITY.getCurrency()); assertEquals(test.withInfo(TRADE_INFO).getInfo(), TRADE_INFO); assertEquals(test.withQuantity(129).getQuantity(), 129d, 0d); assertEquals(test.withPrice(129).getPrice(), 129d, 0d); }
public void test_resolveTarget() { GenericSecurity security = GenericSecurity.of(SECURITY.getInfo()); Trade test = sut().resolveTarget(ImmutableReferenceData.of(SECURITY.getSecurityId(), security)); GenericSecurityTrade expected = GenericSecurityTrade.of(TRADE_INFO, security, 3000, 20); assertEquals(test, expected); }
/** * Creates an option security based on this contract specification. * <p> * The security identifier will be automatically created using {@link EtdIdUtils}. * The {@link #getType() type} must be {@link EtdType#OPTION} otherwise an exception will be thrown. * * @param expiryMonth the expiry month of the option * @param variant the variant of the ETD, such as 'Monthly', 'Weekly, 'Daily' or 'Flex' * @param version the non-negative version, zero by default * @param putCall whether the option is a put or call * @param strikePrice the strike price of the option * @return an option security based on this contract specification * @throws IllegalStateException if the product type of the contract specification is not {@code OPTION} */ public EtdOptionSecurity createOption( YearMonth expiryMonth, EtdVariant variant, int version, PutCall putCall, double strikePrice) { return EtdOptionSecurity.of(this, expiryMonth, variant, version, putCall, strikePrice); }
static EtdOptionSecurity sut() { return EtdOptionSecurity.builder() .info(SecurityInfo.of(SecurityId.of("A", "B"), SecurityPriceInfo.of(Currency.GBP, 100))) .contractSpecId(EtdContractSpecId.of("test", "123")) .expiry(YearMonth.of(2017, 6)) .putCall(PutCall.PUT) .strikePrice(2) .build(); }
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()); }
public void test_summarize() { EtdOptionTrade trade = sut(); PortfolioItemSummary expected = PortfolioItemSummary.builder() .portfolioItemType(PortfolioItemType.TRADE) .productType(ProductType.ETD_OPTION) .currencies(SECURITY.getCurrency()) .description(SECURITY.getSecurityId().getStandardId().getValue() + " x 3000, Jun17 P2") .build(); assertEquals(trade.summarize(), expected); }
public void test_resolveTarget() { EtdOptionPosition position = sut(); GenericSecurity resolvedSecurity = GenericSecurity.of(SECURITY.getInfo()); ImmutableReferenceData refData = ImmutableReferenceData.of(SECURITY.getSecurityId(), resolvedSecurity); GenericSecurityPosition expected = GenericSecurityPosition.ofLongShort(POSITION_INFO, resolvedSecurity, LONG_QUANTITY, SHORT_QUANTITY); assertEquals(position.resolveTarget(refData), expected); }
/** * Obtains an instance from a contract specification, expiry year-month, variant, version, put/call and strike price. * <p> * The security identifier will be automatically created using {@link EtdIdUtils}. * The specification must be for an option. * * @param spec the option contract specification * @param expiry the expiry year-month of the option * @param variant the variant of the ETD, such as 'Monthly', 'Weekly, 'Daily' or 'Flex' * @param version the non-negative version, zero if versioning does not apply * @param putCall whether the option is a put or call * @param strikePrice the strike price of the option * @return an option security based on this contract specification * @throws IllegalStateException if the product type of the contract specification is not {@code OPTION} */ public static EtdOptionSecurity of( EtdContractSpec spec, YearMonth expiry, EtdVariant variant, int version, PutCall putCall, double strikePrice) { return of(spec, expiry, variant, version, putCall, strikePrice, null); }
static EtdOptionSecurity sut2() { return EtdOptionSecurity.builder() .info(SecurityInfo.of(SecurityId.of("B", "C"), SecurityPriceInfo.of(Currency.EUR, 10))) .contractSpecId(EtdContractSpecId.of("test", "234")) .expiry(YearMonth.of(2017, 9)) .variant(EtdVariant.ofWeekly(2)) .version(4) .putCall(PutCall.CALL) .strikePrice(3) .underlyingExpiryMonth(YearMonth.of(2017, 12)) .build(); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 3237038: // info return ((EtdOptionSecurity) bean).getInfo(); case 948987368: // contractSpecId return ((EtdOptionSecurity) bean).getContractSpecId(); case -1289159373: // expiry return ((EtdOptionSecurity) bean).getExpiry(); case 236785797: // variant return ((EtdOptionSecurity) bean).getVariant(); case 351608024: // version return ((EtdOptionSecurity) bean).getVersion(); case -219971059: // putCall return ((EtdOptionSecurity) bean).getPutCall(); case 50946231: // strikePrice return ((EtdOptionSecurity) bean).getStrikePrice(); case 1929351536: // underlyingExpiryMonth return ((EtdOptionSecurity) bean).underlyingExpiryMonth; } return super.propertyGet(bean, propertyName, quiet); }
public void test_summarize() { EtdOptionPosition trade = sut(); PortfolioItemSummary expected = PortfolioItemSummary.builder() .id(POSITION_INFO.getId().orElse(null)) .portfolioItemType(PortfolioItemType.POSITION) .productType(ProductType.ETD_OPTION) .currencies(SECURITY.getCurrency()) .description(SECURITY.getSecurityId().getStandardId().getValue() + " x 1000, Jun17 P2") .build(); assertEquals(trade.summarize(), expected); }
/** * Creates an option security based on this contract specification. * <p> * The security identifier will be automatically created using {@link EtdIdUtils}. * The {@link #getType() type} must be {@link EtdType#OPTION} otherwise an exception will be thrown. * * @param expiryMonth the expiry month of the option * @param variant the variant of the ETD, such as 'Monthly', 'Weekly, 'Daily' or 'Flex' * @param version the non-negative version, zero by default * @param putCall whether the option is a put or call * @param strikePrice the strike price of the option * @param underlyingExpiryMonth the expiry of the underlying instrument, such as a future * @return an option security based on this contract specification * @throws IllegalStateException if the product type of the contract specification is not {@code OPTION} */ public EtdOptionSecurity createOption( YearMonth expiryMonth, EtdVariant variant, int version, PutCall putCall, double strikePrice, YearMonth underlyingExpiryMonth) { return EtdOptionSecurity.of(this, expiryMonth, variant, version, putCall, strikePrice, underlyingExpiryMonth); }
return EtdOptionSecurity.builder() .info(SecurityInfo.of(securityId, spec.getPriceInfo())) .contractSpecId(spec.getId())
public void test_methods() { EtdOptionPosition test = sut(); assertEquals(test.getType(), EtdType.OPTION); assertEquals(test.getCurrency(), Currency.GBP); assertEquals(test.getSecurityId(), test.getSecurity().getSecurityId()); assertEquals(test.getQuantity(), 1000d, 0d); }
.id(StandardId.of("OG", "123431")) .build()) .security(EtdOptionSecurity.of( contract, YearMonth.of(2017, 6), EtdVariant.ofMonthly(), 0, PutCall.PUT, 3d, YearMonth.of(2017, 9))) .longQuantity(15d) .id(StandardId.of("OG", "123432")) .build()) .security(EtdOptionSecurity.of( contract, YearMonth.of(2017, 6), .id(StandardId.of("OG", "123433")) .build()) .security(EtdOptionSecurity.of(contract, YearMonth.of(2017, 6), EtdVariant.ofWeekly(2), 0, PutCall.PUT, 5.1d)) .longQuantity(0d) .shortQuantity(20d)