public void test_presentValueWithZSpread_exCoupon() { CurrencyAmount computed = PRICER.presentValueWithZSpread( PRODUCT_EX_COUPON, RATES_PROVIDER, ISSUER_RATES_PROVIDER, Z_SPREAD, CONTINUOUS, 0); double expected = PERIOD_PRICER.presentValueWithZSpread( PRODUCT_EX_COUPON.getNominalPayment(), RATES_PROVIDER, ISSUER_DISCOUNT_FACTORS, Z_SPREAD, CONTINUOUS, 0); int size = PRODUCT_EX_COUPON.getPeriodicPayments().size(); for (int i = 17; i < size; ++i) { // in ex-coupon period CapitalIndexedBondPaymentPeriod payment = PRODUCT_EX_COUPON.getPeriodicPayments().get(i); expected += PERIOD_PRICER.presentValueWithZSpread( payment, RATES_PROVIDER, ISSUER_DISCOUNT_FACTORS, Z_SPREAD, CONTINUOUS, 0); } assertEquals(computed.getAmount(), expected, TOL * NOTIONAL); }
public void test_presentValue() { CurrencyAmount computed = PRICER.presentValue(PRODUCT, RATES_PROVIDER, ISSUER_RATES_PROVIDER); double expected = PERIOD_PRICER.presentValue(PRODUCT.getNominalPayment(), RATES_PROVIDER, ISSUER_DISCOUNT_FACTORS); int size = PRODUCT.getPeriodicPayments().size(); for (int i = 16; i < size; ++i) { CapitalIndexedBondPaymentPeriod payment = PRODUCT.getPeriodicPayments().get(i); expected += PERIOD_PRICER.presentValue(payment, RATES_PROVIDER, ISSUER_DISCOUNT_FACTORS); } assertEquals(computed.getAmount(), expected, TOL * NOTIONAL); }
public void test_presentValue_exCoupon() { CurrencyAmount computed = PRICER.presentValue(PRODUCT_EX_COUPON, RATES_PROVIDER, ISSUER_RATES_PROVIDER); double expected = PERIOD_PRICER.presentValue( PRODUCT_EX_COUPON.getNominalPayment(), RATES_PROVIDER, ISSUER_DISCOUNT_FACTORS); int size = PRODUCT_EX_COUPON.getPeriodicPayments().size(); for (int i = 17; i < size; ++i) { // in ex-coupon period CapitalIndexedBondPaymentPeriod payment = PRODUCT_EX_COUPON.getPeriodicPayments().get(i); expected += PERIOD_PRICER.presentValue(payment, RATES_PROVIDER, ISSUER_DISCOUNT_FACTORS); } assertEquals(computed.getAmount(), expected, TOL * NOTIONAL); }
public void test_presentValueWithZSpread() { CurrencyAmount computed = PRICER.presentValueWithZSpread( PRODUCT, RATES_PROVIDER, ISSUER_RATES_PROVIDER, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); double expected = PERIOD_PRICER.presentValueWithZSpread(PRODUCT.getNominalPayment(), RATES_PROVIDER, ISSUER_DISCOUNT_FACTORS, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); int size = PRODUCT.getPeriodicPayments().size(); for (int i = 16; i < size; ++i) { CapitalIndexedBondPaymentPeriod payment = PRODUCT.getPeriodicPayments().get(i); expected += PERIOD_PRICER.presentValueWithZSpread( payment, RATES_PROVIDER, ISSUER_DISCOUNT_FACTORS, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); } assertEquals(computed.getAmount(), expected, TOL * NOTIONAL); }
/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(ResolvedCapitalIndexedBond beanToCopy) { this.securityId = beanToCopy.getSecurityId(); this.nominalPayment = beanToCopy.getNominalPayment(); this.periodicPayments = beanToCopy.getPeriodicPayments(); this.frequency = beanToCopy.getFrequency(); this.rollConvention = beanToCopy.getRollConvention(); this.dayCount = beanToCopy.getDayCount(); this.yieldConvention = beanToCopy.getYieldConvention(); this.legalEntityId = beanToCopy.getLegalEntityId(); this.settlementDateOffset = beanToCopy.getSettlementDateOffset(); this.rateCalculation = beanToCopy.getRateCalculation(); }
public void test_builder() { ResolvedCapitalIndexedBond test = sut(); assertEquals(test.getCurrency(), USD); assertEquals(test.getDayCount(), ACT_ACT_ISDA); assertEquals(test.getStartDate(), PERIODIC[0].getStartDate()); assertEquals(test.getEndDate(), PERIODIC[3].getEndDate()); assertEquals(test.getUnadjustedStartDate(), PERIODIC[0].getUnadjustedStartDate()); assertEquals(test.getUnadjustedEndDate(), PERIODIC[3].getUnadjustedEndDate()); assertEquals(test.getLegalEntityId(), LEGAL_ENTITY); assertEquals(test.getNominalPayment(), NOMINAL); assertEquals(test.getNotional(), NOTIONAL); assertEquals(test.getPeriodicPayments().toArray(), PERIODIC); assertEquals(test.getSettlementDateOffset(), SETTLE_OFFSET); assertEquals(test.getYieldConvention(), US_IL_REAL); assertEquals(test.hasExCouponPeriod(), false); assertEquals(test.getFirstIndexValue(), RATE_CALC.getFirstIndexValue().getAsDouble()); assertEquals(test.findPeriod(PERIODIC[0].getUnadjustedStartDate()), Optional.of(test.getPeriodicPayments().get(0))); assertEquals(test.findPeriod(LocalDate.MIN), Optional.empty()); assertEquals(test.findPeriodIndex(PERIODIC[0].getUnadjustedStartDate()), OptionalInt.of(0)); assertEquals(test.findPeriodIndex(PERIODIC[1].getUnadjustedStartDate()), OptionalInt.of(1)); assertEquals(test.findPeriodIndex(LocalDate.MIN), OptionalInt.empty()); assertEquals( test.calculateSettlementDateFromValuation(date(2015, 6, 30), REF_DATA), SETTLE_OFFSET.adjust(date(2015, 6, 30), REF_DATA)); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 1574023291: // securityId return ((ResolvedCapitalIndexedBond) bean).getSecurityId(); case -44199542: // nominalPayment return ((ResolvedCapitalIndexedBond) bean).getNominalPayment(); case -367345944: // periodicPayments return ((ResolvedCapitalIndexedBond) bean).getPeriodicPayments(); case -70023844: // frequency return ((ResolvedCapitalIndexedBond) bean).getFrequency(); case -10223666: // rollConvention return ((ResolvedCapitalIndexedBond) bean).getRollConvention(); case 1905311443: // dayCount return ((ResolvedCapitalIndexedBond) bean).getDayCount(); case -1895216418: // yieldConvention return ((ResolvedCapitalIndexedBond) bean).getYieldConvention(); case 866287159: // legalEntityId return ((ResolvedCapitalIndexedBond) bean).getLegalEntityId(); case 135924714: // settlementDateOffset return ((ResolvedCapitalIndexedBond) bean).getSettlementDateOffset(); case -521703991: // rateCalculation return ((ResolvedCapitalIndexedBond) bean).getRateCalculation(); } return super.propertyGet(bean, propertyName, quiet); }
PointSensitivityBuilder presentValueSensitivity( ResolvedCapitalIndexedBond bond, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider, LocalDate referenceDate) { IssuerCurveDiscountFactors issuerDf = issuerCurveDf(bond, discountingProvider); PointSensitivityBuilder pointNominal = periodPricer.presentValueSensitivity(bond.getNominalPayment(), ratesProvider, issuerDf); PointSensitivityBuilder pointCoupon = PointSensitivityBuilder.none(); for (CapitalIndexedBondPaymentPeriod period : bond.getPeriodicPayments()) { if ((bond.hasExCouponPeriod() && period.getDetachmentDate().isAfter(referenceDate)) || (!bond.hasExCouponPeriod() && period.getPaymentDate().isAfter(referenceDate))) { pointCoupon = pointCoupon.combinedWith( periodPricer.presentValueSensitivity(period, ratesProvider, issuerDf)); } } return pointNominal.combinedWith(pointCoupon); }
/** * Calculates the current cash of the bond product. * * @param bond the product * @param ratesProvider the rates provider, used to determine price index values * @param settlementDate the settlement date * @return the current cash of the product */ public CurrencyAmount currentCash( ResolvedCapitalIndexedBond bond, RatesProvider ratesProvider, LocalDate settlementDate) { LocalDate valuationDate = ratesProvider.getValuationDate(); Currency currency = bond.getCurrency(); CurrencyAmount currentCash = CurrencyAmount.zero(currency); if (settlementDate.isBefore(valuationDate)) { double cashCoupon = bond.hasExCouponPeriod() ? 0d : currentCashPayment(bond, ratesProvider, valuationDate); CapitalIndexedBondPaymentPeriod nominal = bond.getNominalPayment(); double cashNominal = nominal.getPaymentDate().isEqual(valuationDate) ? periodPricer.forecastValue(nominal, ratesProvider) : 0d; currentCash = currentCash.plus(CurrencyAmount.of(currency, cashCoupon + cashNominal)); } return currentCash; }
CurrencyAmount presentValue( ResolvedCapitalIndexedBond bond, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider, LocalDate referenceDate) { IssuerCurveDiscountFactors issuerDf = issuerCurveDf(bond, discountingProvider); double pvNominal = periodPricer.presentValue(bond.getNominalPayment(), ratesProvider, issuerDf); double pvCoupon = 0d; for (CapitalIndexedBondPaymentPeriod period : bond.getPeriodicPayments()) { if ((bond.hasExCouponPeriod() && period.getDetachmentDate().isAfter(referenceDate)) || (!bond.hasExCouponPeriod() && period.getPaymentDate().isAfter(referenceDate))) { pvCoupon += periodPricer.presentValue(period, ratesProvider, issuerDf); } } return CurrencyAmount.of(bond.getCurrency(), pvCoupon + pvNominal); }
PointSensitivityBuilder presentValueSensitivityWithZSpread( ResolvedCapitalIndexedBond bond, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider, LocalDate referenceDate, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { IssuerCurveDiscountFactors issuerDf = issuerCurveDf(bond, discountingProvider); PointSensitivityBuilder pointNominal = periodPricer.presentValueSensitivityWithZSpread( bond.getNominalPayment(), ratesProvider, issuerDf, zSpread, compoundedRateType, periodsPerYear); PointSensitivityBuilder pointCoupon = PointSensitivityBuilder.none(); for (CapitalIndexedBondPaymentPeriod period : bond.getPeriodicPayments()) { if ((bond.hasExCouponPeriod() && period.getDetachmentDate().isAfter(referenceDate)) || (!bond.hasExCouponPeriod() && period.getPaymentDate().isAfter(referenceDate))) { pointCoupon = pointCoupon.combinedWith(periodPricer.presentValueSensitivityWithZSpread( period, ratesProvider, issuerDf, zSpread, compoundedRateType, periodsPerYear)); } } return pointNominal.combinedWith(pointCoupon); }
CurrencyAmount presentValueWithZSpread( ResolvedCapitalIndexedBond bond, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider, LocalDate referenceDate, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { IssuerCurveDiscountFactors issuerDf = issuerCurveDf(bond, discountingProvider); double pvNominal = periodPricer.presentValueWithZSpread( bond.getNominalPayment(), ratesProvider, issuerDf, zSpread, compoundedRateType, periodsPerYear); double pvCoupon = 0d; for (CapitalIndexedBondPaymentPeriod period : bond.getPeriodicPayments()) { if ((bond.hasExCouponPeriod() && period.getDetachmentDate().isAfter(referenceDate)) || (!bond.hasExCouponPeriod() && period.getPaymentDate().isAfter(referenceDate))) { pvCoupon += periodPricer.presentValueWithZSpread( period, ratesProvider, issuerDf, zSpread, compoundedRateType, periodsPerYear); } } return CurrencyAmount.of(bond.getCurrency(), pvCoupon + pvNominal); }