Class ShortRateModels
java.lang.Object
com.quantfinlib.rates.ShortRateModels
The three classic short-rate models, each answering "what is a
zero-coupon bond worth if the short rate follows this SDE?" in closed
form — the workhorse trio of rates risk factor modeling:
- Vasicek
dr = a(b − r)dt + σ dW— Gaussian, tractable everywhere, and honest about its flaw: rates can go negative (which, post-2015, is a feature as much as a bug); - CIR
dr = a(b − r)dt + σ√r dW— the square-root diffusion keeps rates non-negative (strictly positive when the Feller condition2ab ≥ σ²holds), at the cost of fatter formulas; - Hull-White — Vasicek with a time-dependent drift fitted so the model reprices TODAY'S curve exactly: the standard production choice, because a rates model that disagrees with the discount curve it hedges against is wrong by construction. Bond prices come from the curve plus a Gaussian convexity adjustment; no explicit θ(t) is needed for pricing.
All prices are for unit face. Simulation steps (exact Gaussian for Vasicek, full-truncation Euler for CIR) are provided for Monte Carlo scenario generation — the rates leg of a risk-factor simulation. Static, allocation-free per call, research lane. Calibration of (a, σ) to market instruments is the caller's optimization exercise; these classes price and simulate given parameters.
-
Method Summary
Modifier and TypeMethodDescriptionstatic doublecirBond(double shortRate, double a, double b, double sigma, double maturityYears) CIR zero-coupon bond price P(t, t+T).static doublecirFeller(double a, double b, double sigma) The Feller ratio 2ab/σ²; ≥ 1 keeps the CIR rate strictly positive.static doublecirStep(double shortRate, double a, double b, double sigma, double dtYears, double gaussian) One full-truncation Euler CIR step (never sources vol from a negative rate).static doublehullWhiteBond(YieldCurve curve, double tYears, double maturityYears, double shortRate, double a, double sigma) Hull-White zero-coupon bond price P(t, t+T) given the market curve and the short rate now.static doubleinstantaneousForward(YieldCurve curve, double tYears) The instantaneous forward rate f(0, t) off the curve, by symmetric finite difference of ln P (the curve carries no analytic derivative).static doublevasicekBond(double shortRate, double a, double b, double sigma, double maturityYears) Vasicek zero-coupon bond price P(t, t+T) given the short rate now.static doublevasicekStep(double shortRate, double a, double b, double sigma, double dtYears, double gaussian) One EXACT Vasicek simulation step (the transition is Gaussian, so no discretization error):r ← b + (r−b)e^{−aΔt} + stdev·z.static doublevasicekYield(double shortRate, double a, double b, double sigma, double maturityYears) The continuously-compounded zero yield implied byvasicekBond(double, double, double, double, double).
-
Method Details
-
vasicekBond
public static double vasicekBond(double shortRate, double a, double b, double sigma, double maturityYears) Vasicek zero-coupon bond price P(t, t+T) given the short rate now. -
vasicekYield
public static double vasicekYield(double shortRate, double a, double b, double sigma, double maturityYears) The continuously-compounded zero yield implied byvasicekBond(double, double, double, double, double). -
vasicekStep
public static double vasicekStep(double shortRate, double a, double b, double sigma, double dtYears, double gaussian) One EXACT Vasicek simulation step (the transition is Gaussian, so no discretization error):r ← b + (r−b)e^{−aΔt} + stdev·z. -
cirBond
public static double cirBond(double shortRate, double a, double b, double sigma, double maturityYears) CIR zero-coupon bond price P(t, t+T). -
cirFeller
public static double cirFeller(double a, double b, double sigma) The Feller ratio 2ab/σ²; ≥ 1 keeps the CIR rate strictly positive. -
cirStep
public static double cirStep(double shortRate, double a, double b, double sigma, double dtYears, double gaussian) One full-truncation Euler CIR step (never sources vol from a negative rate). -
hullWhiteBond
public static double hullWhiteBond(YieldCurve curve, double tYears, double maturityYears, double shortRate, double a, double sigma) Hull-White zero-coupon bond price P(t, t+T) given the market curve and the short rate now. By construction, att = 0withshortRate = f(0, 0)this reprices the curve exactly; away from it, the Gaussian convexity adjustment applies:P(t,T) = [P(0,T)/P(0,t)] · exp(B(f(0,t) − r) − σ²B²(1−e^{−2at})/(4a))- Parameters:
curve- today's discount curvetYears- valuation time (0 = today)maturityYears- time FROM t to the bond's maturityshortRate- the simulated short rate at ta- mean-reversion speedsigma- short-rate vol
-
instantaneousForward
The instantaneous forward rate f(0, t) off the curve, by symmetric finite difference of ln P (the curve carries no analytic derivative).
-