Discount Curve
DiscountCurve
- class rivapy.marketdata.DiscountCurve(id: str, refdate: datetime | date, dates: List[date | datetime], df: List[float], interpolation: InterpolationType = InterpolationType.HAGAN_DF, extrapolation: ExtrapolationType = ExtrapolationType.NONE, daycounter: DayCounterType = DayCounterType.Act365Fixed)[source]
Bases:
objectDiscountcurve
- Parameters:
id (str) – Identifier of the discount curve.
refdate (Union[datetime, date]) – Reference date of the discount curve.
dates (List[Union[datetime, date]]) – List of dates belonging to the list of discount factors. All dates must be distinct and equal or after the refdate, otherwise an exception will be thrown.
df (List[float]) – List of discount factors. Length of list of discount factors must equal to length of list of dates, otherwise an exception will be thrown.
interpolation (enums.InterpolationType, optional) – Defaults to InterpolationType.HAGAN_DF.
extrapolation (enums.ExtrapolationType, optional) – Defaults to ExtrapolationType.NONE which does not allow to compute a discount factor for a date past all given dates given to this constructor.
daycounter (enums.DayCounterType, optional) – Daycounter used within the interpolation formula to compute a discount factor between two dates from the dates-list above. Defaults to DayCounterType.Act365Fixed.
- get_dates() Tuple[datetime][source]
Return list of dates of curve
- Returns:
List of dates
- Return type:
Tuple[datetime]
- get_df() Tuple[float][source]
Return list of discount factors
- Returns:
List of discount factors
- Return type:
Tuple[float]
- plot(days: int = 10, discount_factors: bool = False, **kwargs)[source]
Plots the discount curve using matplotlibs plot function. The timegrid includes the dates of the discount curve. Here either the discount factors or the zero rates (continuously compounded, ACT365 yearfraction) are plotted.
- Parameters:
days (int, optional) – The number of days between two plotted rates/discount factors. Defaults to 10.
discount_factors (bool, optional) – If True, discount factors will be plotted, otherwise the rates. Defaults to False.
**kwargs – optional arguments that will be directly passed to the matplotlib plot function
- value(refdate: date | datetime, d: date | datetime, payment_dates=None, annual_payment_frequency=None) float[source]
Return discount factor for a given date
- Parameters:
refdate (Union[date, datetime]) – The reference date. If the reference date is in the future (compared to the curves reference date), the forward discount factor will be returned.
d (Union[date, datetime]) – The date for which the discount factor will be returned. Assumption is that the day given already follows correct business logic (e.g., roll convention)
- Returns:
discount factor
- Return type:
float
- value_fwd(val_date: date | datetime, d1: date | datetime, d2: date | datetime) float[source]
Return forward discount factor for a given date (without dependencies from pyvacon)
The value_fwd() method has been updated to support forward valuation scenarios (val_date > refdate) by rebasing the curve from its construction date to the new valuation date.
The rebasement follows the relationship:
DF(val_date, t) = DF(refdate, t) / DF(refdate, val_date)
This adjustment ensures that discount factors and forward rates remain consistent across time, even when the valuation date is later than the curve’s reference date.
This approach aligns with market-standard practices for OIS and collateralized discounting frameworks, where forward discounting must be time-consistent with the curve’s anchor date.
- Parameters:
refdate (Union[date, datetime]) – The reference date. If the reference date is in the future (compared to the curves reference date), the forward discount factor will be returned.
d (Union[date, datetime]) – The date for which the discount factor will be returned. Assumption is that the day given already follows correct business logic (e.g., roll convention)
- Returns:
discount factor
- Return type:
float
- value_fwd_rate(refdate: date | datetime, d1: date | datetime, d2: date | datetime) float[source]
Return forward continuously compounded zero rate for a given date
- Parameters:
refdate (Union[date, datetime]) – The reference date. If the reference date is in the future (compared to the curves reference date), the forward rate will be returned.
d1 (Union[date, datetime]) – The start date of the period for which the forward continuously compounded zero rate will be returned.
d2 (Union[date, datetime]) – The end date of the period for which the forward continuously compounded zero rate will be returned.
- Returns:
forward continuously compounded zero rate
- Return type:
float
- value_rate(refdate: date | datetime, d: date | datetime) float[source]
Return continuously compounded zero rate for a given date
- Parameters:
refdate (Union[date, datetime]) – The reference date. If the reference date is in the future (compared to the curves reference date), the forward rate will be returned.
d (Union[date, datetime]) – The date for which the continuously compounded zero rate will be returned.
- Returns:
continuously compounded zero rate
- Return type:
float
DiscountCurveParametrized
Parametrizations
- class rivapy.marketdata.NelsonSiegel(beta0: float, beta1: float, beta2: float, tau: float)[source]
Bases:
FactoryObjectNelson-Siegel parametrization for rates and yields, see Nelson and Siegel[1].
This parametrization is mostly used to parametrize rate curves and can be used in conjunction with
rivapy.marketdata.DiscountCurveParametrized. It is defined by\[f(t) = \beta_0 + (\beta_1+\beta_2)\frac{1-e^{-t/\tau}}{t/\tau} -\beta_2e^{t/\tau}\]- Parameters:
beta0 (float) – This parameter is the asymptotic (for arbitrary large maturities) rate, see formula above.
beta1 (float) – beta0 + beta1 give the short term rate, see formula above.
beta2 (float) – This parameter controls the size of the hump, see formula above.
tau (float) – This parameter controls the location of the hump, see formula above.
Examples
>>> from rivapy.marketdata.curves import NelsonSiegel, DiscountCurveParametrized >>> ns = NelsonSiegel(beta0=0.05, beta1 = 0.02, beta2=0.1, tau=1.0) >>> dc = DiscountCurveParametrized('DC', refdate = dt.datetime(2023,1,1), rate_parametrization=ns, daycounter = DayCounterType.Act365Fixed) >>> dates = [dt.datetime(2023,1,1) + dt.timedelta(days=30*days) for days in range(120)] >>> values = [dc.value(refdate = dt.datetime(2023,1,1),d=d) for d in dates] >>> plt.plot(dates, values)
- static compute(beta0: float, beta1: float, beta2: float, tau: float, T: float) float[source]
_summary_
- Parameters:
beta0 (float) – longrun
beta1 (float) – beta0 + beta1 = shortrun
beta2 (float) – hump or through
tau (float) – locaton of hump
T (float) – _description_
- Returns:
_description_
- Return type:
float
- class rivapy.marketdata.NelsonSiegelSvensson(beta0: float, beta1: float, beta2: float, beta3: float, tau: float, tau2: float)[source]
Bases:
NelsonSiegelNelson-Siegel parametrization for rates and yields, see Nelson and Siegel[1].
This parametrization is mostly used to parametrize rate curves and can be used in conjunction with
rivapy.marketdata.DiscountCurveParametrized. It is defined by\[f(t) = \beta_0 + (\beta_1+\beta_2)\frac{1-e^{-t/\tau}}{t/\tau} -\beta_2e^{t/\tau}\]- Parameters:
beta0 (float) – This parameter is the asymptotic (for arbitrary large maturities) rate, see formula above.
beta1 (float) – beta0 + beta1 give the short term rate, see formula above.
beta2 (float) – This parameter controls the size of the hump, see formula above.
tau (float) – This parameter controls the location of the hump, see formula above.
Examples
>>> from rivapy.marketdata.curves import NelsonSiegel, DiscountCurveParametrized >>> ns = NelsonSiegel(beta0=0.05, beta1 = 0.02, beta2=0.1, tau=1.0) >>> dc = DiscountCurveParametrized('DC', refdate = dt.datetime(2023,1,1), rate_parametrization=ns, daycounter = DayCounterType.Act365Fixed) >>> dates = [dt.datetime(2023,1,1) + dt.timedelta(days=30*days) for days in range(120)] >>> values = [dc.value(refdate = dt.datetime(2023,1,1),d=d) for d in dates] >>> plt.plot(dates, values)
- class rivapy.marketdata.ConstantRate(rate: float)[source]
Bases:
FactoryObjectContinuously compounded flat rate object that can be used in conjunction with
rivapy.marketdata.DiscountCurveParametrized.- Parameters:
rate (float) – The constant rate.
DiscountCurveParametrized
- class rivapy.marketdata.DiscountCurveParametrized(obj_id: str, refdate: datetime | date, rate_parametrization, daycounter: DayCounterType | str = DayCounterType.Act365Fixed)[source]
Bases:
FactoryObject_summary_
- Parameters:
obj_id (str) – _description_
refdate (Union[datetime, date]) – _description_
rate_parametrization (Callable[[float], float]) – _description_
daycounter (Union[DayCounterType, str], optional) – _description_. Defaults to DayCounterType.Act365Fixed.
- value(refdate: date | datetime, d: date | datetime) float[source]
Return discount factor for a given date
- Parameters:
refdate (Union[date, datetime]) – The reference date. If the reference date is in the future (compared to the curves reference date), the forward discount factor will be returned.
d (Union[date, datetime]) – The date for which the discount factor will be returned
- Returns:
discount factor
- Return type:
float
- value_fwd(refdate: date | datetime, d1: date | datetime, d2: date | datetime) float[source]
Return forward discount factor for a given date
- Parameters:
refdate (Union[date, datetime]) – The reference date. If the reference date is in the future (compared to the curves reference date), the forward discount factor will be returned.
d1 (Union[date, datetime]) – The start date of the forward period
d2 (Union[date, datetime]) – The end date of the forward period
- Returns:
forward rate
- Return type:
float
- value_fwd_rate(refdate: date | datetime, d1: date | datetime, d2: date | datetime) float[source]
Return forward continuously compounded zero rate for a given date
- Parameters:
refdate (Union[date, datetime]) – The reference date. If the reference date is in the future (compared to the curves reference date), the forward rate will be returned.
d1 (Union[date, datetime]) – The start date of the period for which the forward continuously compounded zero rate will be returned.
d2 (Union[date, datetime]) – The end date of the period for which the forward continuously compounded zero rate will be returned.
- Returns:
forward continuously compounded zero rate
- Return type:
float
- value_rate(refdate: date | datetime, d: date | datetime) float[source]
Return the continuous rate for a given date
- Parameters:
refdate (Union[date, datetime]) – The reference date. If the reference date is in the future (compared to the curves reference date), the forward discount factor will be returned.
d (Union[date, datetime]) – The date for which the discount factor will be returned
- Returns:
continuous rate
- Return type:
float