@Override public EtdOptionPosition createPosition( PositionInfo positionInfo, double longQuantity, double shortQuantity, ReferenceData refData) { return EtdOptionPosition.ofLongShort(positionInfo, this, longQuantity, shortQuantity); }
/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(EtdOptionPosition beanToCopy) { this.info = beanToCopy.getInfo(); this.security = beanToCopy.getSecurity(); this.longQuantity = beanToCopy.getLongQuantity(); this.shortQuantity = beanToCopy.getShortQuantity(); }
@Override public SecuritizedProductPosition<?> resolveTarget(ReferenceData refData) { SecurityId securityId = getSecurityId(); Security security = refData.getValue(securityId); Position position = security.createPosition(getInfo(), getLongQuantity(), getShortQuantity(), refData); if (position instanceof SecuritizedProductPosition) { return (SecuritizedProductPosition<?>) position; } throw new ClassCastException(Messages.format( "Reference data for security '{}' did not implement SecuritizedProductPosition: ", securityId, position.getClass().getName())); }
public void test_ofNet() { EtdOptionPosition test = EtdOptionPosition.ofNet(SECURITY, 1000); assertEquals(test.getLongQuantity(), 1000d, 0d); assertEquals(test.getShortQuantity(), 0d, 0d); assertEquals(test.getSecurity(), SECURITY); assertEquals(test.getQuantity(), 1000d, 0d); assertEquals(test.withInfo(POSITION_INFO).getInfo(), POSITION_INFO); assertEquals(test.withQuantity(129).getQuantity(), 129d, 0d); assertEquals(test.withQuantity(-129).getQuantity(), -129d, 0d); }
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); }
@Override public PortfolioItemSummary summarize() { // O-ECAG-OGBS-201706-P1.50 x 200, Jun17 P1.50 String option = security.summaryDescription(); String description = getSecurityId().getStandardId().getValue() + " x " + SummarizerUtils.value(getQuantity()) + ", " + option; return SummarizerUtils.summary(this, ProductType.ETD_OPTION, description, getCurrency()); }
/** * Obtains an instance from the security, long quantity and short quantity. * <p> * The long quantity and short quantity must be zero or positive, not negative. * In many cases, only a long quantity or short quantity will be present with the other set to zero. * However it is also possible for both to be non-zero, allowing long and short positions to be treated separately. * * @param security the underlying security * @param longQuantity the long quantity of the underlying security * @param shortQuantity the short quantity of the underlying security * @return the position */ public static EtdOptionPosition ofLongShort(EtdOptionSecurity security, double longQuantity, double shortQuantity) { return ofLongShort(PositionInfo.empty(), security, longQuantity, shortQuantity); }
static EtdOptionPosition sut() { return EtdOptionPosition.builder() .info(POSITION_INFO) .security(SECURITY) .longQuantity(LONG_QUANTITY) .shortQuantity(SHORT_QUANTITY) .build(); }
@Override public EtdOptionPosition withQuantity(double quantity) { return EtdOptionPosition.ofNet(info, security, quantity); }
/** * 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); }
static EtdOptionPosition sut2() { return EtdOptionPosition.builder() .security(EtdOptionSecurityTest.sut2()) .longQuantity(4000) .shortQuantity(1000) .build(); }
/** * Obtains an instance from the security and net quantity. * <p> * The net quantity is the long quantity minus the short quantity, which may be negative. * If the quantity is positive it is treated as a long quantity. * Otherwise it is treated as a short quantity. * * @param security the underlying security * @param netQuantity the net quantity of the underlying security * @return the position */ public static EtdOptionPosition ofNet(EtdOptionSecurity security, double netQuantity) { return ofNet(PositionInfo.empty(), security, netQuantity); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 3237038: // info return ((EtdOptionPosition) bean).getInfo(); case 949122880: // security return ((EtdOptionPosition) bean).getSecurity(); case 611668775: // longQuantity return ((EtdOptionPosition) bean).getLongQuantity(); case -2094395097: // shortQuantity return ((EtdOptionPosition) bean).getShortQuantity(); case -1285004149: // quantity return ((EtdOptionPosition) bean).getQuantity(); } return super.propertyGet(bean, propertyName, quiet); }
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)); }
assertEquals(filtered.size(), 3); EtdOptionPosition expected1 = EtdOptionPosition.builder() .info(PositionInfo.builder() .id(StandardId.of("OG", "123431")) assertBeanEquals(expected1, filtered.get(0)); EtdOptionPosition expected2 = EtdOptionPosition.builder() .info(PositionInfo.builder() .id(StandardId.of("OG", "123432")) assertBeanEquals(expected2, filtered.get(1)); EtdOptionPosition expected3 = EtdOptionPosition.builder() .info(PositionInfo.builder() .id(StandardId.of("OG", "123433"))
public void test_ofNet_short() { EtdOptionPosition test = EtdOptionPosition.ofNet(SECURITY, -1000); assertEquals(test.getLongQuantity(), 0d, 0d); assertEquals(test.getShortQuantity(), 1000d, 0d); assertEquals(test.getSecurity(), SECURITY); assertEquals(test.getQuantity(), -1000d, 0d); }
public void test_ofNet_withInfo() { EtdOptionPosition test = EtdOptionPosition.ofNet(POSITION_INFO, SECURITY, 1000); assertEquals(test.getLongQuantity(), 1000d, 0d); assertEquals(test.getShortQuantity(), 0d, 0d); assertEquals(test.getInfo(), POSITION_INFO); assertEquals(test.getSecurity(), SECURITY); assertEquals(test.getQuantity(), 1000d, 0d); }
public void test_ofLongShort_withInfo() { EtdOptionPosition test = EtdOptionPosition.ofLongShort(POSITION_INFO, SECURITY, 2000, 1000); assertEquals(test.getLongQuantity(), 2000d, 0d); assertEquals(test.getShortQuantity(), 1000d, 0d); assertEquals(test.getInfo(), POSITION_INFO); assertEquals(test.getSecurity(), SECURITY); assertEquals(test.getQuantity(), 1000d, 0d); }
public void test_ofLongShort() { EtdOptionPosition test = EtdOptionPosition.ofLongShort(SECURITY, 2000, 1000); assertEquals(test.getLongQuantity(), 2000d, 0d); assertEquals(test.getShortQuantity(), 1000d, 0d); assertEquals(test.getSecurity(), SECURITY); assertEquals(test.getQuantity(), 1000d, 0d); }