@ImmutableValidator private void validate() { int size = deliveryBasketIds.size(); ArgChecker.isTrue(size == conversionFactors.size(), "The delivery basket size should be the same as the conversion factor size"); ArgChecker.inOrderOrEqual(firstNoticeDate, lastNoticeDate, "firstNoticeDate", "lastNoticeDate"); if (firstDeliveryDate != null && lastDeliveryDate != null) { ArgChecker.inOrderOrEqual(firstDeliveryDate, lastDeliveryDate, "firstDeliveryDate", "lastDeliveryDate"); ArgChecker.inOrderOrEqual(firstNoticeDate, firstDeliveryDate, "firstNoticeDate", "firstDeliveryDate"); ArgChecker.inOrderOrEqual(lastNoticeDate, lastDeliveryDate, "lastNoticeDate", "lastDeliveryDate"); } }
/** * Gets the stream of business days between the two dates. * <p> * This method will treat weekends as holidays. * If the dates are equal, an empty stream is returned. * If the end is before the start, an exception is thrown. * * @param startInclusive the start date * @param endExclusive the end date * @return the stream of business days * @throws IllegalArgumentException if either date is outside the supported range */ public default Stream<LocalDate> businessDays(LocalDate startInclusive, LocalDate endExclusive) { ArgChecker.inOrderOrEqual(startInclusive, endExclusive, "startInclusive", "endExclusive"); return LocalDateUtils.stream(startInclusive, endExclusive) .filter(this::isBusinessDay); }
/** * Calculates the number of business days between two dates. * <p> * This calculates the number of business days within the range. * If the dates are equal, zero is returned. * If the end is before the start, an exception is thrown. * * @param startInclusive the start date * @param endExclusive the end date * @return the total number of business days between the start and end date * @throws IllegalArgumentException if either date is outside the supported range */ public default int daysBetween(LocalDate startInclusive, LocalDate endExclusive) { ArgChecker.inOrderOrEqual(startInclusive, endExclusive, "startInclusive", "endExclusive"); return Math.toIntExact(LocalDateUtils.stream(startInclusive, endExclusive) .filter(this::isBusinessDay) .count()); }
/** * Gets the stream of holidays between the two dates. * <p> * This method will treat weekends as holidays. * If the dates are equal, an empty stream is returned. * If the end is before the start, an exception is thrown. * * @param startInclusive the start date * @param endExclusive the end date * @return the stream of holidays * @throws IllegalArgumentException if either date is outside the supported range */ public default Stream<LocalDate> holidays(LocalDate startInclusive, LocalDate endExclusive) { ArgChecker.inOrderOrEqual(startInclusive, endExclusive, "startInclusive", "endExclusive"); return LocalDateUtils.stream(startInclusive, endExclusive) .filter(this::isHoliday); }
public void test_inOrderOrEqual_true() { LocalDate a = LocalDate.of(2011, 7, 2); LocalDate b = LocalDate.of(2011, 7, 3); ArgChecker.inOrderOrEqual(a, b, "a", "b"); ArgChecker.inOrderOrEqual(a, a, "a", "b"); ArgChecker.inOrderOrEqual(b, b, "a", "b"); }
@ImmutableValidator private void validate() { LocalDate lastTradeDate = underlyingFuture.getLastTradeDate(); ArgChecker.inOrderOrEqual(expiry.toLocalDate(), lastTradeDate, "expiry.date", "underlyingFuture.lastTradeDate"); }
@ImmutableValidator private void validate() { inOrderOrEqual(expiry.toLocalDate(), underlying.getPaymentDate(), "expiry.date", "underlying.paymentDate"); }
@ImmutableValidator private void validate() { ArgChecker.inOrderOrEqual( expiryDate, underlyingFuture.getLastTradeDate(), "expiryDate", "underlyingFuture.lastTradeDate"); }
@ImmutableValidator private void validate() { inOrderOrEqual(expiryDate, underlying.getPaymentDate(), "expiryDate", "underlying.paymentDate"); }
@Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = ".*a.* [<][=] .*b.*") public void test_inOrderOrEqual_false() { LocalDate a = LocalDate.of(2011, 7, 3); LocalDate b = LocalDate.of(2011, 7, 2); ArgChecker.inOrderOrEqual(a, b, "a", "b"); }
@ImmutableValidator private void validate() { LocalDate lastTradeDate = underlyingFuture.getLastTradeDate(); ArgChecker.inOrderOrEqual(expiry.toLocalDate(), lastTradeDate, "expiry.date", "underlying.lastTradeDate"); ArgChecker.isTrue( strikePrice < 2, "Strike price must be in decimal form, such as 0.993 for a 0.7% rate, but was: {}", strikePrice); }
@ImmutableValidator private void validate() { int size = deliveryBasket.size(); ArgChecker.isTrue(size == conversionFactors.size(), "The delivery basket size should be the same as the conversion factor size"); ArgChecker.inOrderOrEqual(firstNoticeDate, lastNoticeDate, "firstNoticeDate", "lastNoticeDate"); ArgChecker.inOrderOrEqual(firstDeliveryDate, lastDeliveryDate, "firstDeliveryDate", "lastDeliveryDate"); ArgChecker.inOrderOrEqual(firstNoticeDate, firstDeliveryDate, "firstNoticeDate", "firstDeliveryDate"); ArgChecker.inOrderOrEqual(lastNoticeDate, lastDeliveryDate, "lastNoticeDate", "lastDeliveryDate"); if (size > 1) { double notional = getNotional(); Currency currency = getCurrency(); for (int i = 1; i < size; ++i) { ArgChecker.isTrue(deliveryBasket.get(i).getNotional() == notional); ArgChecker.isTrue(deliveryBasket.get(i).getCurrency().equals(currency)); } } }
@ImmutableValidator private void validate() { ArgChecker.inOrderOrEqual(expiryDate, underlyingFuture.getLastTradeDate(), "expiryDate", "lastTradeDate"); ArgChecker.isTrue( strikePrice < 2, "Strike price must be in decimal form, such as 0.993 for a 0.7% rate, but was: {}", strikePrice); }
@ImmutableValidator private void validate() { ArgChecker.inOrderOrEqual(firstStepDate, lastStepDate, "firstStepDate", "lastStepDate"); ArgChecker.isTrue(adjustment.getType() != ValueAdjustmentType.REPLACE, "ValueAdjustmentType must not be 'Replace'"); }
@ImmutableValidator private void validate() { if (baseCurrencyPayment.getCurrency().equals(counterCurrencyPayment.getCurrency())) { throw new IllegalArgumentException("Payments must have different currencies"); } if ((baseCurrencyPayment.getAmount() != 0d || counterCurrencyPayment.getAmount() != 0d) && Math.signum(baseCurrencyPayment.getAmount()) != -Math.signum(counterCurrencyPayment.getAmount())) { throw new IllegalArgumentException("Payments must have different signs"); } ArgChecker.inOrderOrEqual(baseCurrencyPayment.getDate(), counterCurrencyPayment.getDate(), "baseCurrencyPayment.date", "counterCurrencyPayment.date"); }
@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"); }
@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"); }
@Override public SwapTrade toTrade( TradeInfo tradeInfo, LocalDate startDate, LocalDate endDate, BuySell buySell, double notional, double spread) { Optional<LocalDate> tradeDate = tradeInfo.getTradeDate(); if (tradeDate.isPresent()) { ArgChecker.inOrderOrEqual(tradeDate.get(), startDate, "tradeDate", "startDate"); } SwapLeg leg1 = spreadLeg.toLeg(startDate, endDate, PayReceive.ofPay(buySell.isBuy()), notional, spread); SwapLeg leg2 = flatLeg.toLeg(startDate, endDate, PayReceive.ofPay(buySell.isSell()), notional); return SwapTrade.builder() .info(tradeInfo) .product(Swap.of(leg1, leg2)) .build(); }
@ImmutableValidator private void validate() { ArgChecker.isTrue( startObservation.getIndex().equals(endObservation.getIndex()), "All observations must be for the same index"); ArgChecker.isTrue( startObservation.getIndex().equals(startSecondObservation.getIndex()), "All observations must be for the same index"); ArgChecker.isTrue( startObservation.getIndex().equals(endSecondObservation.getIndex()), "All observations must be for the same index"); ArgChecker.inOrderNotEqual( startObservation.getFixingMonth(), startSecondObservation.getFixingMonth(), "startObservation", "startSecondObservation"); ArgChecker.inOrderOrEqual( startSecondObservation.getFixingMonth(), endObservation.getFixingMonth(), "startSecondObservation", "endObservation"); ArgChecker.inOrderNotEqual( endObservation.getFixingMonth(), endSecondObservation.getFixingMonth(), "endObservation", "endSecondObservation"); }
/** * Calculates the price for settlement at a given settlement date using curves. * * @param bill the bill * @param provider the discounting provider * @param settlementDate the settlement date * @return the price */ public double priceFromCurves(ResolvedBill bill, LegalEntityDiscountingProvider provider, LocalDate settlementDate) { ArgChecker.inOrderNotEqual(settlementDate, bill.getNotional().getDate(), "settlementDate", "endDate"); ArgChecker.inOrderOrEqual(provider.getValuationDate(), settlementDate, "valuationDate", "settlementDate"); IssuerCurveDiscountFactors issuerDf = issuerCurveDf(bill, provider); double dfMaturity = issuerDf.discountFactor(bill.getNotional().getDate()); RepoCurveDiscountFactors repoDf = repoCurveDf(bill, provider); double dfRepoSettle = repoDf.discountFactor(settlementDate); return dfMaturity / dfRepoSettle; }