BondSecurityDiscountingMethod { public MultipleCurrencyAmount presentValue(final BondSecurity<? extends Payment, ? extends Coupon> bond, final IssuerProviderInterface issuerMulticurves) { ArgumentChecker.notNull(bond, "Bond"); final MulticurveProviderInterface multicurvesDecorated = new MulticurveProviderDiscountingDecoratedIssuer(issuerMulticurves, bond.getCurrency(), bond.getIssuerEntity()); final MultipleCurrencyAmount pvNominal = bond.getNominal().accept(PVDC, multicurvesDecorated); final MultipleCurrencyAmount pvCoupon = bond.getCoupon().accept(PVDC, multicurvesDecorated); return pvNominal.plus(pvCoupon); } private  BondSecurityDiscountingMethod(); static BondSecurityDiscountingMethod getInstance(); MultipleCurrencyAmount presentValue(final BondSecurity<? extends Payment, ? extends Coupon> bond, final IssuerProviderInterface issuerMulticurves); MultipleCurrencyAmount presentValueFromCleanPrice(final BondSecurity<? extends Payment, ? extends Coupon> bond, final MulticurveProviderInterface multicurves, final double cleanPrice); MultipleCurrencyAmount presentValueFromYield(final BondSecurity<? extends Payment, ? extends Coupon> bond, final MulticurveProviderInterface multicurves, final double yield); MultipleCurrencyAmount presentValueFromZSpread(final BondSecurity<? extends Payment, ? extends Coupon> bond,
      final IssuerProviderInterface issuerMulticurves, final double zSpread); MultipleCurrencyAmount presentValueFromZSpread(BondSecurity<? extends Payment, ? extends Coupon> bond,
      IssuerProviderInterface issuerMulticurves, double zSpread, boolean periodic, int periodPerYear); double presentValueZSpreadSensitivity(final BondSecurity<? extends Payment, ? extends Coupon> bond, final IssuerProviderInterface issuerMulticurves, final double zSpread); double dirtyPriceFromCurves(final BondFixedSecurity bond, final IssuerProviderInterface issuerMulticurves); double dirtyPriceFromCleanPrice(final BondFixedSecurity bond, final double cleanPrice); double dirtyPriceFromYield(final BondFixedSecurity bond, final double yield); MulticurveSensitivity dirtyPriceCurveSensitivity(final BondFixedSecurity bond, final IssuerProviderInterface issuerMulticurves); double cleanPriceFromCurves(final BondFixedSecurity bond, final IssuerProviderInterface issuerMulticurves); double cleanPriceFromDirtyPrice(final BondFixedSecurity bond, final double dirtyPrice); double cleanPriceFromYield(final BondFixedSecurity bond, final double yield); double yieldFromDirtyPrice(final BondFixedSecurity bond, final double dirtyPrice); double yieldFromCurves(final BondFixedSecurity bond, final IssuerProviderInterface issuerMulticurves); double yieldFromCleanPrice(final BondFixedSecurity bond, final double cleanPrice); double modifiedDurationFromYield(final BondFixedSecurity bond, final double yield); double modifiedDurationFromCurves(final BondFixedSecurity bond, final IssuerProviderInterface issuerMulticurves); double modifiedDurationFromDirtyPrice(final BondFixedSecurity bond, final double dirtyPrice); double modifiedDurationFromCleanPrice(final BondFixedSecurity bond, final double cleanPrice); double macaulayDurationFromYield(final BondFixedSecurity bond, final double yield); double macaulayDurationFromCurves(final BondFixedSecurity bond, final IssuerProviderInterface issuerMulticurves); double macaulayDurationFromCleanPrice(final BondFixedSecurity bond, final double cleanPrice); double macaulayDurationFromDirtyPrice(final BondFixedSecurity bond, final double dirtyPrice); double convexityFromYield(final BondFixedSecurity bond, final double yield); double convexityFromCurves(final BondFixedSecurity bond, final IssuerProviderInterface issuerMulticurves); double convexityFromDirtyPrice(final BondFixedSecurity bond, final double dirtyPrice); double convexityFromCleanPrice(final BondFixedSecurity bond, final double cleanPrice); double zSpreadFromCurvesAndPV(final BondSecurity<? extends Payment, ? extends Coupon> bond, final IssuerProviderInterface issuerMulticurves, final MultipleCurrencyAmount pv); double zSpreadFromCurvesAndPV(final BondSecurity<? extends Payment, ? extends Coupon> bond,
      final IssuerProviderInterface issuerMulticurves, final MultipleCurrencyAmount pv, final boolean periodic,
      final int periodPerYear); double presentValueZSpreadSensitivityFromCurvesAndPV(final BondSecurity<? extends Payment, ? extends Coupon> bond, final IssuerProviderInterface issuerMulticurves,
      final MultipleCurrencyAmount pv); double zSpreadFromCurvesAndClean(final BondSecurity<? extends Payment, ? extends Coupon> bond, final IssuerProviderInterface issuerMulticurves, final double cleanPrice); double zSpreadFromCurvesAndClean(BondSecurity<? extends Payment, ? extends Coupon> bond,
      IssuerProviderInterface issuerMulticurves, double cleanPrice, boolean periodic, int periodPerYear); double zSpreadFromCurvesAndYield(final BondSecurity<? extends Payment, ? extends Coupon> bond, final IssuerProviderInterface issuerMulticurves, final double yield); double zSpreadFromCurvesAndYield(BondSecurity<? extends Payment, ? extends Coupon> bond,
      IssuerProviderInterface issuerMulticurves, double yield, boolean periodic, int periodPerYear); double presentValueZSpreadSensitivityFromCurvesAndClean(final BondSecurity<? extends Payment, ? extends Coupon> bond, final IssuerProviderInterface issuerMulticurves,
      final double cleanPrice); MultipleCurrencyMulticurveSensitivity presentValueCurveSensitivity(final BondSecurity<? extends Payment, ? extends Coupon> bond, final IssuerProviderInterface issuerMulticurves); StringAmount presentValueParallelCurveSensitivity(final BondSecurity<? extends Payment, ? extends Coupon> bond, final IssuerProviderInterface issuerMulticurves); double accruedInterestFromYield(final BondFixedSecurity bond, final double yield); double accruedInterestFromDirtyPrice(final BondFixedSecurity bond, final double dirtyPrice); double accruedInterestFromCleanPrice(final BondFixedSecurity bond, final double cleanPrice); double accruedInterestFromCurves(final BondFixedSecurity bond, final IssuerProviderInterface curves);  }
