public void test_of_withAdditionalInfo() { SecurityInfo test = SecurityInfo.of(ID, PRICE_INFO) .withAttribute(AttributeType.NAME, "B") .withAttribute(AttributeType.NAME, "A"); // overwrites "B" assertEquals(test.getId(), ID); assertEquals(test.getPriceInfo(), PRICE_INFO); assertEquals(test.getAttributes(), INFO_MAP); assertEquals(test.getAttribute(AttributeType.NAME), "A"); assertEquals(test.findAttribute(AttributeType.NAME), Optional.of("A")); }
/** * Builds the security information. * * @return the security information */ public SecurityInfo build() { return new SecurityInfo(id, priceInfo, attributes); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 3355: // id return ((SecurityInfo) bean).getId(); case -2126070377: // priceInfo return ((SecurityInfo) bean).getPriceInfo(); case 405645655: // attributes return ((SecurityInfo) bean).getAttributes(); } return super.propertyGet(bean, propertyName, quiet); }
@Override public Set<String> tokens(Security security) { MetaBean metaBean = MetaBean.of(security.getClass()); return Sets.union( Sets.union(metaBean.metaPropertyMap().keySet(), security.getInfo().propertyNames()), security.getInfo().getPriceInfo().propertyNames()); }
public void test_serialization() { SecurityInfo test = SecurityInfo.of(ID, PRICE_INFO); assertSerialization(test); }
public void test_builder() { SecurityInfo test = SecurityInfo.builder() .id(ID) .priceInfo(PRICE_INFO) .addAttribute(AttributeType.NAME, "B") .addAttribute(AttributeType.NAME, "A") // overwrites "B" .build(); assertEquals(test.getId(), ID); assertEquals(test.getPriceInfo(), PRICE_INFO); assertEquals(test.getAttributes(), INFO_MAP); assertEquals(test.getAttribute(AttributeType.NAME), "A"); assertEquals(test.findAttribute(AttributeType.NAME), Optional.of("A")); }
static CapitalIndexedBondSecurity createSecurity(CapitalIndexedBond product) { return CapitalIndexedBondSecurity.builder() .info(SecurityInfo.of(product.getSecurityId(), INFO.getPriceInfo())) .currency(product.getCurrency()) .notional(product.getNotional()) .accrualSchedule(product.getAccrualSchedule()) .rateCalculation(product.getRateCalculation()) .dayCount(product.getDayCount()) .yieldConvention(product.getYieldConvention()) .legalEntityId(product.getLegalEntityId()) .settlementDateOffset(product.getSettlementDateOffset()) .exCouponPeriod(product.getExCouponPeriod()) .build(); }
public void coverage() { SecurityInfo test = SecurityInfo.of(ID, PRICE_INFO); coverImmutableBean(test); SecurityInfo test2 = SecurityInfo.of(ID2, PRICE_INFO2).withAttribute(AttributeType.NAME, "A"); coverBeanEquals(test, test2); }
/** * Gets the currency that the security is traded in. * * @return the trading currency */ public default Currency getCurrency() { return getInfo().getPriceInfo().getCurrency(); }
public void test_toBuilder() { SecurityInfo test = SecurityInfo.builder() .addAttribute(AttributeType.NAME, "name") .id(ID) .priceInfo(PRICE_INFO) .build() .toBuilder() .id(ID2) .build(); assertEquals(test.getId(), ID2); assertEquals(test.getAttribute(AttributeType.NAME), "name"); }
Optional<String> securityInfoPropertyName = security.getInfo().propertyNames().stream() .filter(p -> p.equalsIgnoreCase(firstToken)) .findFirst(); if (securityInfoPropertyName.isPresent()) { Object propertyValue = security.getInfo().property(securityInfoPropertyName.get()).get(); return propertyValue != null ? EvaluationResult.success(propertyValue, remainingTokens) : Optional<String> securityPriceInfoPropertyName = security.getInfo().getPriceInfo().propertyNames().stream() .filter(p -> p.equalsIgnoreCase(firstToken)) .findFirst(); if (securityPriceInfoPropertyName.isPresent()) { Object propertyValue = security.getInfo().getPriceInfo().property(securityPriceInfoPropertyName.get()).get(); return propertyValue != null ? EvaluationResult.success(propertyValue, remainingTokens) :
public void test_of() { GenericSecurity test = sut(); assertEquals(test.getInfo(), INFO); assertEquals(test.getSecurityId(), INFO.getId()); assertEquals(test.getCurrency(), INFO.getPriceInfo().getCurrency()); assertEquals(test.getUnderlyingIds(), ImmutableSet.of()); assertEquals(test, GenericSecurity.of(INFO)); assertEquals(test.createProduct(ReferenceData.empty()), test); assertEquals( test.createTrade(TradeInfo.empty(), 1, 2, ReferenceData.empty()), GenericSecurityTrade.of(TradeInfo.empty(), GenericSecurity.of(INFO), 1, 2)); assertEquals( test.createPosition(PositionInfo.empty(), 1, ReferenceData.empty()), GenericSecurityPosition.ofNet(PositionInfo.empty(), GenericSecurity.of(INFO), 1)); assertEquals( test.createPosition(PositionInfo.empty(), 1, 2, ReferenceData.empty()), GenericSecurityPosition.ofLongShort(PositionInfo.empty(), GenericSecurity.of(INFO), 1, 2)); }
/** * Gets the security identifier. * <p> * This identifier uniquely identifies the security within the system. * * @return the security identifier */ public default SecurityId getSecurityId() { return getInfo().getId(); }
/** * Gets the attribute associated with the specified type. * <p> * This method obtains the specified attribute. * This allows an attribute about a security to be obtained if available. * <p> * If the attribute is not found, an exception is thrown. * * @param <T> the type of the result * @param type the type to find * @return the attribute value * @throws IllegalArgumentException if the attribute is not found */ @Override public <T> T getAttribute(AttributeType<T> type) { return findAttribute(type).orElseThrow(() -> new IllegalArgumentException( Messages.format("Attribute not found for type '{}'", type))); }
static Position parseNonEtdPosition(CsvRow row, PositionInfo info, PositionCsvInfoResolver resolver) { SecurityPosition base = parseSecurityPosition(row, info, resolver); Optional<Double> tickSizeOpt = row.findValue(TICK_SIZE).map(str -> LoaderUtils.parseDouble(str)); Optional<Currency> currencyOpt = row.findValue(CURRENCY).map(str -> Currency.of(str)); Optional<Double> tickValueOpt = row.findValue(TICK_VALUE).map(str -> LoaderUtils.parseDouble(str)); double contractSize = row.findValue(CONTRACT_SIZE).map(str -> LoaderUtils.parseDouble(str)).orElse(1d); if (tickSizeOpt.isPresent() && currencyOpt.isPresent() && tickValueOpt.isPresent()) { SecurityPriceInfo priceInfo = SecurityPriceInfo.of(tickSizeOpt.get(), CurrencyAmount.of(currencyOpt.get(), tickValueOpt.get()), contractSize); GenericSecurity sec = GenericSecurity.of(SecurityInfo.of(base.getSecurityId(), priceInfo)); return GenericSecurityPosition.ofLongShort(base.getInfo(), sec, base.getLongQuantity(), base.getShortQuantity()); } return base; }
static FixedCouponBondSecurity createSecurity(FixedCouponBond product) { return FixedCouponBondSecurity.builder() .info(SecurityInfo.of(product.getSecurityId(), INFO.getPriceInfo())) .currency(product.getCurrency()) .notional(product.getNotional()) .accrualSchedule(product.getAccrualSchedule()) .fixedRate(product.getFixedRate()) .dayCount(product.getDayCount()) .yieldConvention(product.getYieldConvention()) .legalEntityId(product.getLegalEntityId()) .settlementDateOffset(product.getSettlementDateOffset()) .exCouponPeriod(product.getExCouponPeriod()) .build(); }
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_of_priceInfo() { SecurityInfo test = SecurityInfo.of(ID, PRICE_INFO); assertEquals(test.getId(), ID); assertEquals(test.getPriceInfo(), PRICE_INFO); assertEquals(test.getAttributes(), ImmutableMap.of()); assertThrowsIllegalArg(() -> test.getAttribute(AttributeType.NAME)); assertEquals(test.findAttribute(AttributeType.NAME), Optional.empty()); }
static SecurityQuantityTrade parseTrade(CsvRow row, TradeInfo info, TradeCsvInfoResolver resolver) { SecurityTrade trade = parseSecurityTrade(row, info, resolver); SecurityTrade base = resolver.completeTrade(row, trade); Optional<Double> tickSizeOpt = row.findValue(TICK_SIZE).map(str -> LoaderUtils.parseDouble(str)); Optional<Currency> currencyOpt = row.findValue(CURRENCY).map(str -> Currency.of(str)); Optional<Double> tickValueOpt = row.findValue(TICK_VALUE).map(str -> LoaderUtils.parseDouble(str)); double contractSize = row.findValue(CONTRACT_SIZE).map(str -> LoaderUtils.parseDouble(str)).orElse(1d); if (tickSizeOpt.isPresent() && currencyOpt.isPresent() && tickValueOpt.isPresent()) { SecurityPriceInfo priceInfo = SecurityPriceInfo.of(tickSizeOpt.get(), CurrencyAmount.of(currencyOpt.get(), tickValueOpt.get()), contractSize); GenericSecurity sec = GenericSecurity.of(SecurityInfo.of(base.getSecurityId(), priceInfo)); return GenericSecurityTrade.of(base.getInfo(), sec, base.getQuantity(), base.getPrice()); } return base; }
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()); }