public void test_explainPresentValueWithSpread_past() { ExplainMapBuilder builder = ExplainMap.builder(); PRICER.explainPresentValueWithSpread( PAYMENT_PERIOD, ISSUER_CURVE_AFTER, builder, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); ExplainMap explain = builder.build(); assertEquals(explain.get(ExplainKey.ENTRY_TYPE).get(), "FixedCouponBondPaymentPeriod"); assertEquals(explain.get(ExplainKey.PAYMENT_DATE).get(), PAYMENT_PERIOD.getPaymentDate()); assertEquals(explain.get(ExplainKey.PAYMENT_CURRENCY).get(), PAYMENT_PERIOD.getCurrency()); assertEquals(explain.get(ExplainKey.START_DATE).get(), START_ADJUSTED); assertEquals(explain.get(ExplainKey.UNADJUSTED_START_DATE).get(), START); assertEquals(explain.get(ExplainKey.END_DATE).get(), END_ADJUSTED); assertEquals(explain.get(ExplainKey.UNADJUSTED_END_DATE).get(), END); assertEquals(explain.get(ExplainKey.DAYS).get().intValue(), (int) DAYS.between(START_ADJUSTED, END_ADJUSTED)); assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().getAmount(), 0d, NOTIONAL * TOL); assertEquals(explain.get(ExplainKey.PRESENT_VALUE).get().getAmount(), 0d, NOTIONAL * TOL); }
public void test_explainPresentValue_past() { ExplainMapBuilder builder = ExplainMap.builder(); PRICER.explainPresentValue(PAYMENT_PERIOD, ISSUER_CURVE_AFTER, builder); ExplainMap explain = builder.build(); assertEquals(explain.get(ExplainKey.ENTRY_TYPE).get(), "FixedCouponBondPaymentPeriod"); assertEquals(explain.get(ExplainKey.PAYMENT_DATE).get(), PAYMENT_PERIOD.getPaymentDate()); assertEquals(explain.get(ExplainKey.PAYMENT_CURRENCY).get(), PAYMENT_PERIOD.getCurrency()); assertEquals(explain.get(ExplainKey.START_DATE).get(), START_ADJUSTED); assertEquals(explain.get(ExplainKey.UNADJUSTED_START_DATE).get(), START); assertEquals(explain.get(ExplainKey.END_DATE).get(), END_ADJUSTED); assertEquals(explain.get(ExplainKey.UNADJUSTED_END_DATE).get(), END); assertEquals(explain.get(ExplainKey.DAYS).get().intValue(), (int) DAYS.between(START_ADJUSTED, END_ADJUSTED)); assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().getAmount(), 0d, NOTIONAL * TOL); assertEquals(explain.get(ExplainKey.PRESENT_VALUE).get().getAmount(), 0d, NOTIONAL * TOL); }
public void test_explainPresentValue() { ExplainMapBuilder builder = ExplainMap.builder(); PRICER.explainPresentValue(PAYMENT_PERIOD, ISSUER_CURVE, builder); ExplainMap explain = builder.build(); assertEquals(explain.get(ExplainKey.ENTRY_TYPE).get(), "FixedCouponBondPaymentPeriod"); assertEquals(explain.get(ExplainKey.PAYMENT_DATE).get(), PAYMENT_PERIOD.getPaymentDate()); assertEquals(explain.get(ExplainKey.PAYMENT_CURRENCY).get(), PAYMENT_PERIOD.getCurrency()); assertEquals(explain.get(ExplainKey.START_DATE).get(), START_ADJUSTED); assertEquals(explain.get(ExplainKey.UNADJUSTED_START_DATE).get(), START); assertEquals(explain.get(ExplainKey.END_DATE).get(), END_ADJUSTED); assertEquals(explain.get(ExplainKey.UNADJUSTED_END_DATE).get(), END); assertEquals(explain.get(ExplainKey.DAYS).get().intValue(), (int) DAYS.between(START_ADJUSTED, END_ADJUSTED)); assertEquals(explain.get(ExplainKey.DISCOUNT_FACTOR).get(), DSC_FACTORS.discountFactor(END_ADJUSTED)); assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().getAmount(), FIXED_RATE * NOTIONAL * YEAR_FRACTION, NOTIONAL * TOL); assertEquals(explain.get(ExplainKey.PRESENT_VALUE).get().getAmount(), FIXED_RATE * NOTIONAL * YEAR_FRACTION * DSC_FACTORS.discountFactor(END_ADJUSTED), NOTIONAL * TOL); }
public void test_explainPresentValueWithSpread() { ExplainMapBuilder builder = ExplainMap.builder(); PRICER.explainPresentValueWithSpread( PAYMENT_PERIOD, ISSUER_CURVE, builder, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); ExplainMap explain = builder.build(); assertEquals(explain.get(ExplainKey.ENTRY_TYPE).get(), "FixedCouponBondPaymentPeriod"); assertEquals(explain.get(ExplainKey.PAYMENT_DATE).get(), PAYMENT_PERIOD.getPaymentDate()); assertEquals(explain.get(ExplainKey.PAYMENT_CURRENCY).get(), PAYMENT_PERIOD.getCurrency()); assertEquals(explain.get(ExplainKey.START_DATE).get(), START_ADJUSTED); assertEquals(explain.get(ExplainKey.UNADJUSTED_START_DATE).get(), START); assertEquals(explain.get(ExplainKey.END_DATE).get(), END_ADJUSTED); assertEquals(explain.get(ExplainKey.UNADJUSTED_END_DATE).get(), END); assertEquals(explain.get(ExplainKey.DAYS).get().intValue(), (int) DAYS.between(START_ADJUSTED, END_ADJUSTED)); assertEquals(explain.get(ExplainKey.DISCOUNT_FACTOR).get(), DSC_FACTORS.discountFactorWithSpread(END_ADJUSTED, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR)); assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().getAmount(), FIXED_RATE * NOTIONAL * YEAR_FRACTION, NOTIONAL * TOL); assertEquals(explain.get(ExplainKey.PRESENT_VALUE).get().getAmount(), FIXED_RATE * NOTIONAL * YEAR_FRACTION * DSC_FACTORS.discountFactorWithSpread(END_ADJUSTED, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR), NOTIONAL * TOL); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 575402001: // currency return ((FixedCouponBondPaymentPeriod) bean).getCurrency(); case 1585636160: // notional return ((FixedCouponBondPaymentPeriod) bean).getNotional(); case -2129778896: // startDate return ((FixedCouponBondPaymentPeriod) bean).getStartDate(); case -1607727319: // endDate return ((FixedCouponBondPaymentPeriod) bean).getEndDate(); case 1457691881: // unadjustedStartDate return ((FixedCouponBondPaymentPeriod) bean).getUnadjustedStartDate(); case 31758114: // unadjustedEndDate return ((FixedCouponBondPaymentPeriod) bean).getUnadjustedEndDate(); case -878940481: // detachmentDate return ((FixedCouponBondPaymentPeriod) bean).getDetachmentDate(); case 747425396: // fixedRate return ((FixedCouponBondPaymentPeriod) bean).getFixedRate(); case -1731780257: // yearFraction return ((FixedCouponBondPaymentPeriod) bean).getYearFraction(); } return super.propertyGet(bean, propertyName, quiet); }
/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(FixedCouponBondPaymentPeriod beanToCopy) { this.currency = beanToCopy.getCurrency(); this.notional = beanToCopy.getNotional(); this.startDate = beanToCopy.getStartDate(); this.endDate = beanToCopy.getEndDate(); this.unadjustedStartDate = beanToCopy.getUnadjustedStartDate(); this.unadjustedEndDate = beanToCopy.getUnadjustedEndDate(); this.detachmentDate = beanToCopy.getDetachmentDate(); this.fixedRate = beanToCopy.getFixedRate(); this.yearFraction = beanToCopy.getYearFraction(); }
.yearFraction(YEAR_FRACTION) .build(); assertEquals(test.getCurrency(), USD); assertEquals(test.getUnadjustedStartDate(), START); assertEquals(test.getStartDate(), START_ADJUSTED); ImmutableSet.Builder<Index> builder = ImmutableSet.builder(); test.collectIndices(builder); assertEquals(test.getCurrency(), USD); assertEquals(test.getUnadjustedStartDate(), START); assertEquals(test.getStartDate(), START_ADJUSTED);
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); }
/** * Explains the present value of a single fixed coupon payment period. * <p> * This adds information to the {@link ExplainMapBuilder} to aid understanding of the calculation. * * @param period the period to price * @param discountFactors the discount factor provider * @param builder the builder to populate */ public void explainPresentValue( FixedCouponBondPaymentPeriod period, IssuerCurveDiscountFactors discountFactors, ExplainMapBuilder builder) { Currency currency = period.getCurrency(); LocalDate paymentDate = period.getPaymentDate(); explainBasics(period, builder, currency, paymentDate); if (paymentDate.isBefore(discountFactors.getValuationDate())) { builder.put(ExplainKey.COMPLETED, Boolean.TRUE); builder.put(ExplainKey.FORECAST_VALUE, CurrencyAmount.zero(currency)); builder.put(ExplainKey.PRESENT_VALUE, CurrencyAmount.zero(currency)); } else { builder.put(ExplainKey.DISCOUNT_FACTOR, discountFactors.discountFactor(paymentDate)); builder.put(ExplainKey.FORECAST_VALUE, CurrencyAmount.of(currency, forecastValue(period, discountFactors))); builder.put(ExplainKey.PRESENT_VALUE, CurrencyAmount.of(currency, presentValue(period, discountFactors))); } }
int periodsPerYear) { Currency currency = period.getCurrency(); LocalDate paymentDate = period.getPaymentDate(); explainBasics(period, builder, currency, paymentDate);