/** * Gets the expiry date-time. * <p> * The option expires at this date and time. * <p> * The result is returned by combining the expiry date, time and time-zone. * * @return the expiry date and time */ public ZonedDateTime getExpiry() { return expiryDate.getUnadjusted().atTime(expiryTime).atZone(expiryZone); }
@Override public String formatForCsv(AdjustableDate amount) { return amount.getUnadjusted().toString(); }
@Override public String formatForDisplay(AdjustableDate amount) { return amount.getUnadjusted().toString(); }
/** * Gets the accrual start date of the swap. * <p> * This is the earliest accrual date of the legs, often known as the effective date. * The latest date is chosen by examining the unadjusted end date. * * @return the start date of the swap */ @DerivedProperty public AdjustableDate getStartDate() { return legs.stream() .map(SwapLeg::getStartDate) .min(Comparator.comparing(adjDate -> adjDate.getUnadjusted())) .get(); // always at least one leg, so get() is safe }
/** * Gets the accrual end date of the swap. * <p> * This is the latest accrual date of the legs, often known as the termination date. * The latest date is chosen by examining the unadjusted end date. * * @return the end date of the swap */ @DerivedProperty public AdjustableDate getEndDate() { return legs.stream() .map(SwapLeg::getEndDate) .max(Comparator.comparing(adjDate -> adjDate.getUnadjusted())) .get(); // always at least one leg, so get() is safe }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 482476551: // unadjusted return ((AdjustableDate) bean).getUnadjusted(); case 1977085293: // adjustment return ((AdjustableDate) bean).getAdjustment(); } return super.propertyGet(bean, propertyName, quiet); }
@Override public PortfolioItemSummary summarize() { // Long 5Y USD 2mm Rec USD-LIBOR-6M / Pay 1% : 21Jan18 String swapDesc = product.getUnderlying().summaryDescription(); swapDesc = swapDesc.contains(":") ? swapDesc.substring(0, swapDesc.lastIndexOf(':')).trim() : swapDesc; StringBuilder buf = new StringBuilder(96); buf.append(product.getLongShort()); buf.append(' '); buf.append(swapDesc); buf.append(" : "); buf.append(SummarizerUtils.date(product.getExpiryDate().getUnadjusted())); return SummarizerUtils.summary(this, ProductType.SWAPTION, buf.toString(), product.getCurrency()); }
@Override public PortfolioItemSummary summarize() { // Pay USD 2mm : 21Jan18 StringBuilder buf = new StringBuilder(64); buf.append(product.getPayReceive()); buf.append(' '); buf.append(SummarizerUtils.amount(product.getValue())); buf.append(" : "); buf.append(SummarizerUtils.date(product.getDate().getUnadjusted())); return SummarizerUtils.summary(this, ProductType.BULLET_PAYMENT, buf.toString(), product.getCurrency()); }
/** * Computes the price from the yield at a given settlement date. * * @param yield the yield * @param settlementDate the settlement date * @return the price */ public double priceFromYield(double yield, LocalDate settlementDate) { double accrualFactor = dayCount.relativeYearFraction(settlementDate, notional.getDate().getUnadjusted()); return yieldConvention.priceFromYield(yield, accrualFactor); }
/** * Computes the yield from the price at a given settlement date. * * @param price the price * @param settlementDate the settlement date * @return the yield */ public double yieldFromPrice(double price, LocalDate settlementDate) { double accrualFactor = dayCount.relativeYearFraction(settlementDate, notional.getDate().getUnadjusted()); return yieldConvention.yieldFromPrice(price, accrualFactor); }
@Override public Dsf createProduct(ReferenceData refData) { LocalDate deliveryDate = underlyingSwap.getStartDate().getUnadjusted(); return new Dsf(getSecurityId(), notional, lastTradeDate, deliveryDate, underlyingSwap); }
@Override public PortfolioItemSummary summarize() { // 5Y USD 2mm Rec USD-LIBOR-1100-1Y Cap 1% / Pay Premium : 21Jan17-21Jan22 StringBuilder buf = new StringBuilder(96); CmsLeg mainLeg = product.getCmsLeg(); buf.append(SummarizerUtils.datePeriod(mainLeg.getStartDate().getUnadjusted(), mainLeg.getEndDate().getUnadjusted())); buf.append(' '); buf.append(SummarizerUtils.amount(mainLeg.getCurrency(), mainLeg.getNotional().getInitialValue())); buf.append(' '); if (mainLeg.getPayReceive().isReceive()) { buf.append("Rec "); summarizeMainLeg(mainLeg, buf); buf.append(getPremium().isPresent() ? " / Pay Premium" : (product.getPayLeg().isPresent() ? " / Pay Periodic" : "")); } else { buf.append( getPremium().isPresent() ? "Rec Premium / Pay " : (product.getPayLeg().isPresent() ? "Rec Periodic / Pay " : "")); summarizeMainLeg(mainLeg, buf); } buf.append(" : "); buf.append(SummarizerUtils.dateRange(mainLeg.getStartDate().getUnadjusted(), mainLeg.getEndDate().getUnadjusted())); return SummarizerUtils.summary(this, ProductType.CMS, buf.toString(), mainLeg.getCurrency()); }
private SwaptionSettlement parseSettlement(XmlElement swaptionEl, FpmlDocument document) { Optional<String> optionalCashSettlement = swaptionEl.findAttribute("cashSettlement"); if (optionalCashSettlement.isPresent()) { XmlElement cashSettlementEl = swaptionEl.getChild("cashSettlement"); CashSwaptionSettlementMethod method = parseCashSettlementMethod(cashSettlementEl); LocalDate settlementDate = document.parseAdjustedRelativeDateOffset(cashSettlementEl).getUnadjusted(); return CashSwaptionSettlement.of(settlementDate, method); } else { // treat physical as the default to match FpML examples return PhysicalSwaptionSettlement.DEFAULT; } }
@ImmutableValidator private void validate() { ArgChecker.inOrderOrEqual( expiryDate.getUnadjusted(), underlying.getStartDate().getUnadjusted(), "expiryDate", "underlying.startDate.unadjusted"); ArgChecker.isTrue(!underlying.isCrossCurrency(), "Underlying swap must not be cross-currency"); ArgChecker.isTrue(underlying.getLegs(SwapLegType.FIXED).size() == 1, "Underlying swap must have one fixed leg"); ArgChecker.isTrue(underlying.getLegs(SwapLegType.IBOR).size() == 1, "Underlying swap must have one Ibor leg"); ArgChecker.isTrue(underlying.allIndices().size() == 1, "Underlying swap must have one index"); ArgChecker.isTrue(underlying.allIndices().iterator().next() instanceof IborIndex, "Underlying swap must have one Ibor index"); }
public void test_of_2args_withNoAdjustment() { AdjustableDate test = AdjustableDate.of(FRI_2014_07_11, BDA_NONE); assertEquals(test.getUnadjusted(), FRI_2014_07_11); assertEquals(test.getAdjustment(), BDA_NONE); assertEquals(test.toString(), "2014-07-11"); assertEquals(test.adjusted(REF_DATA), FRI_2014_07_11); }
public void test_of_2args_withAdjustment() { AdjustableDate test = AdjustableDate.of(FRI_2014_07_11, BDA_FOLLOW_SAT_SUN); assertEquals(test.getUnadjusted(), FRI_2014_07_11); assertEquals(test.getAdjustment(), BDA_FOLLOW_SAT_SUN); assertEquals(test.toString(), "2014-07-11 adjusted by Following using calendar Sat/Sun"); assertEquals(test.adjusted(REF_DATA), FRI_2014_07_11); }
public void test_of_1arg() { AdjustableDate test = AdjustableDate.of(FRI_2014_07_11); assertEquals(test.getUnadjusted(), FRI_2014_07_11); assertEquals(test.getAdjustment(), BDA_NONE); assertEquals(test.toString(), "2014-07-11"); assertEquals(test.adjusted(REF_DATA), FRI_2014_07_11); }
@ImmutableValidator private void validate() { ArgChecker.inOrderNotEqual( startDate, endDate, "startDate", "endDate"); if (firstRegularStartDate != null) { if (lastRegularEndDate != null) { ArgChecker.inOrderOrEqual( firstRegularStartDate, lastRegularEndDate, "firstRegularStartDate", "lastRegularEndDate"); } // Check override start date if present, otherwise use regular start date if (overrideStartDate != null) { ArgChecker.inOrderNotEqual( overrideStartDate.getUnadjusted(), firstRegularStartDate, "overrideStartDate", "firstRegularStartDate"); } else { ArgChecker.inOrderOrEqual( startDate, firstRegularStartDate, "unadjusted", "firstRegularStartDate"); } } if (lastRegularEndDate != null) { ArgChecker.inOrderOrEqual( lastRegularEndDate, endDate, "lastRegularEndDate", "endDate"); } }
public void test_ofYield() { BillTrade test = sut_yield(); assertEquals(test.getProduct(), PRODUCT); assertEquals(test.getInfo(), TRADE_INFO); assertEquals(test.getQuantity(), QUANTITY); double price = 1.0d - YIELD * PRODUCT.getDayCount().relativeYearFraction(SETTLEMENT_DATE, PRODUCT.getNotional().getDate().getUnadjusted()); assertEquals(test.getPrice(), price, TOLERANCE_PRICE); assertEquals(test.withInfo(TRADE_INFO).getInfo(), TRADE_INFO); assertEquals(test.withQuantity(129).getQuantity(), 129d, 0d); assertEquals(test.withPrice(129).getPrice(), 129d, 0d); }
@ImmutableValidator private void validate() { ArgChecker.inOrderOrEqual( deliveryDate, underlyingSwap.getStartDate().getUnadjusted(), "deliveryDate", "underlyingSwap.startDate.unadjusted"); ArgChecker.isFalse(underlyingSwap.isCrossCurrency(), "Underlying swap must not be cross currency"); for (SwapLeg swapLeg : underlyingSwap.getLegs()) { if (swapLeg.getType().equals(SwapLegType.FIXED)) { ArgChecker.isTrue(swapLeg.getPayReceive().isReceive(), "Underlying swap must receive the fixed leg"); } if (swapLeg instanceof RateCalculationSwapLeg) { RateCalculationSwapLeg leg = (RateCalculationSwapLeg) swapLeg; ArgChecker.isTrue(Math.abs(leg.getNotionalSchedule().getAmount().getInitialValue()) == 1d, "Underlying swap must have a notional of 1"); } } ArgChecker.inOrderOrEqual(lastTradeDate, deliveryDate, "lastTradeDate", "deliveryDate"); }