/** * Adjusts the date using the business day adjustment. * <p> * This returns the adjusted date, calculated by applying the business day * adjustment to the unadjusted date. * * @param refData the reference data to use * @return the adjusted date */ public LocalDate adjusted(ReferenceData refData) { return adjustment.adjust(unadjusted, refData); }
/** * Calculates the expiration date of a swaption from the calibration date and the underlying swap convention. * * @param bda the business day convention * @param calibrationDate the calibration date * @param expiry the period to expiry * @return the date */ private LocalDate expirationDate(BusinessDayAdjustment bda, LocalDate calibrationDate, Period expiry) { return bda.adjust(calibrationDate.plus(expiry), refData); }
@Override public LocalDate calculateReferenceDateFromTradeDate( LocalDate tradeDate, YearMonth yearMonth, ReferenceData refData) { LocalDate referenceDate = dateSequence.dateMatching(yearMonth); return businessDayAdjustment.adjust(referenceDate, refData); }
private List<LocalDate> applyBusinessDayAdjustment(List<LocalDate> unadj, ReferenceData refData) { List<LocalDate> adj = new ArrayList<>(unadj.size()); adj.add(calculatedStartDate().adjusted(refData)); for (int i = 1; i < unadj.size() - 1; i++) { adj.add(businessDayAdjustment.adjust(unadj.get(i), refData)); } adj.add(calculatedEndDate().adjusted(refData)); return adj; }
@Override public LocalDate calculateReferenceDateFromTradeDate( LocalDate tradeDate, Period minimumPeriod, int sequenceNumber, ReferenceData refData) { LocalDate earliestDate = tradeDate.plus(minimumPeriod); LocalDate referenceDate = dateSequence.nthOrSame(earliestDate, sequenceNumber); return businessDayAdjustment.adjust(referenceDate, refData); }
@Override public LocalDate date(LocalDate tradeDate, ReferenceData refData) { LocalDate startDate = spotDateOffset.adjust(tradeDate, refData); LocalDate endDate = startDate.plus(tenor); return businessDayAdjustment.adjust(endDate, refData); }
/** * Adjusts the date, adding the period in days using the holiday calendar * and then applying the business day adjustment. * <p> * The calculation is performed in two steps. * <p> * Step one, use {@link HolidayCalendar#shift(LocalDate, int)} to add the number of days. * If the holiday calendar is 'None' this will effectively add calendar days. * <p> * Step two, use {@link BusinessDayAdjustment#adjust(LocalDate, ReferenceData)} to adjust the result of step one. * * @param date the date to adjust * @param refData the reference data, used to find the holiday calendar * @return the adjusted date */ public LocalDate adjust(LocalDate date, ReferenceData refData) { LocalDate added = calendar.resolve(refData).shift(date, days); return adjustment.adjust(added, refData); }
@Override public LocalDate date(LocalDate tradeDate, ReferenceData refData) { LocalDate startDate = spotDateOffset.adjust(tradeDate, refData); LocalDate endDate = startDate.plus(tenor.getPeriod()); return businessDayAdjustment.adjust(endDate, refData); }
public BasicFixedLeg( LocalDate curveSpotDate, LocalDate maturityDate, Period swapInterval, DayCount swapDCC, DayCount curveDcc, BusinessDayAdjustment busAdj, ReferenceData refData) { List<LocalDate> list = new ArrayList<>(); LocalDate tDate = maturityDate; int step = 1; while (tDate.isAfter(curveSpotDate)) { list.add(tDate); tDate = maturityDate.minus(swapInterval.multipliedBy(step++)); } // remove spotDate from list, if it ends up there list.remove(curveSpotDate); nPayment = list.size(); swapPaymentTime = new double[nPayment]; yearFraction = new double[nPayment]; LocalDate prev = curveSpotDate; int j = nPayment - 1; for (int i = 0; i < nPayment; i++, j--) { LocalDate current = list.get(j); LocalDate adjCurr = busAdj.adjust(current, refData); yearFraction[i] = swapDCC.relativeYearFraction(prev, adjCurr); swapPaymentTime[i] = curveDcc.relativeYearFraction(curveSpotDate, adjCurr); // Payment times always good business days prev = adjCurr; } }
@Test(dataProvider = "convention", dataProviderClass = BusinessDayConventionTest.class) public void test_adjustDate(BusinessDayConvention convention, LocalDate input, LocalDate expected) { BusinessDayAdjustment test = BusinessDayAdjustment.of(convention, SAT_SUN); assertEquals(test.adjust(input, REF_DATA), expected); assertEquals(test.resolve(REF_DATA).adjust(input), expected); }
@Test public void testImmutableReferenceDataWithMergedHolidays() { HolidayCalendar hc = HolidayCalendars.FRI_SAT.combinedWith(HolidayCalendars.SAT_SUN); ImmutableReferenceData referenceData = ImmutableReferenceData.of(hc.getId(), hc); LocalDate date = BusinessDayAdjustment.of(BusinessDayConventions.PRECEDING, hc.getId()).adjust(LocalDate.of(2016, 8, 20), referenceData); assertEquals(LocalDate.of(2016, 8, 18), date); }
public void test_resolve() { Swaption base = sut(); ResolvedSwaption test = base.resolve(REF_DATA); assertEquals(test.getExpiry(), ADJUSTMENT.adjust(EXPIRY_DATE, REF_DATA).atTime(EXPIRY_TIME).atZone(ZONE)); assertEquals(test.getLongShort(), LONG); assertEquals(test.getSwaptionSettlement(), PHYSICAL_SETTLE); assertEquals(test.getUnderlying(), SWAP.resolve(REF_DATA)); }
public void test_metadata_end() { FxSwapCurveNode node = FxSwapCurveNode.of(TEMPLATE, QUOTE_ID_PTS); LocalDate valuationDate = LocalDate.of(2015, 1, 22); LocalDate endDate = CONVENTION.getBusinessDayAdjustment() .adjust(CONVENTION.getSpotDateOffset().adjust(valuationDate, REF_DATA).plus(FAR_PERIOD), REF_DATA); ParameterMetadata metadata = node.metadata(valuationDate, REF_DATA); assertEquals(((TenorDateParameterMetadata) metadata).getDate(), endDate); assertEquals(((TenorDateParameterMetadata) metadata).getTenor(), Tenor.of(FAR_PERIOD)); }
public void test_resolve() { FixedCouponBond base = sut(); ResolvedFixedCouponBond resolved = base.resolve(REF_DATA); assertEquals(resolved.getLegalEntityId(), LEGAL_ENTITY); assertEquals(resolved.getSettlementDateOffset(), DATE_OFFSET); assertEquals(resolved.getYieldConvention(), YIELD_CONVENTION); ImmutableList<FixedCouponBondPaymentPeriod> periodicPayments = resolved.getPeriodicPayments(); int expNum = 20; assertEquals(periodicPayments.size(), expNum); LocalDate unadjustedEnd = END_DATE; Schedule unadjusted = PERIOD_SCHEDULE.createSchedule(REF_DATA).toUnadjusted(); for (int i = 0; i < expNum; ++i) { FixedCouponBondPaymentPeriod payment = periodicPayments.get(expNum - 1 - i); assertEquals(payment.getCurrency(), EUR); assertEquals(payment.getNotional(), NOTIONAL); assertEquals(payment.getFixedRate(), FIXED_RATE); assertEquals(payment.getUnadjustedEndDate(), unadjustedEnd); assertEquals(payment.getEndDate(), BUSINESS_ADJUST.adjust(unadjustedEnd, REF_DATA)); assertEquals(payment.getPaymentDate(), payment.getEndDate()); LocalDate unadjustedStart = unadjustedEnd.minusMonths(6); assertEquals(payment.getUnadjustedStartDate(), unadjustedStart); assertEquals(payment.getStartDate(), BUSINESS_ADJUST.adjust(unadjustedStart, REF_DATA)); assertEquals(payment.getYearFraction(), unadjusted.getPeriod(expNum - 1 - i).yearFraction(DAY_COUNT, unadjusted)); assertEquals(payment.getDetachmentDate(), EX_COUPON.adjust(payment.getPaymentDate(), REF_DATA)); unadjustedEnd = unadjustedStart; } Payment expectedPayment = Payment.of(CurrencyAmount.of(EUR, NOTIONAL), BUSINESS_ADJUST.adjust(END_DATE, REF_DATA)); assertEquals(resolved.getNominalPayment(), expectedPayment); }
public void test_resolve() { TermDeposit base = TermDeposit.builder() .buySell(SELL) .startDate(START_DATE) .endDate(END_DATE) .businessDayAdjustment(BDA_MOD_FOLLOW) .dayCount(ACT_365F) .notional(NOTIONAL) .currency(GBP) .rate(RATE) .build(); ResolvedTermDeposit test = base.resolve(REF_DATA); LocalDate expectedEndDate = BDA_MOD_FOLLOW.adjust(END_DATE, REF_DATA); double expectedYearFraction = ACT_365F.yearFraction(START_DATE, expectedEndDate); assertEquals(test.getStartDate(), START_DATE); assertEquals(test.getEndDate(), expectedEndDate); assertEquals(test.getNotional(), -NOTIONAL); assertEquals(test.getYearFraction(), expectedYearFraction, EPS); assertEquals(test.getInterest(), -RATE * expectedYearFraction * NOTIONAL, NOTIONAL * EPS); assertEquals(test.getRate(), RATE); assertEquals(test.getCurrency(), GBP); }
public void test_resolve() { IborFixingDeposit base = IborFixingDeposit.builder() .buySell(SELL) .notional(NOTIONAL) .startDate(START_DATE) .endDate(END_DATE) .businessDayAdjustment(BDA_MOD_FOLLOW) .index(GBP_LIBOR_6M) .fixedRate(RATE) .build(); ResolvedIborFixingDeposit test = base.resolve(REF_DATA); LocalDate expectedEndDate = BDA_MOD_FOLLOW.adjust(END_DATE, REF_DATA); double expectedYearFraction = ACT_365F.yearFraction(START_DATE, expectedEndDate); IborRateComputation expectedObservation = IborRateComputation.of( GBP_LIBOR_6M, GBP_LIBOR_6M.getFixingDateOffset().adjust(START_DATE, REF_DATA), REF_DATA); assertEquals(test.getCurrency(), GBP); assertEquals(test.getStartDate(), START_DATE); assertEquals(test.getEndDate(), expectedEndDate); assertEquals(test.getFloatingRate(), expectedObservation); assertEquals(test.getNotional(), -NOTIONAL); assertEquals(test.getFixedRate(), RATE); assertEquals(test.getYearFraction(), expectedYearFraction); }
double tenor = TENORS_SIMPLE.get(looptenor).get(ChronoUnit.YEARS); LocalDate expiry = EUR_FIXED_1Y_EURIBOR_6M.getFloatingLeg().getStartDateBusinessDayAdjustment() .adjust(CALIBRATION_DATE.plus(EXPIRIES_SIMPLE_2.get(loopexpiry)), REF_DATA); LocalDate effectiveDate = EUR_FIXED_1Y_EURIBOR_6M.calculateSpotDateFromTradeDate(expiry, REF_DATA); LocalDate endDate = effectiveDate.plus(TENORS_SIMPLE.get(looptenor));
for (int loopexpiry = 0; loopexpiry < EXPIRIES.size(); loopexpiry++) { LocalDate expiry = EUR_FIXED_1Y_EURIBOR_6M.getFloatingLeg().getStartDateBusinessDayAdjustment() .adjust(CALIBRATION_DATE.plus(EXPIRIES.get(loopexpiry)), REF_DATA); LocalDate effectiveDate = EUR_FIXED_1Y_EURIBOR_6M.calculateSpotDateFromTradeDate(expiry, REF_DATA); LocalDate endDate = effectiveDate.plus(TENORS.get(looptenor));
public void test_trade() { FraCurveNode node = FraCurveNode.of(TEMPLATE, QUOTE_ID, SPREAD); LocalDate valuationDate = LocalDate.of(2015, 1, 22); double rate = 0.035; ImmutableMarketData marketData = ImmutableMarketData.builder(valuationDate).addValue(QUOTE_ID, rate).build(); FraTrade trade = node.trade(1d, marketData, REF_DATA); LocalDate startDateExpected = BDA_MOD_FOLLOW.adjust(OFFSET.adjust(valuationDate, REF_DATA).plus(PERIOD_TO_START), REF_DATA); LocalDate endDateExpected = BDA_MOD_FOLLOW.adjust(OFFSET.adjust(valuationDate, REF_DATA).plus(PERIOD_TO_END), REF_DATA); Fra productExpected = Fra.builder() .buySell(BuySell.SELL) .currency(GBP) .dayCount(ACT_365F) .startDate(startDateExpected) .endDate(endDateExpected) .paymentDate(AdjustableDate.of(startDateExpected)) .notional(1.0d) .index(GBP_LIBOR_3M) .fixedRate(rate + SPREAD) .build(); TradeInfo tradeInfoExpected = TradeInfo.builder() .tradeDate(valuationDate) .build(); assertEquals(trade.getProduct(), productExpected); assertEquals(trade.getInfo(), tradeInfoExpected); }
IborCapletFloorletPeriod[] periods = new IborCapletFloorletPeriod[4]; for (int i = 0; i < 4; ++i) { LocalDate start = BUSS_ADJ.adjust(unadjustedDates[i], REF_DATA); LocalDate end = BUSS_ADJ.adjust(unadjustedDates[i + 1], REF_DATA); double yearFraction = EUR_EURIBOR_3M.getDayCount().relativeYearFraction(start, end); LocalDate fixingDate = RATE_CALCULATION.getFixingDateOffset().adjust(start, REF_DATA);