Quick start

Build a market curve

Every no-arbitrage and full-curve model takes a DiscountCurve as input:

import numpy as np
from interest_rate_models import DiscountCurve

curve = DiscountCurve.from_zero_rates(
    times=np.array([0.5, 1.0, 2.0, 5.0, 10.0]),
    zero_rates=np.array([0.030, 0.032, 0.034, 0.037, 0.039]),
)

curve.discount(3.0)       # P(0, 3)
curve.zero_rate(3.0)      # continuously-compounded zero rate
curve.inst_forward(3.0)   # instantaneous forward f(0, 3)
curve.forward_rate(2.0, 2.5)  # simple forward over [2, 2.5]

Curves can also be built from discount factors (DiscountCurve(times, dfs)) or flat (DiscountCurve.flat(0.03)).

Short-rate models

Equilibrium models are configured by their parameters and can be least-squares calibrated to a curve:

from interest_rate_models import get_model

vasicek = get_model("vasicek", kappa=0.86, theta=0.05, sigma=0.02, r0=0.03)
vasicek.bond_price(0.0, 5.0)
vasicek.bond_option(1.0, 3.0, strike=0.9, kind="call")
params = vasicek.calibrate(curve, r0=0.03)   # updates the instance in place

cir = get_model("cir", kappa=0.9, theta=0.05, sigma=0.15, r0=0.04)
times, paths = cir.simulate(T=5.0, n_steps=500, n_paths=10_000, seed=42)

No-arbitrage models take the curve directly and reproduce it exactly:

hw = get_model("hull-white", curve=curve, a=0.1, sigma=0.01)
hw.bond_price(0.0, 5.0)                     # == curve.discount(5.0)
hw.bond_option(1.0, 5.0, strike=0.85)
hw.cap_price(strike=0.035, maturity=3.0, tenor=0.5)

g2 = get_model("g2++", curve=curve, a=0.5, b=0.05, sigma=0.008, eta=0.006, rho=-0.7)
g2.bond_option(1.0, 5.0, strike=0.85)

Caps and floors are available on every model with a closed-form bond option, via the model-independent replication of a caplet as a put on a zero-coupon bond.

Full-curve models

from interest_rate_models import HJM, LiborMarketModel

# Gaussian HJM: drift is derived from the factor vols automatically
hjm = HJM.exponential_vol(curve, sigma=0.01, lam=0.1, T_max=5.0, n_steps=100)
hjm.mc_bond_price(3.0, n_paths=50_000, seed=1)   # == curve.discount(3.0) up to MC error
hjm.mc_bond_option(1.0, 3.0, strike=0.93)

# LMM: lognormal forwards, Black caplets, Rebonato swaptions
lmm = LiborMarketModel(curve, tenor=0.5, n_periods=10, vol=0.20, corr_beta=0.1)
lmm.cap_price(strike=0.035, maturity=3.0)
lmm.swaption_price(alpha=2, beta=6, strike=lmm.swap_rate(2, 6))
lmm.mc_swaption_price(alpha=2, beta=6, strike=0.035, n_paths=100_000, seed=1)

Model selection

See Models for the taxonomy (equilibrium vs no-arbitrage, short-rate vs full-curve) and guidance on which model fits which task.