private double factorToNextCoupon(ResolvedFixedCouponBond bond, LocalDate settlementDate) { if (bond.getPeriodicPayments().get(0).getStartDate().isAfter(settlementDate)) { return 0d; } int couponIndex = couponIndex(bond.getPeriodicPayments(), settlementDate); double factorSpot = accruedYearFraction(bond, settlementDate); double factorPeriod = bond.getPeriodicPayments().get(couponIndex).getYearFraction(); return (factorPeriod - factorSpot) / factorPeriod; }
/** * Calculates the Macaulay duration of the fixed coupon bond product from yield. * <p> * Macaulay defined an alternative way of weighting the future cash flows. * <p> * The input yield must be fractional. The dirty price and its derivative are * computed for {@link FixedCouponBondYieldConvention}, and the result is expressed in fraction. * * @param bond the product * @param settlementDate the settlement date * @param yield the yield * @return the modified duration of the product */ public double macaulayDurationFromYield(ResolvedFixedCouponBond bond, LocalDate settlementDate, double yield) { ImmutableList<FixedCouponBondPaymentPeriod> payments = bond.getPeriodicPayments(); int nCoupon = payments.size() - couponIndex(payments, settlementDate); FixedCouponBondYieldConvention yieldConv = bond.getYieldConvention(); if ((yieldConv.equals(US_STREET)) && (nCoupon == 1)) { return factorToNextCoupon(bond, settlementDate) / bond.getFrequency().eventsPerYear(); } if ((yieldConv.equals(US_STREET)) || (yieldConv.equals(GB_BUMP_DMO)) || (yieldConv.equals(DE_BONDS))) { return modifiedDurationFromYield(bond, settlementDate, yield) * (1d + yield / bond.getFrequency().eventsPerYear()); } throw new UnsupportedOperationException("The convention " + yieldConv.name() + " is not supported."); }
int nCoupon = payments.size() - couponIndex(payments, settlementDate); FixedCouponBondYieldConvention yieldConv = bond.getYieldConvention(); if (nCoupon == 1) {
int nCoupon = payments.size() - couponIndex(payments, settlementDate); FixedCouponBondYieldConvention yieldConv = bond.getYieldConvention(); if (nCoupon == 1) {
int nCoupon = payments.size() - couponIndex(payments, settlementDate); FixedCouponBondYieldConvention yieldConv = bond.getYieldConvention(); if (nCoupon == 1) {