@Override public EtdFuturePosition createPosition( PositionInfo positionInfo, double longQuantity, double shortQuantity, ReferenceData refData) { return EtdFuturePosition.ofLongShort(positionInfo, this, longQuantity, shortQuantity); }
/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(EtdFuturePosition 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() { EtdFuturePosition test = EtdFuturePosition.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() { EtdFuturePosition test = sut(); assertEquals(test.getType(), EtdType.FUTURE); assertEquals(test.getCurrency(), Currency.GBP); assertEquals(test.getSecurityId(), test.getSecurity().getSecurityId()); assertEquals(test.getQuantity(), 1000d, 0d); }
@Override public PortfolioItemSummary summarize() { // F-ECAG-FGBS-201706 x 200, Jun17 String future = security.summaryDescription(); String description = getSecurityId().getStandardId().getValue() + " x " + SummarizerUtils.value(getQuantity()) + ", " + future; return SummarizerUtils.summary(this, ProductType.ETD_FUTURE, 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 EtdFuturePosition ofLongShort(EtdFutureSecurity security, double longQuantity, double shortQuantity) { return ofLongShort(PositionInfo.empty(), security, longQuantity, shortQuantity); }
static EtdFuturePosition sut() { return EtdFuturePosition.builder() .info(POSITION_INFO) .security(SECURITY) .longQuantity(LONG_QUANTITY) .shortQuantity(SHORT_QUANTITY) .build(); }
@Override public EtdFuturePosition withQuantity(double quantity) { return EtdFuturePosition.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 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); }
static EtdFuturePosition sut2() { return EtdFuturePosition.builder() .security(EtdFutureSecurityTest.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 EtdFuturePosition ofNet(EtdFutureSecurity 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 ((EtdFuturePosition) bean).getInfo(); case 949122880: // security return ((EtdFuturePosition) bean).getSecurity(); case 611668775: // longQuantity return ((EtdFuturePosition) bean).getLongQuantity(); case -2094395097: // shortQuantity return ((EtdFuturePosition) bean).getShortQuantity(); case -1285004149: // quantity return ((EtdFuturePosition) bean).getQuantity(); } return super.propertyGet(bean, propertyName, quiet); }
public void test() { EtdFutureSecurity test = sut(); assertEquals(test.getVariant(), EtdVariant.MONTHLY); assertEquals(test.getType(), EtdType.FUTURE); 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()), EtdFutureTrade.of(TradeInfo.empty(), test, 1, 2)); assertEquals( test.createPosition(PositionInfo.empty(), 1, ReferenceData.empty()), EtdFuturePosition.ofNet(PositionInfo.empty(), test, 1)); assertEquals( test.createPosition(PositionInfo.empty(), 1, 2, ReferenceData.empty()), EtdFuturePosition.ofLongShort(PositionInfo.empty(), test, 1, 2)); }
assertEquals(filtered.size(), 4); EtdFuturePosition expected1 = EtdFuturePosition.builder() .info(PositionInfo.builder() .id(StandardId.of("OG", "123421")) assertBeanEquals(expected1, filtered.get(0)); EtdFuturePosition expected2 = EtdFuturePosition.builder() .info(PositionInfo.builder() .id(StandardId.of("OG", "123422")) assertBeanEquals(expected2, filtered.get(1)); EtdFuturePosition expected3 = EtdFuturePosition.builder() .info(PositionInfo.builder() .id(StandardId.of("OG", "123423")) assertBeanEquals(expected3, filtered.get(2)); EtdFuturePosition expected4 = EtdFuturePosition.builder() .info(PositionInfo.builder() .id(StandardId.of("OG", "123424"))
public void test_ofNet_withInfo() { EtdFuturePosition test = EtdFuturePosition.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() { EtdFuturePosition test = EtdFuturePosition.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_ofNet_short() { EtdFuturePosition test = EtdFuturePosition.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_ofLongShort() { EtdFuturePosition test = EtdFuturePosition.ofLongShort(SECURITY, 2000, 1000); assertEquals(test.getLongQuantity(), 2000d, 0d); assertEquals(test.getShortQuantity(), 1000d, 0d); assertEquals(test.getSecurity(), SECURITY); assertEquals(test.getQuantity(), 1000d, 0d); }