/** * Calculates the currency exposure of the fixed coupon bond trade. * * @param trade the trade * @param provider the discounting provider * @return the currency exposure of the fixed coupon bond trade */ public MultiCurrencyAmount currencyExposure(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider provider) { return MultiCurrencyAmount.of(presentValue(trade, provider)); }
public void test_presentValueSensitivityWithZSpread_continuous() { PointSensitivities pointTrade = TRADE_PRICER.presentValueSensitivityWithZSpread(TRADE, PROVIDER, Z_SPREAD, CONTINUOUS, 0); CurrencyParameterSensitivities computedTrade = PROVIDER.parameterSensitivity(pointTrade); CurrencyParameterSensitivities expectedTrade = FD_CAL.sensitivity( PROVIDER, (p) -> TRADE_PRICER.presentValueWithZSpread(TRADE, (p), Z_SPREAD, CONTINUOUS, 0)); assertTrue(computedTrade.equalWithTolerance(expectedTrade, 20d * NOTIONAL * QUANTITY * EPS)); }
private CurrencyAmount presentValuePayment(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider provider) { RepoCurveDiscountFactors repoDf = DiscountingFixedCouponBondProductPricer.repoCurveDf(trade.getProduct(), provider); Payment upfrontPayment = upfrontPayment(trade); return paymentPricer.presentValue(upfrontPayment, repoDf.getDiscountFactors()); }
/** * Calculates the present value of the fixed coupon bond trade. * <p> * The present value of the trade is the value on the valuation date. * The result is expressed using the payment currency of the bond. * <p> * Coupon payments of the underlying product are considered based on the settlement date of the trade. * * @param trade the trade * @param provider the discounting provider * @return the present value of the fixed coupon bond trade */ public CurrencyAmount presentValue(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider provider) { LocalDate settlementDate = settlementDate(trade, provider.getValuationDate()); CurrencyAmount pvProduct = productPricer.presentValue(trade.getProduct(), provider, settlementDate); return presentValueFromProductPresentValue(trade, provider, pvProduct); }
public void test_currencyExposureWithZSpread() { MultiCurrencyAmount ceComputed = TRADE_PRICER.currencyExposureWithZSpread( TRADE, PROVIDER, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); CurrencyAmount pv = TRADE_PRICER.presentValueWithZSpread(TRADE, PROVIDER, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); assertEquals(ceComputed, MultiCurrencyAmount.of(pv)); }
public void test_currencyExposure() { MultiCurrencyAmount ceComputed = TRADE_PRICER.currencyExposure(TRADE, PROVIDER); CurrencyAmount pv = TRADE_PRICER.presentValue(TRADE, PROVIDER); assertEquals(ceComputed, MultiCurrencyAmount.of(pv)); }
public void test_presentValueFromCleanPriceWithZSpread_continuous_coherency() { double priceDirty = PRODUCT_PRICER .dirtyPriceFromCurvesWithZSpread(PRODUCT, PROVIDER, REF_DATA, Z_SPREAD, CONTINUOUS, 0); LocalDate standardSettlementDate = PRODUCT.getSettlementDateOffset().adjust(PROVIDER.getValuationDate(), REF_DATA); double priceCleanComputed = PRODUCT_PRICER.cleanPriceFromDirtyPrice(PRODUCT, standardSettlementDate, priceDirty); CurrencyAmount pvCleanPrice = TRADE_PRICER.presentValueFromCleanPriceWithZSpread( TRADE, PROVIDER, REF_DATA, priceCleanComputed, Z_SPREAD, CONTINUOUS, 0); CurrencyAmount pvCurves = TRADE_PRICER.presentValueWithZSpread(TRADE, PROVIDER, Z_SPREAD, CONTINUOUS, 0); assertEquals(pvCleanPrice.getAmount(), pvCurves.getAmount(), NOTIONAL * TOL); }
/** * Calculates the currency exposure of the fixed coupon bond trade with z-spread. * * @param trade the trade * @param provider the discounting provider * @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 fixed coupon bond trade */ public MultiCurrencyAmount currencyExposureWithZSpread( ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider provider, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { return MultiCurrencyAmount.of(presentValueWithZSpread(trade, provider, zSpread, compoundedRateType, periodsPerYear)); }
public void test_presentValueFromCleanPrice_noExcoupon_coherency() { double priceDirty = PRODUCT_PRICER.dirtyPriceFromCurves(PRODUCT_NO_EXCOUPON, PROVIDER, REF_DATA); LocalDate standardSettlementDate = PRODUCT.getSettlementDateOffset().adjust(PROVIDER.getValuationDate(), REF_DATA); double priceCleanComputed = PRODUCT_PRICER.cleanPriceFromDirtyPrice(PRODUCT, standardSettlementDate, priceDirty); CurrencyAmount pvCleanPrice = TRADE_PRICER.presentValueFromCleanPrice( TRADE_NO_EXCOUPON, PROVIDER, REF_DATA, priceCleanComputed); CurrencyAmount pvCurves = TRADE_PRICER.presentValue(TRADE_NO_EXCOUPON, PROVIDER); assertEquals(pvCleanPrice.getAmount(), pvCurves.getAmount(), NOTIONAL * TOL); }
public void test_presentValueProductSensitivity_noExcoupon() { PointSensitivities pointTrade = TRADE_PRICER.presentValueSensitivity(TRADE_NO_EXCOUPON, PROVIDER); CurrencyParameterSensitivities computedTrade = PROVIDER.parameterSensitivity(pointTrade); CurrencyParameterSensitivities expectedTrade = FD_CAL.sensitivity( PROVIDER, (p) -> TRADE_PRICER.presentValue(TRADE_NO_EXCOUPON, (p))); assertTrue(computedTrade.equalWithTolerance(expectedTrade, 30d * NOTIONAL * QUANTITY * EPS)); }
LocalDate standardSettlementDate = standardSettlementDate(product, provider, refData); LocalDate tradeSettlementDate = settlementDate(trade, provider.getValuationDate()); Currency currency = product.getCurrency(); RepoCurveDiscountFactors repoDf = DiscountingFixedCouponBondProductPricer.repoCurveDf(product, provider); (cleanPrice * product.getNotional() + productPricer.accruedInterest(product, standardSettlementDate)) * df; if (standardSettlementDate.isEqual(tradeSettlementDate)) { return presentValueFromProductPresentValue(trade, provider, CurrencyAmount.of(currency, pvStandard)); pvDiff = -productPricer.presentValueCoupon(product, issuerDf, standardSettlementDate, tradeSettlementDate); return presentValueFromProductPresentValue(trade, provider, CurrencyAmount.of(currency, pvStandard + pvDiff));
/** * Calculates the current cash of the fixed coupon bond trade. * * @param trade the trade * @param valuationDate the valuation date * @return the current cash amount */ public CurrencyAmount currentCash(ResolvedFixedCouponBondTrade trade, LocalDate valuationDate) { Payment upfrontPayment = upfrontPayment(trade); Currency currency = upfrontPayment.getCurrency(); // assumes single currency is involved in trade CurrencyAmount currentCash = CurrencyAmount.zero(currency); if (upfrontPayment.getDate().equals(valuationDate)) { currentCash = currentCash.plus(upfrontPayment.getValue()); } if (trade.getSettlement().isPresent()) { LocalDate settlementDate = trade.getSettlement().get().getSettlementDate(); ResolvedFixedCouponBond product = trade.getProduct(); if (!settlementDate.isAfter(valuationDate)) { double cashCoupon = product.hasExCouponPeriod() ? 0d : currentCashCouponPayment(product, valuationDate); Payment payment = product.getNominalPayment(); double cashNominal = payment.getDate().isEqual(valuationDate) ? payment.getAmount() : 0d; currentCash = currentCash.plus(CurrencyAmount.of(currency, (cashCoupon + cashNominal) * trade.getQuantity())); } } return currentCash; }
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); CurrencyAmount computed1Continuous = TRADE_PRICER_NO_UPFRONT.presentValueFromCleanPriceWithZSpread( trade1, provider1, REF_DATA, cleanPrice, Z_SPREAD, CONTINUOUS, 0); CurrencyAmount computed1Periodic = TRADE_PRICER_NO_UPFRONT.presentValueFromCleanPriceWithZSpread( trade1, provider1, REF_DATA, cleanPrice, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); assertEquals(computed1.getAmount(), QUANTITY * (basePv1 + pvExtra1), NOTIONAL * QUANTITY * TOL); .settlement(ResolvedFixedCouponBondSettlement.of(SETTLE_ON_DETACHMENT.plusDays(2), CLEAN_PRICE)) .build(); CurrencyAmount computed2 = TRADE_PRICER_NO_UPFRONT.presentValueFromCleanPrice(trade2, provider1, REF_DATA, cleanPrice); CurrencyAmount computed2Continuous = TRADE_PRICER_NO_UPFRONT.presentValueFromCleanPriceWithZSpread( trade2, provider1, REF_DATA, cleanPrice, Z_SPREAD, CONTINUOUS, 0); CurrencyAmount computed2Periodic = TRADE_PRICER_NO_UPFRONT.presentValueFromCleanPriceWithZSpread( trade2, provider1, REF_DATA, cleanPrice, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); assertEquals(computed2.getAmount(), QUANTITY * basePv1, NOTIONAL * QUANTITY * TOL); .settlement(ResolvedFixedCouponBondSettlement.of(SETTLE_ON_DETACHMENT.plusDays(7), CLEAN_PRICE)) .build(); CurrencyAmount computed3 = TRADE_PRICER_NO_UPFRONT.presentValueFromCleanPrice(trade3, provider1, REF_DATA, cleanPrice); CurrencyAmount computed3Continuous = TRADE_PRICER_NO_UPFRONT.presentValueFromCleanPriceWithZSpread( trade3, provider1, REF_DATA, cleanPrice, Z_SPREAD, CONTINUOUS, 0); CurrencyAmount computed3Periodic = TRADE_PRICER_NO_UPFRONT.presentValueFromCleanPriceWithZSpread( trade3, provider1, REF_DATA, cleanPrice, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); assertEquals(computed3.getAmount(), QUANTITY * basePv1, NOTIONAL * QUANTITY * TOL); double pvExtra4Periodic = COUPON_PRICER.presentValueWithSpread(periodExtra, PROVIDER_BEFORE.issuerCurveDiscountFactors(ISSUER_ID, EUR), Z_SPREAD, PERIODIC, PERIOD_PER_YEAR);
public void test_currentCash_valuationAtPayment() { LocalDate paymentDate = LocalDate.of(2016, 10, 12); CurrencyAmount ccComputed = TRADE_PRICER.currentCash(TRADE, paymentDate); assertEquals(ccComputed, CurrencyAmount.zero(EUR)); }
public void test_presentValueFromCleanPriceWithZSpread_periodic() { double cleanPrice = 0.985; CurrencyAmount computed = TRADE_PRICER.presentValueFromCleanPriceWithZSpread( TRADE, PROVIDER, REF_DATA, cleanPrice, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); LocalDate standardSettlement = PRODUCT.getSettlementDateOffset().adjust(VAL_DATE, REF_DATA); double df = ZeroRateDiscountFactors.of(EUR, VAL_DATE, CURVE_REPO).discountFactor(standardSettlement); double accruedInterest = PRODUCT_PRICER.accruedInterest(PRODUCT, standardSettlement); double pvPayment = PRICER_NOMINAL .presentValue(UPFRONT_PAYMENT, ZeroRateDiscountFactors.of(EUR, VAL_DATE, CURVE_REPO)).getAmount(); double expected = QUANTITY * (cleanPrice * df * NOTIONAL + accruedInterest * df) + pvPayment; assertEquals(computed.getCurrency(), EUR); assertEquals(computed.getAmount(), expected, NOTIONAL * QUANTITY * TOL); }
public void test_presentValueFromCleanPrice_noExcoupon() { double cleanPrice = 0.985; CurrencyAmount computed = TRADE_PRICER.presentValueFromCleanPrice(TRADE_NO_EXCOUPON, PROVIDER, REF_DATA, cleanPrice); LocalDate standardSettlement = PRODUCT_NO_EXCOUPON.getSettlementDateOffset().adjust(VAL_DATE, REF_DATA); double df = ZeroRateDiscountFactors.of(EUR, VAL_DATE, CURVE_REPO).discountFactor(standardSettlement); double accruedInterest = PRODUCT_PRICER.accruedInterest(PRODUCT_NO_EXCOUPON, standardSettlement); double pvPayment = PRICER_NOMINAL .presentValue(UPFRONT_PAYMENT, ZeroRateDiscountFactors.of(EUR, VAL_DATE, CURVE_REPO)).getAmount(); double expected = QUANTITY * (cleanPrice * df * NOTIONAL + accruedInterest * df) + pvPayment; assertEquals(computed.getCurrency(), EUR); assertEquals(computed.getAmount(), expected, NOTIONAL * QUANTITY * TOL); }
public void test_presentValueFromCleanPriceWithZSpread_continuous_noExcoupon_coherency() { double priceDirty = PRODUCT_PRICER.dirtyPriceFromCurvesWithZSpread( PRODUCT_NO_EXCOUPON, PROVIDER, REF_DATA, Z_SPREAD, CONTINUOUS, 0); LocalDate standardSettlementDate = PRODUCT.getSettlementDateOffset().adjust(PROVIDER.getValuationDate(), REF_DATA); double priceCleanComputed = PRODUCT_PRICER.cleanPriceFromDirtyPrice(PRODUCT, standardSettlementDate, priceDirty); CurrencyAmount pvCleanPrice = TRADE_PRICER.presentValueFromCleanPriceWithZSpread( TRADE_NO_EXCOUPON, PROVIDER, REF_DATA, priceCleanComputed, Z_SPREAD, CONTINUOUS, 0); CurrencyAmount pvCurves = TRADE_PRICER .presentValueWithZSpread(TRADE_NO_EXCOUPON, PROVIDER, Z_SPREAD, CONTINUOUS, 0); assertEquals(pvCleanPrice.getAmount(), pvCurves.getAmount(), NOTIONAL * TOL); }
public void test_presentValueWithZSpread_continuous() { CurrencyAmount computedTrade = TRADE_PRICER.presentValueWithZSpread( TRADE, PROVIDER, Z_SPREAD, CONTINUOUS, 0); CurrencyAmount computedProduct = PRODUCT_PRICER.presentValueWithZSpread(PRODUCT, PROVIDER, Z_SPREAD, CONTINUOUS, 0, SETTLEMENT); CurrencyAmount pvPayment = PRICER_NOMINAL.presentValue(UPFRONT_PAYMENT, ZeroRateDiscountFactors.of(EUR, VAL_DATE, CURVE_REPO)); assertEquals(computedTrade.getAmount(), computedProduct.multipliedBy(QUANTITY).plus(pvPayment).getAmount(), NOTIONAL * QUANTITY * TOL); }
public void test_presentValueFromCleanPrice_coherency() { double priceDirty = PRODUCT_PRICER.dirtyPriceFromCurves(PRODUCT, PROVIDER, REF_DATA); LocalDate standardSettlementDate = PRODUCT.getSettlementDateOffset().adjust(PROVIDER.getValuationDate(), REF_DATA); double priceCleanComputed = PRODUCT_PRICER.cleanPriceFromDirtyPrice(PRODUCT, standardSettlementDate, priceDirty); CurrencyAmount pvCleanPrice = TRADE_PRICER.presentValueFromCleanPrice(TRADE, PROVIDER, REF_DATA, priceCleanComputed); CurrencyAmount pvCurves = TRADE_PRICER.presentValue(TRADE, PROVIDER); assertEquals(pvCleanPrice.getAmount(), pvCurves.getAmount(), NOTIONAL * TOL); }
public void test_presentValueSensitivity() { PointSensitivities pointTrade = TRADE_PRICER.presentValueSensitivity(TRADE, PROVIDER); CurrencyParameterSensitivities computedTrade = PROVIDER.parameterSensitivity(pointTrade); CurrencyParameterSensitivities expectedTrade = FD_CAL.sensitivity(PROVIDER, (p) -> TRADE_PRICER.presentValue(TRADE, (p))); assertTrue(computedTrade.equalWithTolerance(expectedTrade, 30d * NOTIONAL * QUANTITY * EPS)); }