/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(CapitalIndexedBondPosition beanToCopy) { this.info = beanToCopy.getInfo(); this.product = beanToCopy.getProduct(); this.longQuantity = beanToCopy.getLongQuantity(); this.shortQuantity = beanToCopy.getShortQuantity(); }
@Override public CapitalIndexedBondPosition withInfo(PositionInfo info) { return new CapitalIndexedBondPosition(info, product, longQuantity, shortQuantity); }
public void test_builder_resolved() { CapitalIndexedBondPosition test = sut(); assertEquals(test.getProduct(), PRODUCT); assertEquals(test.getInfo(), POSITION_INFO); assertEquals(test.getLongQuantity(), QUANTITY, 0d); assertEquals(test.getShortQuantity(), 0d, 0d); assertEquals(test.getQuantity(), QUANTITY, 0d); assertEquals(test.withInfo(POSITION_INFO).getInfo(), POSITION_INFO); assertEquals(test.withQuantity(129).getQuantity(), 129d, 0d); }
@Override public PortfolioItemSummary summarize() { // ID x 200 String description = getSecurityId().getStandardId().getValue() + " x " + SummarizerUtils.value(getQuantity()); return SummarizerUtils.summary(this, ProductType.BOND, description, getCurrency()); }
@Override public CapitalIndexedBondPosition createPosition( PositionInfo positionInfo, double longQuantity, double shortQuantity, ReferenceData refData) { return CapitalIndexedBondPosition.ofLongShort(positionInfo, createProduct(refData), longQuantity, shortQuantity); }
@Override public ResolvedCapitalIndexedBondTrade resolve(ReferenceData refData) { ResolvedCapitalIndexedBond resolved = product.resolve(refData); return new ResolvedCapitalIndexedBondTrade(info, resolved, getQuantity(), null); }
public void test_withQuantity() { CapitalIndexedBondPosition base = sut(); double quantity = 75343d; CapitalIndexedBondPosition computed = base.withQuantity(quantity); CapitalIndexedBondPosition expected = CapitalIndexedBondPosition.builder() .info(POSITION_INFO) .product(PRODUCT) .longQuantity(quantity) .build(); assertEquals(computed, expected); }
static CapitalIndexedBondPosition sut() { return CapitalIndexedBondPosition.builder() .info(POSITION_INFO) .product(PRODUCT) .longQuantity(QUANTITY) .build(); }
static CapitalIndexedBondPosition sut2() { return CapitalIndexedBondPosition.builder() .info(POSITION_INFO2) .product(PRODUCT2) .longQuantity(100) .shortQuantity(50) .build(); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 3237038: // info return ((CapitalIndexedBondPosition) bean).getInfo(); case -309474065: // product return ((CapitalIndexedBondPosition) bean).getProduct(); case 611668775: // longQuantity return ((CapitalIndexedBondPosition) bean).getLongQuantity(); case -2094395097: // shortQuantity return ((CapitalIndexedBondPosition) bean).getShortQuantity(); case -1285004149: // quantity return ((CapitalIndexedBondPosition) bean).getQuantity(); } return super.propertyGet(bean, propertyName, quiet); }
@Override public CapitalIndexedBondPosition build() { return new CapitalIndexedBondPosition( info, product, longQuantity, shortQuantity); }
/** * Obtains an instance from position information, product 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 positionInfo the position information * @param product the underlying product * @param netQuantity the net quantity of the underlying security * @return the position */ public static CapitalIndexedBondPosition ofNet(PositionInfo positionInfo, CapitalIndexedBond product, double netQuantity) { double longQuantity = netQuantity >= 0 ? netQuantity : 0; double shortQuantity = netQuantity >= 0 ? 0 : -netQuantity; return new CapitalIndexedBondPosition(positionInfo, product, longQuantity, shortQuantity); }
/** * Obtains an instance from position information, product, 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 positionInfo the position information * @param product the underlying product * @param longQuantity the long quantity of the underlying security * @param shortQuantity the short quantity of the underlying security * @return the position */ public static CapitalIndexedBondPosition ofLongShort( PositionInfo positionInfo, CapitalIndexedBond product, double longQuantity, double shortQuantity) { return new CapitalIndexedBondPosition(positionInfo, product, longQuantity, shortQuantity); }