BondTransactionDiscountingMethod { public MultipleCurrencyAmount presentValueFromYield( final BondTransaction<? extends BondSecurity<? extends Payment, ? extends Coupon>> bond, final IssuerProviderInterface issuerMulticurves, final double yield) { ArgumentChecker.notNull(bond, "Bond"); ArgumentChecker.isTrue(bond instanceof BondFixedTransaction, "Present value from clean price only for fixed coupon bond"); final Currency ccy = bond.getBondTransaction().getCurrency(); final MulticurveProviderInterface multicurvesDecorated = new MulticurveProviderDiscountingDecoratedIssuer( issuerMulticurves, ccy, bond.getBondTransaction().getIssuerEntity()); final BondFixedTransaction bondFixed = (BondFixedTransaction) bond; final double dfSettle = issuerMulticurves.getMulticurveProvider(). getDiscountFactor(ccy, bondFixed.getBondStandard().getSettlementTime()); final double dirtyPrice = METHOD_BOND_SECURITY.dirtyPriceFromYield(bondFixed.getBondStandard(), yield); final MultipleCurrencyAmount pvPriceStandard = MultipleCurrencyAmount.of(ccy, dirtyPrice * dfSettle); final MultipleCurrencyAmount pvNominalStandard = bond.getBondStandard().getNominal().accept(PVDC, multicurvesDecorated); final MultipleCurrencyAmount pvCouponStandard = bond.getBondStandard().getCoupon().accept(PVDC, multicurvesDecorated); final MultipleCurrencyAmount pvDiscountingStandard = pvNominalStandard.plus(pvCouponStandard); final MultipleCurrencyAmount pvNominalTransaction = bond.getBondTransaction().getNominal().accept(PVDC, multicurvesDecorated); final MultipleCurrencyAmount pvCouponTransaction = bond.getBondTransaction().getCoupon().accept(PVDC, multicurvesDecorated); final MultipleCurrencyAmount pvDiscountingTransaction = pvNominalTransaction.plus(pvCouponTransaction); double settlementAmount = -bond.getTransactionPrice() * bond.getBondTransaction().getCoupon().getNthPayment(0).getNotional(); if (bond.getBondTransaction() instanceof BondFixedSecurity) { settlementAmount -= ((BondFixedSecurity) bond.getBondTransaction()).getAccruedInterest(); } settlementAmount *= bond.getQuantity(); final PaymentFixed settlement = new PaymentFixed(bond.getBondTransaction().getCurrency(), bond.getBondTransaction().getSettlementTime(), settlementAmount); final MultipleCurrencyAmount pvSettlement = settlement.accept(PVDC, issuerMulticurves.getMulticurveProvider()); return (pvDiscountingTransaction.plus(pvDiscountingStandard.multipliedBy(-1d)).plus(pvPriceStandard)). multipliedBy(bond.getQuantity()).plus(pvSettlement); } private  BondTransactionDiscountingMethod(); static BondTransactionDiscountingMethod getInstance(); MultipleCurrencyAmount presentValue(final BondFixedTransaction bond, 
      final IssuerProviderInterface issuerMulticurves); MultipleCurrencyAmount presentValue(final BondIborTransaction bond, 
      final IssuerProviderInterface issuerMulticurves); MultipleCurrencyAmount presentValueFromCleanPrice(
      final BondTransaction<? extends BondSecurity<? extends Payment, ? extends Coupon>> bond, 
          final IssuerProviderInterface issuerMulticurves, final double cleanPrice); MultipleCurrencyAmount presentValueFromYield(
      final BondTransaction<? extends BondSecurity<? extends Payment, ? extends Coupon>> bond, 
          final IssuerProviderInterface issuerMulticurves, final double yield); MultipleCurrencyMulticurveSensitivity presentValueCurveSensitivity(final BondFixedTransaction bond, 
      final IssuerProviderInterface issuerMulticurves); MultipleCurrencyMulticurveSensitivity presentValueCurveSensitivity(final BondIborTransaction bond, 
      final IssuerProviderInterface issuerMulticurves); double parSpread(final BondFixedTransaction bond, final IssuerProviderInterface issuerMulticurves); double parSpread(final BondIborTransaction bond, final IssuerProviderInterface issuerMulticurves); double parSpreadYield(final BondFixedTransaction bond, final IssuerProviderInterface issuerMulticurves); MulticurveSensitivity parSpreadCurveSensitivity(final BondFixedTransaction bond, final IssuerProviderInterface issuerMulticurves); MulticurveSensitivity parSpreadCurveSensitivity(final BondIborTransaction bond, 
      final IssuerProviderInterface issuerMulticurves); MulticurveSensitivity parSpreadYieldCurveSensitivity(final BondFixedTransaction bond, 
      final IssuerProviderInterface issuerMulticurves);  }
