Class BondPricer

java.lang.Object
com.quantfinlib.rates.BondPricer

public final class BondPricer extends Object
Fixed-coupon bond analytics: price/yield conversion, Macaulay and modified duration, convexity, and DV01. Yields are per-annum with frequency compounding (the bond's coupon frequency); coupons are assumed on a regular schedule with the last payment at maturity.

The risk numbers and what each is FOR: Macaulay duration is the cash-flow-weighted average time to payment (years — an intuition number); modified duration = Macaulay / (1 + y/f) is the first-order price sensitivity, dP/P ≈ -modDur · dy; DV01 is the same derivative in money terms per 1bp — the number the desk actually hedges, because DV01s ADD across positions while durations must be value-weighted. Convexity is the second-order term that makes the duration hedge wrong for large moves — always in the LONG bondholder's favor (price rises more than duration predicts when yields fall, drops less when they rise), which is why long-convexity positions cost carry.

Simplifications, stated: whole coupon periods (no accrued-interest split of dirty into clean price), no settlement-lag discounting, and yield-to-maturity as the single rate — the classic textbook bond, exact for pricing OFF a yield quote. Pricing off a full curve (each cash flow at its own zero rate) is YieldCurve's job; hedging a position against non-parallel curve moves is KeyRateDurations'.

  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    accruedInterest(double face, double couponRate, int frequency, LocalDate settlement, LocalDate maturity, DayCount dayCount)
    Accrued interest at settlement (accrual on unadjusted period dates).
    static double
    cleanPrice(double face, double couponRate, int frequency, LocalDate settlement, LocalDate maturity, double yield, DayCount dayCount, BusinessCalendar calendar, BusinessCalendar.Roll roll)
    Clean price = dirty price minus accrued interest.
    static double
    convexity(double face, double couponRate, int frequency, double yearsToMaturity, double yield)
    Convexity (numeric second derivative of price w.r.t. yield, normalized by price).
    static double
    dirtyPrice(double face, double couponRate, int frequency, LocalDate settlement, LocalDate maturity, double yield, DayCount dayCount, BusinessCalendar calendar, BusinessCalendar.Roll roll)
    Dirty price with real-world conventions: coupon dates generated from the maturity, payment dates rolled on the business calendar, accrual and discounting measured with the day-count convention.
    static double
    dv01(double face, double couponRate, int frequency, double yearsToMaturity, double yield)
    Price change for a one-basis-point yield move (positive number).
    static double
    macaulayDuration(double face, double couponRate, int frequency, double yearsToMaturity, double yield)
    Macaulay duration in years: PV-weighted average time to cash flow.
    static double
    modifiedDuration(double face, double couponRate, int frequency, double yearsToMaturity, double yield)
    Modified duration: price sensitivity per unit yield change.
    static double
    priceFromCurve(double face, double couponRate, int frequency, double yearsToMaturity, YieldCurve curve)
    Price by discounting each cash flow on a zero curve.
    static double
    priceFromYield(double face, double couponRate, int frequency, double yearsToMaturity, double yield)
    Dirty price per face from a yield (regular schedule, whole periods).
    static LocalDate
    settlementDate(LocalDate tradeDate, int lagDays, BusinessCalendar calendar)
    Settlement date from a trade date and settlement lag (e.g.
    static double
    yieldToMaturity(double price, double face, double couponRate, int frequency, double yearsToMaturity)
    Yield to maturity by bisection (price must be positive).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • priceFromYield

      public static double priceFromYield(double face, double couponRate, int frequency, double yearsToMaturity, double yield)
      Dirty price per face from a yield (regular schedule, whole periods).
    • priceFromCurve

      public static double priceFromCurve(double face, double couponRate, int frequency, double yearsToMaturity, YieldCurve curve)
      Price by discounting each cash flow on a zero curve.
    • yieldToMaturity

      public static double yieldToMaturity(double price, double face, double couponRate, int frequency, double yearsToMaturity)
      Yield to maturity by bisection (price must be positive).
    • macaulayDuration

      public static double macaulayDuration(double face, double couponRate, int frequency, double yearsToMaturity, double yield)
      Macaulay duration in years: PV-weighted average time to cash flow.
    • modifiedDuration

      public static double modifiedDuration(double face, double couponRate, int frequency, double yearsToMaturity, double yield)
      Modified duration: price sensitivity per unit yield change.
    • convexity

      public static double convexity(double face, double couponRate, int frequency, double yearsToMaturity, double yield)
      Convexity (numeric second derivative of price w.r.t. yield, normalized by price).
    • dv01

      public static double dv01(double face, double couponRate, int frequency, double yearsToMaturity, double yield)
      Price change for a one-basis-point yield move (positive number).
    • dirtyPrice

      public static double dirtyPrice(double face, double couponRate, int frequency, LocalDate settlement, LocalDate maturity, double yield, DayCount dayCount, BusinessCalendar calendar, BusinessCalendar.Roll roll)
      Dirty price with real-world conventions: coupon dates generated from the maturity, payment dates rolled on the business calendar, accrual and discounting measured with the day-count convention. Coupons accrue on unadjusted period dates (bond-market convention); each coupon is face * couponRate * yearFraction(periodStart, periodEnd).
    • accruedInterest

      public static double accruedInterest(double face, double couponRate, int frequency, LocalDate settlement, LocalDate maturity, DayCount dayCount)
      Accrued interest at settlement (accrual on unadjusted period dates).
    • cleanPrice

      public static double cleanPrice(double face, double couponRate, int frequency, LocalDate settlement, LocalDate maturity, double yield, DayCount dayCount, BusinessCalendar calendar, BusinessCalendar.Roll roll)
      Clean price = dirty price minus accrued interest.
    • settlementDate

      public static LocalDate settlementDate(LocalDate tradeDate, int lagDays, BusinessCalendar calendar)
      Settlement date from a trade date and settlement lag (e.g. T+2).