public void test_forecastValue() { double computed = PRICER.forecastValue(PAYMENT_PERIOD, ISSUER_CURVE); double expected = FIXED_RATE * NOTIONAL * YEAR_FRACTION; assertEquals(computed, expected); }
public void test_presentValue_past() { double computed = PRICER.presentValue(PAYMENT_PERIOD, ISSUER_CURVE_AFTER); assertEquals(computed, 0d); }
public void test_presentValueSensitivity_past() { PointSensitivityBuilder computed = PRICER.presentValueSensitivity(PAYMENT_PERIOD, ISSUER_CURVE_AFTER); assertEquals(computed, PointSensitivityBuilder.none()); }
/** * 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))); } }
explainBasics(period, builder, currency, paymentDate); if (paymentDate.isBefore(discountFactors.getValuationDate())) { builder.put(ExplainKey.COMPLETED, Boolean.TRUE); builder.put(ExplainKey.DISCOUNT_FACTOR, discountFactors.getDiscountFactors() .discountFactorWithSpread(paymentDate, zSpread, compoundedRateType, periodsPerYear)); builder.put(ExplainKey.FORECAST_VALUE, CurrencyAmount.of(currency, forecastValue(period, discountFactors))); builder.put(ExplainKey.PRESENT_VALUE, CurrencyAmount.of(currency, presentValueWithSpread(period, discountFactors, zSpread, compoundedRateType, periodsPerYear)));
public void test_presentValueWithSpread_past() { double computed = PRICER.presentValueWithSpread( PAYMENT_PERIOD, ISSUER_CURVE_AFTER, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); assertEquals(computed, 0d); }
double accruedInterest1 = PRODUCT_PRICER.accruedInterest(PRODUCT, standardSettlement1); double basePv1 = cleanPrice * df1 * NOTIONAL + accruedInterest1 * df1; double pvExtra1 = COUPON_PRICER.presentValue(periodExtra, provider1.issuerCurveDiscountFactors(ISSUER_ID, EUR)); double pvExtra1Continuous = COUPON_PRICER.presentValueWithSpread( periodExtra, provider1.issuerCurveDiscountFactors(ISSUER_ID, EUR), Z_SPREAD, CONTINUOUS, 0); double pvExtra1Periodic = COUPON_PRICER.presentValueWithSpread( periodExtra, provider1.issuerCurveDiscountFactors(ISSUER_ID, EUR), Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); CurrencyAmount computed1 = TRADE_PRICER_NO_UPFRONT.presentValueFromCleanPrice(trade1, provider1, REF_DATA, cleanPrice); double accruedInterest4 = PRODUCT_PRICER.accruedInterest(PRODUCT, standardSettlement4); double basePv4 = cleanPrice * df4 * NOTIONAL + accruedInterest4 * df4; double pvExtra4 = COUPON_PRICER.presentValue(periodExtra, PROVIDER_BEFORE.issuerCurveDiscountFactors(ISSUER_ID, EUR)); double pvExtra4Continuous = COUPON_PRICER.presentValueWithSpread( periodExtra, PROVIDER_BEFORE.issuerCurveDiscountFactors(ISSUER_ID, EUR), Z_SPREAD, CONTINUOUS, 0); double pvExtra4Periodic = COUPON_PRICER.presentValueWithSpread(periodExtra, PROVIDER_BEFORE.issuerCurveDiscountFactors(ISSUER_ID, EUR), Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); CurrencyAmount computed4 = TRADE_PRICER_NO_UPFRONT.presentValueFromCleanPrice(trade4, PROVIDER_BEFORE, REF_DATA, cleanPrice);
public void test_presentValueSensitivityWithSpread_past() { PointSensitivityBuilder computed = PRICER.presentValueSensitivityWithSpread( PAYMENT_PERIOD, ISSUER_CURVE_AFTER, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); assertEquals(computed, PointSensitivityBuilder.none()); }
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_forecastValueSensitivity() { PointSensitivityBuilder computed = PRICER.forecastValueSensitivity(PAYMENT_PERIOD, ISSUER_CURVE); assertEquals(computed, PointSensitivityBuilder.none()); }
public void test_presentValueWithSpread() { double computed = PRICER.presentValueWithSpread( PAYMENT_PERIOD, ISSUER_CURVE, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); double expected = FIXED_RATE * NOTIONAL * YEAR_FRACTION * DSC_FACTORS.discountFactorWithSpread(END_ADJUSTED, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); assertEquals(computed, expected); }
double accruedInterest1 = PRODUCT_PRICER.accruedInterest(PRODUCT_NO_EXCOUPON, standardSettlement1); double basePv1 = cleanPrice * df1 * NOTIONAL + accruedInterest1 * df1; double pvExtra1 = COUPON_PRICER.presentValue(periodExtra, provider1.issuerCurveDiscountFactors(ISSUER_ID, EUR)); double pvExtra1Continuous = COUPON_PRICER.presentValueWithSpread( periodExtra, provider1.issuerCurveDiscountFactors(ISSUER_ID, EUR), Z_SPREAD, CONTINUOUS, 0); double pvExtra1Periodic = COUPON_PRICER.presentValueWithSpread( periodExtra, provider1.issuerCurveDiscountFactors(ISSUER_ID, EUR), Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); CurrencyAmount computed1 = TRADE_PRICER_NO_UPFRONT.presentValueFromCleanPrice(trade1, provider1, REF_DATA, cleanPrice); double accruedInterest4 = PRODUCT_PRICER.accruedInterest(PRODUCT_NO_EXCOUPON, standardSettlement4); double basePv4 = cleanPrice * df4 * NOTIONAL + accruedInterest4 * df4; double pvExtra4 = COUPON_PRICER.presentValue(periodExtra, PROVIDER_BEFORE.issuerCurveDiscountFactors(ISSUER_ID, EUR)); double pvExtra4Continuous = COUPON_PRICER.presentValueWithSpread(periodExtra, PROVIDER_BEFORE.issuerCurveDiscountFactors(ISSUER_ID, EUR), Z_SPREAD, CONTINUOUS, 0); double pvExtra4Periodic = COUPON_PRICER.presentValueWithSpread(periodExtra, PROVIDER_BEFORE.issuerCurveDiscountFactors(ISSUER_ID, EUR), Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); CurrencyAmount computed4 = TRADE_PRICER_NO_UPFRONT.presentValueFromCleanPrice(trade4, PROVIDER_BEFORE, REF_DATA, cleanPrice);
public void test_presentValueSensitivityWithSpread() { PointSensitivityBuilder computed = PRICER.presentValueSensitivityWithSpread( PAYMENT_PERIOD, ISSUER_CURVE, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); PointSensitivityBuilder expected = IssuerCurveZeroRateSensitivity.of( DSC_FACTORS.zeroRatePointSensitivityWithSpread(END_ADJUSTED, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR) .multipliedBy(FIXED_RATE * NOTIONAL * YEAR_FRACTION), GROUP); assertEquals(computed, expected); }
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); }
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); }
private CurrencyAmount presentValueCouponFromZSpread( ResolvedFixedCouponBond bond, IssuerCurveDiscountFactors discountFactors, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear, LocalDate referenceDate) { double total = 0d; for (FixedCouponBondPaymentPeriod period : bond.getPeriodicPayments()) { if (period.getDetachmentDate().isAfter(referenceDate)) { total += periodPricer.presentValueWithSpread(period, discountFactors, zSpread, compoundedRateType, periodsPerYear); } } return CurrencyAmount.of(bond.getCurrency(), total); }
public void test_presentValue() { double computed = PRICER.presentValue(PAYMENT_PERIOD, ISSUER_CURVE); double expected = FIXED_RATE * NOTIONAL * YEAR_FRACTION * DSC_FACTORS.discountFactor(END_ADJUSTED); assertEquals(computed, expected); }
private PointSensitivityBuilder presentValueSensitivityCoupon( ResolvedFixedCouponBond bond, IssuerCurveDiscountFactors discountFactors, LocalDate referenceDate) { PointSensitivityBuilder builder = PointSensitivityBuilder.none(); for (FixedCouponBondPaymentPeriod period : bond.getPeriodicPayments()) { if (period.getDetachmentDate().isAfter(referenceDate)) { builder = builder.combinedWith(periodPricer.presentValueSensitivity(period, discountFactors)); } } return builder; }
private PointSensitivityBuilder presentValueSensitivityCouponFromZSpread( ResolvedFixedCouponBond bond, IssuerCurveDiscountFactors discountFactors, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear, LocalDate referenceDate) { PointSensitivityBuilder builder = PointSensitivityBuilder.none(); for (FixedCouponBondPaymentPeriod period : bond.getPeriodicPayments()) { if (period.getDetachmentDate().isAfter(referenceDate)) { builder = builder.combinedWith(periodPricer.presentValueSensitivityWithSpread( period, discountFactors, zSpread, compoundedRateType, periodsPerYear)); } } return builder; }