@Test public void presentValueFixedMiddleIssuer() { final AnnuityPaymentFixed nominal = (AnnuityPaymentFixed) BOND_FIXED_SECURITY_DEFINITION_NO_ENTITY.getNominal().toDerivative(REFERENCE_DATE_1); AnnuityCouponFixed coupon = BOND_FIXED_SECURITY_DEFINITION_NO_ENTITY.getCoupons().toDerivative(REFERENCE_DATE_1); coupon = coupon.trimBefore(REFERENCE_TIME_1); final MulticurveProviderInterface multicurvesDecorated = new MulticurveProviderDiscountingDecoratedIssuer(ISSUER_SPECIFIC_MULTICURVES, CUR, ISSUER); final MultipleCurrencyAmount pvNominal = nominal.accept(PVDC, multicurvesDecorated); final MultipleCurrencyAmount pvCoupon = coupon.accept(PVDC, multicurvesDecorated); final MultipleCurrencyAmount pv = METHOD_BOND_SECURITY.presentValue(BOND_FIXED_SECURITY_NO_ENTITY_1, ISSUER_SPECIFIC_MULTICURVES); assertEquals("Fixed coupon bond security: present value", pvNominal.getAmount(CUR) + pvCoupon.getAmount(CUR), pv.getAmount(CUR), TOLERANCE_PV); }
@Test public void presentValueFixedMiddleShortName() { final AnnuityPaymentFixed nominal = (AnnuityPaymentFixed) BOND_FIXED_SECURITY_DEFINITION_NO_ENTITY.getNominal().toDerivative(REFERENCE_DATE_1); AnnuityCouponFixed coupon = BOND_FIXED_SECURITY_DEFINITION_NO_ENTITY.getCoupons().toDerivative(REFERENCE_DATE_1); coupon = coupon.trimBefore(REFERENCE_TIME_1); final MulticurveProviderInterface multicurvesDecorated = new MulticurveProviderDiscountingDecoratedIssuer(ISSUER_SPECIFIC_MULTICURVES, CUR, ISSUER); final MultipleCurrencyAmount pvNominal = nominal.accept(PVDC, multicurvesDecorated); final MultipleCurrencyAmount pvCoupon = coupon.accept(PVDC, multicurvesDecorated); final MultipleCurrencyAmount pv = METHOD_BOND_SECURITY.presentValue(BOND_FIXED_SECURITY_NO_ENTITY_1, ISSUER_SPECIFIC_MULTICURVES); assertEquals("Fixed coupon bond security: present value", pvNominal.getAmount(CUR) + pvCoupon.getAmount(CUR), pv.getAmount(CUR), TOLERANCE_PV); }
@Test public void presentValueFixedMiddleCountry() { final AnnuityPaymentFixed nominal = (AnnuityPaymentFixed) BOND_FIXED_SECURITY_DEFINITION_FULL_ENTITY.getNominal().toDerivative(REFERENCE_DATE_1); AnnuityCouponFixed coupon = BOND_FIXED_SECURITY_DEFINITION_FULL_ENTITY.getCoupons().toDerivative(REFERENCE_DATE_1); coupon = coupon.trimBefore(REFERENCE_TIME_1); final MulticurveProviderInterface multicurvesDecorated = new MulticurveProviderDiscountingDecoratedIssuer(COUNTRY_SPECIFIC_MULTICURVES, CUR, ISSUER); final MultipleCurrencyAmount pvNominal = nominal.accept(PVDC, multicurvesDecorated); final MultipleCurrencyAmount pvCoupon = coupon.accept(PVDC, multicurvesDecorated); final MultipleCurrencyAmount pv = METHOD_BOND_SECURITY.presentValue(BOND_FIXED_SECURITY_FULL_ENTITY_1, COUNTRY_SPECIFIC_MULTICURVES); assertEquals("Fixed coupon bond security: present value", pvNominal.getAmount(CUR) + pvCoupon.getAmount(CUR), pv.getAmount(CUR), TOLERANCE_PV); }
@Test public void presentValueFixedMiddleCurrency() { final AnnuityPaymentFixed nominal = (AnnuityPaymentFixed) BOND_FIXED_SECURITY_DEFINITION_FULL_ENTITY.getNominal().toDerivative(REFERENCE_DATE_1); AnnuityCouponFixed coupon = BOND_FIXED_SECURITY_DEFINITION_FULL_ENTITY.getCoupons().toDerivative(REFERENCE_DATE_1); coupon = coupon.trimBefore(REFERENCE_TIME_1); final MulticurveProviderInterface multicurvesDecorated = new MulticurveProviderDiscountingDecoratedIssuer(CURRENCY_SPECIFIC_MULTICURVES, CUR, ISSUER); final MultipleCurrencyAmount pvNominal = nominal.accept(PVDC, multicurvesDecorated); final MultipleCurrencyAmount pvCoupon = coupon.accept(PVDC, multicurvesDecorated); final MultipleCurrencyAmount pv = METHOD_BOND_SECURITY.presentValue(BOND_FIXED_SECURITY_FULL_ENTITY_1, CURRENCY_SPECIFIC_MULTICURVES); assertEquals("Fixed coupon bond security: present value", pvNominal.getAmount(CUR) + pvCoupon.getAmount(CUR), pv.getAmount(CUR), TOLERANCE_PV); }
@Test public void presentValueFixedMiddleCountryRating() { final AnnuityPaymentFixed nominal = (AnnuityPaymentFixed) BOND_FIXED_SECURITY_DEFINITION_FULL_ENTITY.getNominal().toDerivative(REFERENCE_DATE_1); AnnuityCouponFixed coupon = BOND_FIXED_SECURITY_DEFINITION_FULL_ENTITY.getCoupons().toDerivative(REFERENCE_DATE_1); coupon = coupon.trimBefore(REFERENCE_TIME_1); final MulticurveProviderInterface multicurvesDecorated = new MulticurveProviderDiscountingDecoratedIssuer(COUNTRY_RATING_SPECIFIC_MULTICURVES, CUR, ISSUER); final MultipleCurrencyAmount pvNominal = nominal.accept(PVDC, multicurvesDecorated); final MultipleCurrencyAmount pvCoupon = coupon.accept(PVDC, multicurvesDecorated); final MultipleCurrencyAmount pv = METHOD_BOND_SECURITY.presentValue(BOND_FIXED_SECURITY_FULL_ENTITY_1, COUNTRY_RATING_SPECIFIC_MULTICURVES); assertEquals("Fixed coupon bond security: present value", pvNominal.getAmount(CUR) + pvCoupon.getAmount(CUR), pv.getAmount(CUR), TOLERANCE_PV); }
@Test public void presentValueFixedOnCoupon() { final AnnuityPaymentFixed nominal = (AnnuityPaymentFixed) BOND_FIXED_SECURITY_DEFINITION_NO_ENTITY.getNominal().toDerivative(REFERENCE_DATE_2); AnnuityCouponFixed coupon = BOND_FIXED_SECURITY_DEFINITION_NO_ENTITY.getCoupons().toDerivative(REFERENCE_DATE_2); coupon = coupon.trimBefore(REFERENCE_TIME_2); final MulticurveProviderInterface multicurvesDecorated = new MulticurveProviderDiscountingDecoratedIssuer(ISSUER_SPECIFIC_MULTICURVES, CUR, ISSUER); final MultipleCurrencyAmount pvNominal = nominal.accept(PVDC, multicurvesDecorated); final MultipleCurrencyAmount pvCoupon = coupon.accept(PVDC, multicurvesDecorated); final MultipleCurrencyAmount pv = METHOD_BOND_SECURITY.presentValue(BOND_FIXED_SECURITY_2, ISSUER_SPECIFIC_MULTICURVES); assertEquals("Fixed coupon bond security: present value", pvNominal.getAmount(CUR) + pvCoupon.getAmount(CUR), pv.getAmount(CUR), TOLERANCE_PV); }
@Test public void presentValueFixedMethodVsCalculator() { final MultipleCurrencyAmount pvMethod = METHOD_BOND_SECURITY.presentValue(BOND_FIXED_SECURITY_NO_ENTITY_1, ISSUER_SPECIFIC_MULTICURVES); final MultipleCurrencyAmount pvCalculator = BOND_FIXED_SECURITY_NO_ENTITY_1.accept(PVIC, ISSUER_SPECIFIC_MULTICURVES); assertEquals("Fixed coupon bond security: present value Method vs Calculator", pvMethod.getAmount(CUR), pvCalculator.getAmount(CUR), TOLERANCE_PV); }
@Test public void presentValueFixedExDividend() { final MultipleCurrencyAmount pv = METHOD_BOND_SECURITY.presentValue(BOND_FIXED_SECURITY_UK, ISSUER_SPECIFIC_MULTICURVES); final BondFixedSecurityDefinition bondNoExDefinition = BondFixedSecurityDefinition.from(GBP, MATURITY_DATE_UK, START_ACCRUAL_DATE_UK, PAYMENT_TENOR_UK, RATE_UK, SETTLEMENT_DAYS_UK, NOTIONAL_UK, 0, CALENDAR_UK, DAY_COUNT_UK, BUSINESS_DAY_UK, YIELD_CONVENTION_UK, IS_EOM_UK, ISSUER_UK_NAME, "RepoType"); final BondFixedSecurity BondNoEx = bondNoExDefinition.toDerivative(REFERENCE_DATE_3); final MultipleCurrencyAmount pvNoEx = METHOD_BOND_SECURITY.presentValue(BondNoEx, ISSUER_SPECIFIC_MULTICURVES); final CouponFixedDefinition couponDefinitionEx = BOND_FIXED_SECURITY_DEFINITION_UK.getCoupons().getNthPayment(17); final MulticurveProviderInterface multicurvesDecorated = new MulticurveProviderDiscountingDecoratedIssuer(ISSUER_SPECIFIC_MULTICURVES, GBP, ISSUER_UK); final MultipleCurrencyAmount pvCpn = couponDefinitionEx.toDerivative(REFERENCE_DATE_3).accept(PVDC, multicurvesDecorated); assertEquals("Fixed coupon bond security: present value ex dividend", pvNoEx.getAmount(GBP) - pvCpn.getAmount(GBP), pv.getAmount(GBP), TOLERANCE_PV); }