@Test public void testPVYieldFixedBondSettlePast() { final double yield = 0.05; final MultipleCurrencyAmount pv = METHOD_BOND_TR.presentValueFromYield(BOND_TRANSACTION_FIXED_1, ISSUER_MULTICURVES, yield); final double dirtyPrice = METHOD_BOND_SEC.dirtyPriceFromYield(BOND_TRANSACTION_FIXED_1.getBondStandard(), yield); final double df = ISSUER_MULTICURVES.getMulticurveProvider().getDiscountFactor(CUR, BOND_TRANSACTION_FIXED_1.getBondStandard().getSettlementTime()); final double pvExpected = (dirtyPrice) * df * QUANTITY_FIXED; assertEquals("Fixed bond present value", pvExpected, pv.getAmount(CUR), TOLERANCE_PV_DELTA); }
@Test public void testPVYieldFixedBondCouponBeforeSettle() { final double yield = 0.05; final MultipleCurrencyAmount pv = METHOD_BOND_TR.presentValueFromYield(BOND_TRANSACTION_FIXED_4, ISSUER_MULTICURVES, yield); final double dirtyPrice = METHOD_BOND_SEC.dirtyPriceFromYield(BOND_TRANSACTION_FIXED_4.getBondStandard(), yield); final double df = ISSUER_MULTICURVES.getMulticurveProvider().getDiscountFactor(CUR, BOND_TRANSACTION_FIXED_4.getBondStandard().getSettlementTime()); final MultipleCurrencyAmount pvSec = MultipleCurrencyAmount.of(CUR, dirtyPrice * df); final MulticurveProviderInterface multicurvesDecorated = new MulticurveProviderDiscountingDecoratedIssuer(ISSUER_MULTICURVES, CUR, BOND_TRANSACTION_FIXED_4.getBondTransaction().getIssuerEntity()); final MultipleCurrencyAmount pvNominalStandard = BOND_TRANSACTION_FIXED_4.getBondStandard().getNominal().accept(PVDC, multicurvesDecorated); final MultipleCurrencyAmount pvCouponStandard = BOND_TRANSACTION_FIXED_4.getBondStandard().getCoupon().accept(PVDC, multicurvesDecorated); final MultipleCurrencyAmount pvDiscountingStandard = pvNominalStandard.plus(pvCouponStandard); final MultipleCurrencyAmount pvNominalTransaction = BOND_TRANSACTION_FIXED_4.getBondTransaction().getNominal().accept(PVDC, multicurvesDecorated); final MultipleCurrencyAmount pvCouponTransaction = BOND_TRANSACTION_FIXED_4.getBondTransaction().getCoupon().accept(PVDC, multicurvesDecorated); final MultipleCurrencyAmount pvDiscountingTransaction = pvNominalTransaction.plus(pvCouponTransaction); final double pvExpected = (pvDiscountingTransaction.getAmount(CUR) - pvDiscountingStandard.getAmount(CUR) + pvSec.getAmount(CUR)) * QUANTITY_FIXED; assertEquals("Fixed coupon bond present value", pvExpected, pv.getAmount(CUR), TOLERANCE_PV_DELTA); assertFalse("Fixed coupon bond present value", Math.abs(pvSec.getAmount(CUR) * QUANTITY_FIXED - pv.getAmount(CUR)) < TOLERANCE_PV_DELTA); }