public void dirtyPriceFromYieldJPLastPeriod() { double computed = PRICER.dirtyPriceFromYield(PRODUCT_JP, SETTLEMENT_LAST_JP, YIELD_JP); double maturity = DayCounts.NL_365.relativeYearFraction(SETTLEMENT_LAST_JP, END_JP); double expected = PRICER.dirtyPriceFromCleanPrice( PRODUCT_JP, SETTLEMENT_LAST_JP, (1d + RATE_JP * maturity) / (1d + YIELD_JP * maturity)); assertEquals(computed, expected, TOL); double yield = PRICER.yieldFromDirtyPrice(PRODUCT_JP, SETTLEMENT_LAST_JP, computed); assertEquals(yield, YIELD_JP, TOL); }
public void dirtyPriceFromYieldJP() { double computed = PRICER.dirtyPriceFromYield(PRODUCT_JP, SETTLEMENT_JP, YIELD_JP); double maturity = DayCounts.NL_365.relativeYearFraction(SETTLEMENT_JP, END_JP); double expected = PRICER.dirtyPriceFromCleanPrice( PRODUCT_JP, SETTLEMENT_JP, (1d + RATE_JP * maturity) / (1d + YIELD_JP * maturity)); assertEquals(computed, expected, TOL); double yield = PRICER.yieldFromDirtyPrice(PRODUCT_JP, SETTLEMENT_JP, computed); assertEquals(yield, YIELD_JP, TOL); }
public void test_dirtyPriceFromCleanPrice_cleanPriceFromDirtyPrice() { double dirtyPrice = PRICER.dirtyPriceFromCurves(PRODUCT, PROVIDER, REF_DATA); LocalDate settlement = DATE_OFFSET.adjust(VAL_DATE, REF_DATA); double cleanPrice = PRICER.cleanPriceFromDirtyPrice(PRODUCT, settlement, dirtyPrice); double accruedInterest = PRICER.accruedInterest(PRODUCT, settlement); assertEquals(cleanPrice, dirtyPrice - accruedInterest / NOTIONAL, NOTIONAL * TOL); double dirtyPriceRe = PRICER.dirtyPriceFromCleanPrice(PRODUCT, settlement, cleanPrice); assertEquals(dirtyPriceRe, dirtyPrice, TOL); }
/** * Calculates the payment that was made for the trade. * <p> * This is the payment that was made on the settlement date, based on the quantity and clean price. * * @param trade the trade * @return the payment that was made */ public Payment upfrontPayment(ResolvedFixedCouponBondTrade trade) { ResolvedFixedCouponBond product = trade.getProduct(); Currency currency = product.getCurrency(); if (!trade.getSettlement().isPresent()) { return Payment.of(CurrencyAmount.zero(currency), product.getStartDate()); // date doesn't matter as it is zero } // payment is based on the dirty price ResolvedFixedCouponBondSettlement settlement = trade.getSettlement().get(); LocalDate settlementDate = settlement.getSettlementDate(); double cleanPrice = settlement.getPrice(); double dirtyPrice = productPricer.dirtyPriceFromCleanPrice(product, settlementDate, cleanPrice); // calculate payment double quantity = trade.getQuantity(); double notional = product.getNotional(); return Payment.of(CurrencyAmount.of(currency, -quantity * notional * dirtyPrice), settlementDate); }
double num = 1d + bond.getFixedRate() * maturity; double den = 1d + yield * maturity; double dirtyPrice = dirtyPriceFromCleanPrice(bond, settlementDate, num / den); return 2d * num * Math.pow(maturity, 2) * Math.pow(den, -3) / dirtyPrice;
return dirtyPriceFromCleanPrice(bond, settlementDate, cleanPrice);
double num = 1d + bond.getFixedRate() * maturity; double den = 1d + yield * maturity; double dirtyPrice = dirtyPriceFromCleanPrice(bond, settlementDate, num / den); return num * maturity / den / den / dirtyPrice;