Class BondPricer
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 TypeMethodDescriptionstatic doubleaccruedInterest(double face, double couponRate, int frequency, LocalDate settlement, LocalDate maturity, DayCount dayCount) Accrued interest at settlement (accrual on unadjusted period dates).static doublecleanPrice(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 doubleconvexity(double face, double couponRate, int frequency, double yearsToMaturity, double yield) Convexity (numeric second derivative of price w.r.t. yield, normalized by price).static doubledirtyPrice(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 doubledv01(double face, double couponRate, int frequency, double yearsToMaturity, double yield) Price change for a one-basis-point yield move (positive number).static doublemacaulayDuration(double face, double couponRate, int frequency, double yearsToMaturity, double yield) Macaulay duration in years: PV-weighted average time to cash flow.static doublemodifiedDuration(double face, double couponRate, int frequency, double yearsToMaturity, double yield) Modified duration: price sensitivity per unit yield change.static doublepriceFromCurve(double face, double couponRate, int frequency, double yearsToMaturity, YieldCurve curve) Price by discounting each cash flow on a zero curve.static doublepriceFromYield(double face, double couponRate, int frequency, double yearsToMaturity, double yield) Dirty price perfacefrom a yield (regular schedule, whole periods).static LocalDatesettlementDate(LocalDate tradeDate, int lagDays, BusinessCalendar calendar) Settlement date from a trade date and settlement lag (e.g.static doubleyieldToMaturity(double price, double face, double couponRate, int frequency, double yearsToMaturity) Yield to maturity by bisection (price must be positive).
-
Method Details
-
priceFromYield
public static double priceFromYield(double face, double couponRate, int frequency, double yearsToMaturity, double yield) Dirty price perfacefrom 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 isface * couponRate * yearFraction(periodStart, periodEnd). -
accruedInterest
-
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
Settlement date from a trade date and settlement lag (e.g. T+2).
-