/** * Calculates the accrued interest of the fixed coupon bond with the specified settlement date. * * @param bond the product * @param settlementDate the settlement date * @return the accrued interest of the product */ public double accruedInterest(ResolvedFixedCouponBond bond, LocalDate settlementDate) { double notional = bond.getNotional(); return accruedYearFraction(bond, settlementDate) * bond.getFixedRate() * notional; }
private double dirtyPriceFromYieldStandard( ResolvedFixedCouponBond bond, LocalDate settlementDate, double yield) { int nbCoupon = bond.getPeriodicPayments().size(); double factorOnPeriod = 1 + yield / ((double) bond.getFrequency().eventsPerYear()); double fixedRate = bond.getFixedRate(); double pvAtFirstCoupon = 0; int pow = 0; for (int loopcpn = 0; loopcpn < nbCoupon; loopcpn++) { FixedCouponBondPaymentPeriod period = bond.getPeriodicPayments().get(loopcpn); if ((period.hasExCouponPeriod() && !settlementDate.isAfter(period.getDetachmentDate())) || (!period.hasExCouponPeriod() && period.getPaymentDate().isAfter(settlementDate))) { pvAtFirstCoupon += fixedRate * period.getYearFraction() / Math.pow(factorOnPeriod, pow); ++pow; } } pvAtFirstCoupon += 1d / Math.pow(factorOnPeriod, pow - 1); return pvAtFirstCoupon * Math.pow(factorOnPeriod, -factorToNextCoupon(bond, settlementDate)); }
double factorOnPeriod = 1 + yield / couponPerYear; double nominal = bond.getNotional(); double fixedRate = bond.getFixedRate(); double cvAtFirstCoupon = 0; double pvAtFirstCoupon = 0;
double factorOnPeriod = 1 + yield / couponPerYear; double nominal = bond.getNotional(); double fixedRate = bond.getFixedRate(); double mdAtFirstCoupon = 0d; double pvAtFirstCoupon = 0d;
@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); }
/** * 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(); }
double cleanPrice = (1d + bond.getFixedRate() * maturity) / (1d + yield * maturity); return dirtyPriceFromCleanPrice(bond, settlementDate, cleanPrice);
/** * 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; }
double num = 1d + bond.getFixedRate() * maturity; double den = 1d + yield * maturity; double dirtyPrice = dirtyPriceFromCleanPrice(bond, settlementDate, num / den);
double num = 1d + bond.getFixedRate() * maturity; double den = 1d + yield * maturity; double dirtyPrice = dirtyPriceFromCleanPrice(bond, settlementDate, num / den);