@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 1574023291: // securityId return ((ResolvedFixedCouponBond) bean).getSecurityId(); case -44199542: // nominalPayment return ((ResolvedFixedCouponBond) bean).getNominalPayment(); case -367345944: // periodicPayments return ((ResolvedFixedCouponBond) bean).getPeriodicPayments(); case -70023844: // frequency return ((ResolvedFixedCouponBond) bean).getFrequency(); case -10223666: // rollConvention return ((ResolvedFixedCouponBond) bean).getRollConvention(); case 747425396: // fixedRate return ((ResolvedFixedCouponBond) bean).getFixedRate(); case 1905311443: // dayCount return ((ResolvedFixedCouponBond) bean).getDayCount(); case -1895216418: // yieldConvention return ((ResolvedFixedCouponBond) bean).getYieldConvention(); case 866287159: // legalEntityId return ((ResolvedFixedCouponBond) bean).getLegalEntityId(); case 135924714: // settlementDateOffset return ((ResolvedFixedCouponBond) bean).getSettlementDateOffset(); } return super.propertyGet(bean, propertyName, quiet); }
/** * 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."); }
/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(ResolvedFixedCouponBond beanToCopy) { this.securityId = beanToCopy.getSecurityId(); this.nominalPayment = beanToCopy.getNominalPayment(); this.periodicPayments = beanToCopy.getPeriodicPayments(); this.frequency = beanToCopy.getFrequency(); this.rollConvention = beanToCopy.getRollConvention(); this.fixedRate = beanToCopy.getFixedRate(); this.dayCount = beanToCopy.getDayCount(); this.yieldConvention = beanToCopy.getYieldConvention(); this.legalEntityId = beanToCopy.getLegalEntityId(); this.settlementDateOffset = beanToCopy.getSettlementDateOffset(); }
/** * Calculates the yield of the fixed coupon bond product from dirty price. * <p> * The dirty price must be fractional. * If the analytic formula is not available, the yield is computed by solving * a root-finding problem with {@link #dirtyPriceFromYield(ResolvedFixedCouponBond, LocalDate, double)}. * The result is also expressed in fraction. * * @param bond the product * @param settlementDate the settlement date * @param dirtyPrice the dirty price * @return the yield of the product */ public double yieldFromDirtyPrice(ResolvedFixedCouponBond bond, LocalDate settlementDate, double dirtyPrice) { if (bond.getYieldConvention().equals(JP_SIMPLE)) { double cleanPrice = cleanPriceFromDirtyPrice(bond, settlementDate, dirtyPrice); LocalDate maturityDate = bond.getUnadjustedEndDate(); double maturity = bond.getDayCount().relativeYearFraction(settlementDate, maturityDate); return (bond.getFixedRate() + (1d - cleanPrice) / maturity) / cleanPrice; } final Function<Double, Double> priceResidual = new Function<Double, Double>() { @Override public Double apply(final Double y) { return dirtyPriceFromYield(bond, settlementDate, y) - dirtyPrice; } }; double[] range = ROOT_BRACKETER.getBracketedPoints(priceResidual, 0.00, 0.20); double yield = ROOT_FINDER.getRoot(priceResidual, range[0], range[1]); return yield; }
ImmutableList<FixedCouponBondPaymentPeriod> payments = bond.getPeriodicPayments(); int nCoupon = payments.size() - couponIndex(payments, settlementDate); FixedCouponBondYieldConvention yieldConv = bond.getYieldConvention(); if (nCoupon == 1) { if (yieldConv.equals(US_STREET) || yieldConv.equals(DE_BONDS)) {
ImmutableList<FixedCouponBondPaymentPeriod> payments = bond.getPeriodicPayments(); int nCoupon = payments.size() - couponIndex(payments, settlementDate); FixedCouponBondYieldConvention yieldConv = bond.getYieldConvention(); if (nCoupon == 1) { if (yieldConv.equals(US_STREET) || yieldConv.equals(DE_BONDS)) {
public void test_resolve() { FixedCouponBond base = sut(); ResolvedFixedCouponBond resolved = base.resolve(REF_DATA); assertEquals(resolved.getLegalEntityId(), LEGAL_ENTITY); assertEquals(resolved.getSettlementDateOffset(), DATE_OFFSET); assertEquals(resolved.getYieldConvention(), YIELD_CONVENTION); ImmutableList<FixedCouponBondPaymentPeriod> periodicPayments = resolved.getPeriodicPayments(); int expNum = 20; assertEquals(periodicPayments.size(), expNum); LocalDate unadjustedEnd = END_DATE; Schedule unadjusted = PERIOD_SCHEDULE.createSchedule(REF_DATA).toUnadjusted(); for (int i = 0; i < expNum; ++i) { FixedCouponBondPaymentPeriod payment = periodicPayments.get(expNum - 1 - i); assertEquals(payment.getCurrency(), EUR); assertEquals(payment.getNotional(), NOTIONAL); assertEquals(payment.getFixedRate(), FIXED_RATE); assertEquals(payment.getUnadjustedEndDate(), unadjustedEnd); assertEquals(payment.getEndDate(), BUSINESS_ADJUST.adjust(unadjustedEnd, REF_DATA)); assertEquals(payment.getPaymentDate(), payment.getEndDate()); LocalDate unadjustedStart = unadjustedEnd.minusMonths(6); assertEquals(payment.getUnadjustedStartDate(), unadjustedStart); assertEquals(payment.getStartDate(), BUSINESS_ADJUST.adjust(unadjustedStart, REF_DATA)); assertEquals(payment.getYearFraction(), unadjusted.getPeriod(expNum - 1 - i).yearFraction(DAY_COUNT, unadjusted)); assertEquals(payment.getDetachmentDate(), EX_COUPON.adjust(payment.getPaymentDate(), REF_DATA)); unadjustedEnd = unadjustedStart; } Payment expectedPayment = Payment.of(CurrencyAmount.of(EUR, NOTIONAL), BUSINESS_ADJUST.adjust(END_DATE, REF_DATA)); assertEquals(resolved.getNominalPayment(), expectedPayment); }
ImmutableList<FixedCouponBondPaymentPeriod> payments = bond.getPeriodicPayments(); int nCoupon = payments.size() - couponIndex(payments, settlementDate); FixedCouponBondYieldConvention yieldConv = bond.getYieldConvention(); if (nCoupon == 1) { if (yieldConv.equals(US_STREET) || yieldConv.equals(DE_BONDS)) {