regimelib
QuantLib’s models with a hidden Markov regime, priced by the fast-switching expansion. The Python reference implementation of regimeswitching.org.
A regime is a finite-state Markov chain that the market does not observe directly. Any parameter of a QuantLib
model may take a different value in each regime: the Vasicek mean level, the Black–Scholes volatility, the Heston
long-run variance, a jump intensity, a default intensity. regimelib prices the usual instruments under such models
in QuantLib’s mold — setPricingEngine, NPV(), greeks as methods on the instrument — with three tiers of
engine: the fast-switching expansion in the mean holding time of the chain, the numerical solution of the reduced
system it expands, and grids and Monte Carlo for early exercise and paths.
Every model has a frozen limit, all regimes equal, in which it is QuantLib’s model; every certificate in the test suite checks that limit against QuantLib’s own engine and then checks the switching case against an independent referee.
import regimelib as rl
chain = rl.RegimeChain.twoState(3.0, 5.0) # rates out of regime 0 and out of regime 1
model = rl.SwitchingVasicek(chain, r0=0.03, a=0.5, b=[0.06, 0.02], sigma=[0.015, 0.008])
bond = rl.ZeroCouponBond(5.0)
bond.setPricingEngine(rl.FastSwitchingEngine(model, order=4, regime=0))
print(bond.NPV(), bond.delta(), bond.gamma())
Getting started
Background
Examples