CIR Curve¶
quantflow.rates.cir.CIRCurve
pydantic-model
¶
Bases: YieldCurve
Yield curve derived from the Cox-Ingersoll-Ross short-rate model.
The CIR model describes the short rate as a mean-reverting square-root diffusion:
The model admits a closed-form discount factor; see discount_factor.
Throughout, the auxiliary quantities are:
Fields:
-
ref_date(datetime) -
curve_type(Literal['cir_curve']) -
rate(DecimalNumber) -
kappa(DecimalNumber) -
theta(DecimalNumber) -
sigma(DecimalNumber)
calibrator
¶
Return a CIRCurveCalibration wrapping this curve.
instantaneous_forward_rate
¶
Calculate the instantaneous forward rate for the CIR model.
The forward rate is:
where:
Source code in quantflow/rates/cir.py
discount_factor
¶
Calculate the discount factor using the CIR closed-form solution.
The discount factor is:
The coefficients are:
Source code in quantflow/rates/cir.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/cir.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
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.
Source code in quantflow/rates/yield_curve.py
curve_types
classmethod
¶
get_curve_class
classmethod
¶
quantflow.rates.cir.CIRCurveCalibration
pydantic-model
¶
Bases: YieldCurveCalibration[CIRCurve]
Calibration wrapper for a CIR yield curve.
Fields:
-
yield_curve(Y)
get_params
¶
set_params
¶
Source code in quantflow/rates/cir.py
get_bounds
¶
calibrate
¶
Fit the CIR curve to continuously compounded rates via least squares.
The Feller condition is enforced by reparametrising \(\sigma\) as
Since CIR requires non-negative rates, any negative input rates are floored to a small positive value before fitting.
| PARAMETER | DESCRIPTION |
|---|---|
ttm
|
Times to maturity in years.
TYPE:
|
rates
|
Continuously compounded rates, same length as ttm.
TYPE:
|
Source code in quantflow/rates/cir.py
calibrate_df
¶
Fit the yield curve to target discount factors.
Converts discount factors to continuously compounded rates then calls [calibrate][quantflow.rates.cir.CIRCurveCalibration.calibrate_df.calibrate].
| PARAMETER | DESCRIPTION |
|---|---|
ttm
|
Times to maturity in years.
TYPE:
|
target
|
Target discount factors, same length as ttm.
TYPE:
|