Yield Curve¶
quantflow.rates.yield_curve.YieldCurve
pydantic-model
¶
Bases: BaseModel, ABC
Abstract base class for yield curves
Fields:
-
ref_date(datetime) -
curve_type(str)
curve_type
pydantic-field
¶
Type of the yield curve, used for serialization and discrimination
instantaneous_forward_rate
abstractmethod
¶
Calculate the instantaneous forward rate for a given time to maturity.
The instantaneous forward rate is related to 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.
Source code in quantflow/rates/yield_curve.py
discount_factor
abstractmethod
¶
Calculate the discount factor for a given time to maturity.
The discount factor is related to the instantaneous forward rate by the following formula:
where \(f(\tau)\) is the instantaneous forward rate 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.
Source code in quantflow/rates/yield_curve.py
calibrator
¶
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.no_discount.NoDiscountCurve
pydantic-model
¶
Bases: YieldCurve
Flat yield curve with zero rates (discount factor is always 1).
It has no parameters to calibrate, therefore calibrator returns None and the curve is treated as fixed by curve calibrations.
Fields:
-
ref_date(datetime) -
curve_type(Literal['no_discount_curve'])
instantaneous_forward_rate
¶
discount_factor
¶
calibrator
¶
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.AnyYieldCurve
module-attribute
¶
AnyYieldCurve = Union[
NoDiscountCurve,
CIRCurve,
InterpolatedLinearCurve,
InterpolatedMonotonicCubicCurve,
NelsonSiegelCurve,
VasicekCurve,
]
Discriminated union of all concrete YieldCurve implementations.
Use this type for Pydantic fields that can hold any curve model, such as the quote and asset curves of a VolSurface.
The curve_type discriminator selects the concrete class during validation,
so curves serialise to and from JSON without losing their type.