volkit.utils¶
- volkit.utils.discount_to_rate(discount_rate, *, t=None, days=None, days_per_year=365)[source]¶
Convert a discount factor into a continuously compounded annualized rate.
Exactly one of
tordaysmust be provided to specify the time horizon.- Parameters:
discount_rate (float) – Discount factor. Must be finite and strictly positive (> 0).
t (float, optional) – Time horizon in years. Mutually exclusive with
days.days (int or float, optional) – Time horizon in days. Mutually exclusive with
t.days_per_year (int or float, default=365) – Number of days per year used to convert
daysinto years.
- Returns:
Continuously compounded annualized rate corresponding to the discount factor.
- Return type:
- Raises:
ValueError – If neither or both of
tanddaysare provided. Ifdiscount_rateis not finite or not strictly positive. If the resulting time horizon (years) is not strictly positive.
Examples
>>> discount_to_rate(0.95, t=0.5) # roughly half a year 0.102586... >>> discount_to_rate(0.95, days=90) # 90 trading days with 365/yr 0.20802... >>> discount_to_rate(1.0, t=1.0) 0.0
- volkit.utils.rate_to_discount(rate, *, t=None, days=None, days_per_year=365)[source]¶
Convert a continuously compounded annualized rate into a discount factor.
Exactly one of
tordaysmust be provided to specify the time horizon.- Parameters:
rate (float) – Continuously compounded annualized rate. May be negative or positive, but must be finite (no NaN/Inf).
t (float, optional) – Time horizon in years. Mutually exclusive with
days.days (int or float, optional) – Time horizon in days. Mutually exclusive with
t.days_per_year (int or float, default=365) – Number of days per year used to convert
daysinto years.
- Returns:
Discount factor in (0, +inf) given by
exp(-rate * t_years).- Return type:
- Raises:
ValueError – If neither or both of
tanddaysare provided. Ifrateis not finite. If the resulting time horizon (years) is not strictly positive.
Examples
>>> rate_to_discount(0.1, t=0.5) 0.9512... >>> rate_to_discount(0.1, days=90) 0.9756... >>> rate_to_discount(0.0, t=1.0) 1.0