Vasicek Curve¶
The VasicekCurve models the short rate and yield curve under the Vasicek (Ornstein-Uhlenbeck) dynamics. Historical calibration of model parameters is performed via maximum likelihood using the KalmanFilter from ta/kalman.
quantflow.rates.vasicek.VasicekCurve
pydantic-model
¶
Bases: YieldCurve
Yield curve derived from the Vasicek short-rate model.
The Vasicek model describes the short rate as a mean-reverting Ornstein-Uhlenbeck process:
The model admits a closed-form discount factor; see discount_factor.
Throughout, the auxiliary quantity is:
Fields:
-
ref_date(datetime) -
curve_type(Literal['vasicek_curve']) -
rate(DecimalNumber) -
kappa(DecimalNumber) -
theta(DecimalNumber) -
sigma(DecimalNumber)
calibrator
¶
Return a VasicekCurveCalibration wrapping this curve.
process
¶
Return the underlying Vasicek process corresponding to this curve.
Source code in quantflow/rates/vasicek.py
instantaneous_forward_rate
¶
Calculate the instantaneous forward rate for the Vasicek model.
Source code in quantflow/rates/vasicek.py
discount_factor
¶
Calculate the discount factor using the Vasicek closed-form solution.
where \(A(\tau)\) and \(B(\tau)\) are the affine coefficients given by [affine_coefficients][quantflow.rates.vasicek.VasicekCurve.discount_factor.affine_coefficients].
Source code in quantflow/rates/vasicek.py
affine_coefficients
¶
Return the affine coefficients \(A(\tau)\) and \(B(\tau)\) of the log discount factor.
where
Source code in quantflow/rates/vasicek.py
jacobian
¶
Analytical Jacobian of discount factors w.r.t. \([r_0, \kappa, \theta, \sigma]\). Returns shape (len(ttm), 4).
Source code in quantflow/rates/vasicek.py
continuously_compounded_rate
¶
Calculate the continuously compounded rate for a given time to maturity.
The continuously compounded rate is related to the discount factor by the following formula:
where \(D(\tau)\) is the discount factor for a given time to maturity \(\tau\).
Accepts a scalar float or a float array. Returns a scalar float for scalar input and a numpy float array for array input.
| PARAMETER | DESCRIPTION |
|---|---|
ttm
|
Time to maturity in years
TYPE:
|
Source code in quantflow/rates/yield_curve.py
rates
¶
Calculate zero rates compounded at the given frequency.
The continuously compounded rate \(r_c(\tau)\) is converted to a rate compounded \(m\) times per year via:
When frequency=0 the result is continuously compounded (same as
continuously_compounded_rate).
| PARAMETER | DESCRIPTION |
|---|---|
ttm
|
Time to maturity in years
TYPE:
|
frequency
|
Compounding periods per year (e.g. 2 for semi-annual). Pass 0 for continuously compounded.
TYPE:
|
Source code in quantflow/rates/yield_curve.py
plot
¶
Plot the continuously compounded rate vs time to maturity.
Requires plotly to be installed.
| PARAMETER | DESCRIPTION |
|---|---|
ttm_max
|
Maximum time to maturity in years
TYPE:
|
n
|
Number of points to evaluate
TYPE:
|
Source code in quantflow/rates/yield_curve.py
register_curve_types
classmethod
¶
Register a yield curve subclass for deserialization.
The registry key is the curve_type discriminator value rather than
the class name, so the two can be named independently.
Source code in quantflow/rates/yield_curve.py
curve_types
classmethod
¶
get_curve_class
classmethod
¶
quantflow.rates.vasicek.VasicekCurveCalibration
pydantic-model
¶
Bases: YieldCurveCalibration[VasicekCurve]
Calibration wrapper for a VasicekCurve yield curve.
Fields:
-
yield_curve(Y)
filtered_short_rate
property
¶
Kalman-filtered short rate at each observation date.
Populated by [calibrate_historical_rates][quantflow.rates.vasicek.VasicekCurveCalibration.filtered_short_rate.calibrate_historical_rates]; accessing it before a historical fit raises an error.
get_params
¶
set_params
¶
Source code in quantflow/rates/vasicek.py
get_bounds
¶
calibrate
¶
Fit the Vasicek curve to continuously compounded rates via least squares.
| PARAMETER | DESCRIPTION |
|---|---|
ttm
|
Times to maturity in years.
TYPE:
|
rates
|
Continuously compounded rates, same length as ttm.
TYPE:
|
Source code in quantflow/rates/vasicek.py
calibrate_historical_rates
¶
Fit Vasicek by maximum likelihood with a Kalman filter on the panel.
The short rate \(r_t\) is the latent state of a LinearGaussianModel. Under a uniform time step \(\Delta t\) the exact discretization of the Ornstein-Uhlenbeck dynamics is the Gaussian AR(1):
Centring the state on \(\theta\) (filtering \(z_t = r_t - \theta\)) cancels the AR(1) drift, and the affine yields \(y_i = (B_i r_t - A_i)/\tau_i\) become linear in \(z_t\) once their constant part is subtracted. The plain zero-intercept linear-Gaussian filter then applies.
The negative log-likelihood is minimised over \((\kappa, \theta, \sigma, h)\), where \(h\) is the observation noise standard deviation, then the curve's rate is set to the final filtered short rate.
| PARAMETER | DESCRIPTION |
|---|---|
ttm
|
Times to maturity in years, shape (n,).
TYPE:
|
rates
|
Continuously compounded rates, shape (T, n) (time by maturity).
TYPE:
|
dt
|
Per-step time increments in years, shape (T-1,); assumed uniform.
TYPE:
|
Source code in quantflow/rates/vasicek.py
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | |
calibrate_df
¶
Fit the yield curve to target discount factors.
Converts discount factors to continuously compounded rates then calls calibrate.
| PARAMETER | DESCRIPTION |
|---|---|
ttm
|
Times to maturity in years.
TYPE:
|
target
|
Target discount factors, same length as ttm.
TYPE:
|
Source code in quantflow/rates/calibration.py
calibrate_historical_rates_dataframe
¶
Fit the yield curve from a historical panel of rates.
Tenor column labels are parsed into times to maturity, per-step
time increments are inferred from the DatetimeIndex (irregular
spacing supported), and rates are converted to continuously
compounded if a finite frequency is supplied. The actual fit
is delegated to [calibrate_historical_rates][quantflow.rates.vasicek.calibrate_historical_rates],
which subclasses override.
| PARAMETER | DESCRIPTION |
|---|---|
rates
|
Historical zero rates with a DatetimeIndex and tenor column labels parsed by [ccy.Period][ccy.dates.period.Period] (e.g.
TYPE:
|
frequency
|
Compounding periods per year of the input rates.
TYPE:
|