Interpolated Curves¶
Interpolated curves build the term structure directly from observed continuously compounded zero rates at a set of anchor dates, interpolating between them rather than fitting a parametric form.
The InterpolatedYieldCurve base class holds the interpolation nodes and derives the discount factor and instantaneous forward rate from the interpolated zero rate. Subclasses choose how the zero rate is interpolated between nodes.
InterpolatedLinearCurve interpolates the zero rate piecewise linearly, giving a forward rate that is linear on each segment.
InterpolatedMonotonicCubicCurve uses a shape-preserving PCHIP cubic spline, giving a smooth zero rate and forward rate that introduces no spurious local extrema between nodes.
quantflow.rates.interpolated.InterpolatedYieldCurve
pydantic-model
¶
Bases: YieldCurve
Base class for yield curves built by interpolating the zero rate.
The curve is defined by continuously compounded zero rates \(r_i\) at a set of anchor dates with times to maturity \(\tau_i\) measured from ref_date on an ACT/365 basis. The zero rate is interpolated between the nodes and the discount factor follows directly:
The instantaneous forward rate is then \(f(\tau) = r(\tau) + \tau\,r'(\tau)\). Outside the node range the zero rate is held flat (the first node value below \(\tau_1\) and the last node value beyond \(\tau_N\)).
Subclasses choose how the zero rate is interpolated between nodes: InterpolatedLinearCurve (piecewise linear) or InterpolatedMonotonicCubicCurve (shape-preserving PCHIP spline).
The anchor lists default to empty, leaving the curve uncalibrated until its calibrator fills in the nodes.
Fields:
-
ref_date(datetime) -
curve_type(str) -
anchor_dates(list[datetime]) -
anchor_rates(list[DecimalNumber])
anchor_dates
pydantic-field
¶
Maturity dates of the interpolation nodes, strictly after the reference date and in increasing order
anchor_rates
pydantic-field
¶
Continuously compounded zero rates at each anchor date (0.05 means 5%), same length as anchor_dates
curve_type
pydantic-field
¶
Type of the yield curve, used for serialization and discrimination
calibrator
¶
Return an [InterpolatedYieldCurveCalibration][ ...InterpolatedYieldCurveCalibration] wrapping this curve.
instantaneous_forward_rate
¶
discount_factor
¶
jacobian
¶
Analytical Jacobian of discount factors w.r.t. model parameters.
Returns None if no analytical Jacobian is available (default). Shape when not None: (len(ttm), n_params).
| PARAMETER | DESCRIPTION |
|---|---|
ttm
|
Times to maturity in years.
TYPE:
|
Source code in quantflow/rates/yield_curve.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.interpolated.InterpolatedLinearCurve
pydantic-model
¶
Bases: InterpolatedYieldCurve
Yield curve interpolating the zero rate piecewise linearly.
The zero rate \(r(\tau)\) is linear between adjacent nodes, so the instantaneous forward rate is linear on each segment.
Fields:
-
ref_date(datetime) -
anchor_dates(list[datetime]) -
anchor_rates(list[DecimalNumber]) -
curve_type(Literal['interpolated_linear_curve'])
anchor_dates
pydantic-field
¶
Maturity dates of the interpolation nodes, strictly after the reference date and in increasing order
anchor_rates
pydantic-field
¶
Continuously compounded zero rates at each anchor date (0.05 means 5%), same length as anchor_dates
instantaneous_forward_rate
¶
discount_factor
¶
calibrator
¶
Return an [InterpolatedYieldCurveCalibration][ ...InterpolatedYieldCurveCalibration] wrapping this curve.
jacobian
¶
Analytical Jacobian of discount factors w.r.t. model parameters.
Returns None if no analytical Jacobian is available (default). Shape when not None: (len(ttm), n_params).
| PARAMETER | DESCRIPTION |
|---|---|
ttm
|
Times to maturity in years.
TYPE:
|
Source code in quantflow/rates/yield_curve.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.interpolated.InterpolatedMonotonicCubicCurve
pydantic-model
¶
Bases: InterpolatedYieldCurve
Yield curve interpolating the zero rate with a monotone cubic spline.
The zero rate \(r(\tau)\) is interpolated with a shape-preserving cubic Hermite spline (PCHIP, Fritsch-Carlson) that never introduces a new local maximum or minimum between two nodes, giving a smooth zero rate and forward rate.
Fields:
-
ref_date(datetime) -
anchor_dates(list[datetime]) -
anchor_rates(list[DecimalNumber]) -
curve_type(Literal['interpolated_monotonic_cubic_curve'])
anchor_dates
pydantic-field
¶
Maturity dates of the interpolation nodes, strictly after the reference date and in increasing order
anchor_rates
pydantic-field
¶
Continuously compounded zero rates at each anchor date (0.05 means 5%), same length as anchor_dates
instantaneous_forward_rate
¶
discount_factor
¶
calibrator
¶
Return an [InterpolatedYieldCurveCalibration][ ...InterpolatedYieldCurveCalibration] wrapping this curve.
jacobian
¶
Analytical Jacobian of discount factors w.r.t. model parameters.
Returns None if no analytical Jacobian is available (default). Shape when not None: (len(ttm), n_params).
| PARAMETER | DESCRIPTION |
|---|---|
ttm
|
Times to maturity in years.
TYPE:
|
Source code in quantflow/rates/yield_curve.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.interpolated.InterpolatedYieldCurveCalibration
pydantic-model
¶
Bases: YieldCurveCalibration[InterpolatedYieldCurve]
Calibration wrapper for an interpolated yield curve.
The interpolated curve passes exactly through its nodes, so calibration is direct: the anchor dates and rates are set from the input times to maturity and continuously compounded rates. The free parameters are the anchor rates.
Fields:
-
yield_curve(Y)
get_params
¶
set_params
¶
get_bounds
¶
calibrate
¶
Set the curve nodes so it reprices the given rates exactly.
Maturity dates are reconstructed from the times to maturity relative to ref_date on an ACT/365 basis.
| PARAMETER | DESCRIPTION |
|---|---|
ttm
|
Times to maturity in years.
TYPE:
|
rates
|
Continuously compounded rates, same length as ttm.
TYPE:
|
Source code in quantflow/rates/interpolated.py
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.interpolated.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:
|
Source code in quantflow/rates/calibration.py
calibrate_historical_rates
¶
Model-specific hook for historical rate calibration.
Default implementation raises NotImplementedError. Subclasses with a stochastic short-rate dynamic override this method.
| PARAMETER | DESCRIPTION |
|---|---|
ttm
|
Times to maturity in years.
TYPE:
|
rates
|
Continuously compounded rates, same shape as ttm.
TYPE:
|
dt
|
Time increments between observations, same length as rates.
TYPE:
|