C++ implementations of classical short-rate models for interest rate modeling and bond pricing.
The Vasicek model describes the evolution of the short-term interest rate as a mean-reverting process.
Stochastic Differential Equation (SDE):
-
alpha($\alpha$ ): Speed of mean reversion. -
b($b$ ): Long-term mean level (the target rate).
Exact Transition Formula:
The code implements the analytical solution for a time step
where
The CIR model is an extension of the Vasicek model that ensures interest rates stay non-negative by making volatility dependent on the square root of the current rate.
Stochastic Differential Equation (SDE):
Numerical Scheme (Euler-Maruyama):
The code implements the Euler discretization, which approximates the change over a small time step
where
This implementation utilizes the fact that in a CIR model, the future rate
Stochastic Differential Equation (SDE):
Exact Transition Formula:
The code calculates the rate at the next time step by sampling from the distribution of c is defined as:
Implementation Logic based on Degrees of Freedom (
d: Degrees of freedom, calculated as
-
Case
$d > 1$ (High Mean Reversion/Low Vol): The rate is sampled using the property that a non-central chi-square variable can be represented as the sum of a squared normal distribution (with a shift) and a central chi-square distribution:$$r_{t+\Delta t} = c \cdot \left( (Z + \sqrt{\lambda})^2 + \chi^2_{d-1} \right)$$ where$\lambda = \frac{r_t e^{-\alpha \Delta t}}{c}$ is the non-centrality parameter. -
Case
$d \le 1$ (Low Mean Reversion/High Vol): The rate is sampled using the Poisson-mixture representation. A non-central chi-square variable is equivalent to a central chi-square variable with a random number of degrees of freedom:$$N \sim \text{Poisson}\left(\frac{\lambda}{2}\right), \quad r_{t+\Delta t} = c \cdot \chi^2_{d + 2N}$$
The Ho-Lee model is a "no-arbitrage" model that incorporates the current market yield curve to ensure the simulated rates are consistent with today's bond prices.
Stochastic Differential Equation (SDE):
Note: get_forward_rate(t) ($f(0, t)$): Gets the instantaneous market forward rate.
Numerical Scheme:
To ensure the model fits the initial yield curve, the code calculates the time-dependent drift
Implementation Details:
-
Interpolated Spot Curve: The function
get_interpolated_spotuses linear interpolation to estimate rates between known market quotes, ensuring the model can be evaluated at any time$t$ . - Forward Rate Derivation: Since forward rates are usually not quoted directly, the code calculates them using the relationship:
Compile:
g++ method model_name.cppRun:
./modelAll models provide closed-form or semi-analytical solutions for zero-coupon bond prices:
- Caps/Floors: Option on interest rates
- Swaptions: Option to enter swap
- Bond Options: European options on bonds