Bond Pricing
Price bonds by discounting cash flows at a single YTM, or tenor-by-tenor from a full zero rate curve with linear interpolation.
BondPricerQuant4J is a Java library for quantitative finance — covering fixed income, derivatives, options, futures, swaps, credit, and risk analytics. The v1.0.0 release establishes the fixed income foundation: bond pricing, duration, yield inversion, and curve construction. Each subsequent release extends the library with new instrument types, all sharing the same consistent, interface-driven API.
// 6% bond, semi-annual coupons, 5-year maturity
Bond bond = new Bond(1000.0, 0.06, 5.0, Frequency.SEMI_ANNUALLY);
// Price at 7% YTM, discrete semi-annual compounding
CompoundingStrategy compounding = new DiscreteCompoundingStrategy(2);
BondPricer pricer = new YieldBondPricer(0.07, compounding);
double price = pricer.price(bond); // → 958.42
// Duration & DV01
BondDurationCalculator calc = new YieldBondDurationCalculator(0.07, compounding);
double dv01 = calc.dv01(bond, price); // → 0.4053
Every operation is backed by a named interface. Swap any implementation without touching the rest of your code.
Price bonds by discounting cash flows at a single YTM, or tenor-by-tenor from a full zero rate curve with linear interpolation.
BondPricerInvert the pricing formula numerically. Plug in Bisection, Newton-Raphson, or Secant — the solver is a strategy you supply.
BondYieldCalculatorMacaulay duration, modified duration, and DV01 in one call. The Macaulay-to-modified conversion is delegated to the compounding strategy.
BondDurationCalculatorBuild a spot rate curve from par bonds or observed market prices. Bonds are processed in ascending maturity order; intermediate cash flows are discounted from the curve built so far.
BootstrappingStrategyDiscrete (any frequency) and continuous compounding, each exposing discount factor, accumulation factor, present value, future value, and forward rate.
CompoundingStrategyConvert between any discrete frequency and continuous compounding, or between two discrete frequencies, using the standard equated-accumulation-factor formula.
RateConverterThe following examples cover the main entry points of the library. Inline comments show the actual computed output.
// 6% bond, semi-annual coupons, 5-year maturity
Bond bond = new Bond(1000.0, 0.06, 5.0, Frequency.SEMI_ANNUALLY);
BondYieldCalculator ytm = new RootFindingBondYieldCalculator(
new DiscreteCompoundingStrategy(2),
new NewtonRaphsonSolver());
double yield = ytm.yieldToMaturity(bond, 958.42);
// → 0.0700 (7.00%)
// Any RootSolver works — Bisection and Secant are also available
BondYieldCalculator ytm2 = new RootFindingBondYieldCalculator(
new DiscreteCompoundingStrategy(2),
new BisectionSolver());
// 6% bond, semi-annual coupons, 5-year maturity
Bond bond = new Bond(1000.0, 0.06, 5.0, Frequency.SEMI_ANNUALLY);
Map<Double, Double> curve = Map.of(
0.5, 0.050, 1.0, 0.055,
2.0, 0.060, 5.0, 0.065);
BondPricer pricer = new ZeroCouponBondRateBondPricer(
curve,
new LinearInterpolationStrategy(),
new ContinuousCompoundingStrategy());
double price = pricer.price(bond);
// → 976.55 (each cash flow at its own interpolated spot rate)
BootstrappingStrategy boot = new SpotRateCurveBootstrappingStrategy(
Map.of(0.5, 0.04), // seed: 6-month spot rate
new ContinuousCompoundingStrategy());
List<Bond> benchmarks = List.of(
new Bond(1000, 0.04, 1.0, Frequency.SEMI_ANNUALLY),
new Bond(1000, 0.05, 2.0, Frequency.SEMI_ANNUALLY),
new Bond(1000, 0.055, 3.0, Frequency.SEMI_ANNUALLY));
NavigableMap<Double, Double> spotCurve =
boot.bootstrapFromParBonds(benchmarks, new LinearInterpolationStrategy());
// → {0.5=0.04, 1.0=0.0396, 2.0=0.0497, 3.0=0.0548}
// Semi-annual 5% → continuous equivalent
double rc = RateConverter.discreteToContinuous(
0.05, Frequency.SEMI_ANNUALLY);
// → 0.04938 (4.938%)
// Continuous → quarterly discrete
double rq = RateConverter.continuousToDiscrete(
rc, Frequency.QUARTERLY);
// → 0.04969 (4.969%)
// Direct discrete-to-discrete (equated accumulation factors)
double rm = RateConverter.convertDiscreteRates(
0.05, Frequency.SEMI_ANNUALLY, Frequency.MONTHLY);
// → 0.04949 (4.949%)
Three principles that apply to every module, present and future.
Every operation is expressed as an interface. Swap any implementation — pricer, solver, compounding convention — without touching the rest of your code.
Compounding convention, coupon frequency, and interpolation method are always supplied by the caller. The library never infers them. What you pass is what you get.
Bond is a Java record. All calculators hold only final fields. Every instance is safe for concurrent use with no synchronisation.
Keep quantitative finance logic portable, auditable, and simple to embed. Quant4J integrates cleanly into services, batch jobs, trading tools, and risk applications without pulling a dependency graph behind it.
v1.0.0 ships the fixed income foundation. Every subsequent release adds a new instrument class, all sharing the same consistent interface-driven API.
| Version | Module | Key additions | Status |
|---|---|---|---|
| v1.0.0 | Fixed Income Core | Bond pricing, YTM, duration, DV01, curve bootstrapping, compounding, rate conversion, solvers | ✓ Stable |
| v1.1.0 | Market Conventions | Day-count conventions (Act/Act, 30/360), business calendars, dirty/clean price, accrued interest, settlement lag | Planned |
| v1.2.0 | Money Market | T-bills, certificates of deposit, commercial paper, repo, FRAs, OIS rates | Planned |
| v2.0.0 | Interest Rate Swaps | IRS, OIS, basis swaps, multi-curve framework (OIS discounting + SOFR/LIBOR projection), swap curve bootstrapping | Planned |
| v2.1.0 | Interest Rate Options | Caps, floors, swaptions — Black & Bachelier models, volatility surfaces, Greeks | Planned |
| v3.0.0 | Credit | CDS pricing (ISDA model), credit curve bootstrapping, hazard rates, Z-spread, asset swap spread | Planned |
| v3.1.0 | Equity Derivatives | European & American options, Black-Scholes-Merton, binomial tree, Monte Carlo, full Greeks, implied volatility | Planned |
| v5.0.0 | Risk Engine | VaR (historical, parametric, Monte Carlo), CVaR, Greeks aggregation, scenario analysis, XVA | Planned |
Java 21+. No runtime dependencies.
<dependency>
<groupId>io.quant4j</groupId>
<artifactId>quant4j</artifactId>
<version>1.0.0</version>
</dependency>
dependencies {
implementation("io.quant4j:quant4j:1.0.0")
}