/** * Calculates the currency exposure of the bond product with z-spread. * <p> * The z-spread is a parallel shift applied to continuously compounded rates or * periodic compounded rates of the issuer discounting curve. * * @param bond the product * @param ratesProvider the rates provider, used to determine price index values * @param discountingProvider the discount factors provider * @param referenceDate the reference date * @param zSpread the z-spread * @param compoundedRateType the compounded rate type * @param periodsPerYear the number of periods per year * @return the currency exposure of the product */ public MultiCurrencyAmount currencyExposureWithZSpread( ResolvedCapitalIndexedBond bond, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider, LocalDate referenceDate, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { return MultiCurrencyAmount.of(presentValueWithZSpread(bond, ratesProvider, discountingProvider, referenceDate, zSpread, compoundedRateType, periodsPerYear)); }
@Override public Double apply(Double z) { return presentValueWithZSpread(bond, ratesProvider, discountingProvider, settlementDate, z, compoundedRateType, periodsPerYear).getAmount() - presentValue.getAmount(); } };
public void test_zSpreadFromCurvesAndPv() { CurrencyAmount pv = PRICER.presentValueWithZSpread( PRODUCT, RATES_PROVIDER, ISSUER_RATES_PROVIDER, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); double computed = PRICER.zSpreadFromCurvesAndPv( PRODUCT, RATES_PROVIDER, ISSUER_RATES_PROVIDER, REF_DATA, pv, PERIODIC, PERIOD_PER_YEAR); assertEquals(computed, Z_SPREAD, TOL); }
public void test_zSpreadFromCurvesAndPv_exCoupon() { CurrencyAmount pv = PRICER.presentValueWithZSpread( PRODUCT_EX_COUPON, RATES_PROVIDER, ISSUER_RATES_PROVIDER, Z_SPREAD, CONTINUOUS, 0); double computed = PRICER.zSpreadFromCurvesAndPv( PRODUCT_EX_COUPON, RATES_PROVIDER, ISSUER_RATES_PROVIDER, REF_DATA, pv, CONTINUOUS, 0); assertEquals(computed, Z_SPREAD, TOL); }
double dirtyNominalPriceFromCurvesWithZSpread( ResolvedCapitalIndexedBond bond, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider, LocalDate settlementDate, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { CurrencyAmount pv = presentValueWithZSpread( bond, ratesProvider, discountingProvider, settlementDate, zSpread, compoundedRateType, periodsPerYear); RepoCurveDiscountFactors repoDf = repoCurveDf(bond, discountingProvider); double df = repoDf.discountFactor(settlementDate); double notional = bond.getNotional(); return pv.getAmount() / (df * notional); }
private CurrencyParameterSensitivities fdPvSensitivityWithZSpread( ResolvedCapitalIndexedBond product, ImmutableRatesProvider ratesProvider, LegalEntityDiscountingProvider issuerRatesProvider, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { CurrencyParameterSensitivities sensi1 = FD_CAL.sensitivity( issuerRatesProvider, p -> PRICER.presentValueWithZSpread(product, ratesProvider, p, zSpread, compoundedRateType, periodsPerYear)); CurrencyParameterSensitivities sensi2 = FD_CAL.sensitivity( ratesProvider, p -> PRICER.presentValueWithZSpread(product, p, issuerRatesProvider, zSpread, compoundedRateType, periodsPerYear)); return sensi1.combinedWith(sensi2); }
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); }
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_dirtyNominalPriceFromCurvesWithZSpread() { double computed = PRICER.dirtyNominalPriceFromCurvesWithZSpread( PRODUCT, RATES_PROVIDER, ISSUER_RATES_PROVIDER, REF_DATA, Z_SPREAD, CONTINUOUS, 0); LocalDate settlement = SETTLE_OFFSET.adjust(VALUATION, REF_DATA); double df = ISSUER_RATES_PROVIDER.repoCurveDiscountFactors(SECURITY_ID, LEGAL_ENTITY, USD).discountFactor(settlement); double expected = PRICER.presentValueWithZSpread(PRODUCT, RATES_PROVIDER, ISSUER_RATES_PROVIDER, settlement, Z_SPREAD, CONTINUOUS, 0).getAmount() / NOTIONAL / df; assertEquals(computed, expected, TOL); }
CurrencyAmount pvProduct = productPricer.presentValueWithZSpread( trade.getProduct(), ratesProvider, discountingProvider,
public void test_dirtyNominalPriceFromCurvesWithZSpread_exCoupon() { double computed = PRICER.dirtyNominalPriceFromCurvesWithZSpread( PRODUCT_EX_COUPON, RATES_PROVIDER, ISSUER_RATES_PROVIDER, REF_DATA, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); LocalDate settlement = SETTLE_OFFSET.adjust(VALUATION, REF_DATA); double df = ISSUER_RATES_PROVIDER.repoCurveDiscountFactors(SECURITY_ID, LEGAL_ENTITY, USD).discountFactor(settlement); double expected = PRICER.presentValueWithZSpread(PRODUCT_EX_COUPON, RATES_PROVIDER, ISSUER_RATES_PROVIDER, settlement, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR).getAmount() / NOTIONAL / df; assertEquals(computed, expected, TOL); }
public void test_presentValueWithZSpread_late() { CurrencyAmount computed = PRICER.presentValueWithZSpread( TRADE_LATE, RATES_PROVIDER, ISSUER_RATES_PROVIDER, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); double expected1 = QUANTITY * PRODUCT_PRICER.presentValueWithZSpread( RPRODUCT, RATES_PROVIDER, ISSUER_RATES_PROVIDER, SETTLEMENT_LATE, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR).getAmount(); double df = ISSUER_RATES_PROVIDER.repoCurveDiscountFactors(SECURITY_ID, LEGAL_ENTITY, USD) .discountFactor(SETTLEMENT_LATE); double expected2 = df * PERIOD_PRICER.forecastValue(SETTLE_PERIOD_LATE, RATES_PROVIDER); assertEquals(computed.getAmount(), expected1 + expected2, NOTIONAL * QUANTITY * TOL); }
public void test_presentValueWithZSpread_standard() { CurrencyAmount computed = PRICER.presentValueWithZSpread( TRADE_STANDARD, RATES_PROVIDER, ISSUER_RATES_PROVIDER, Z_SPREAD, CONTINUOUS, 0); double expected1 = QUANTITY * PRODUCT_PRICER.presentValueWithZSpread( RPRODUCT, RATES_PROVIDER, ISSUER_RATES_PROVIDER, SETTLEMENT_STANDARD, Z_SPREAD, CONTINUOUS, 0).getAmount(); double df = ISSUER_RATES_PROVIDER.repoCurveDiscountFactors(SECURITY_ID, LEGAL_ENTITY, USD) .discountFactor(SETTLEMENT_STANDARD); double expected2 = df * PERIOD_PRICER.forecastValue(SETTLE_PERIOD_STANDARD, RATES_PROVIDER); assertEquals(computed.getAmount(), expected1 + expected2, NOTIONAL * QUANTITY * TOL); }
public void test_currencyExposureWithZSpread() { MultiCurrencyAmount computed = PRICER.currencyExposureWithZSpread( PRODUCT, RATES_PROVIDER, ISSUER_RATES_PROVIDER, VALUATION, Z_SPREAD, CONTINUOUS, 0); PointSensitivities point = PRICER.presentValueSensitivityWithZSpread( PRODUCT, RATES_PROVIDER, ISSUER_RATES_PROVIDER, Z_SPREAD, CONTINUOUS, 0).build(); MultiCurrencyAmount expected = RATES_PROVIDER.currencyExposure(point).plus( PRICER.presentValueWithZSpread(PRODUCT, RATES_PROVIDER, ISSUER_RATES_PROVIDER, Z_SPREAD, CONTINUOUS, 0)); assertEquals(computed.getCurrencies().size(), 1); assertEquals(computed.getAmount(USD).getAmount(), expected.getAmount(USD).getAmount(), NOTIONAL * TOL); }
public void test_currencyExposureWithZSpread_exCoupon() { MultiCurrencyAmount computed = PRICER.currencyExposureWithZSpread( PRODUCT_EX_COUPON, RATES_PROVIDER, ISSUER_RATES_PROVIDER, VALUATION, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); PointSensitivities point = PRICER.presentValueSensitivityWithZSpread( PRODUCT_EX_COUPON, RATES_PROVIDER, ISSUER_RATES_PROVIDER, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR).build(); MultiCurrencyAmount expected = RATES_PROVIDER.currencyExposure(point).plus(PRICER.presentValueWithZSpread( PRODUCT_EX_COUPON, RATES_PROVIDER, ISSUER_RATES_PROVIDER, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR)); assertEquals(computed.getCurrencies().size(), 1); assertEquals(computed.getAmount(USD).getAmount(), expected.getAmount(USD).getAmount(), NOTIONAL * TOL); }
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); }
CurrencyAmount pv = presentValueWithZSpread( bond, ratesProvider, discountingProvider, settlementDate, zSpread, compoundedRateType, periodsPerYear);