It is the time interval used in calculations with interest rates. The Term class represents the period used to discount or compound a spot rate.
The Term object is defined by its numeric value and its unit, that can be
"days", "months" or "years".
For example:
term(6, "months")
#> [1] "6 months"It represents a period of 6 months. The Term object can also be created from a string representation of a Term.
as.term("6 months")
#> [1] "6 months"Since the Term object inherits from a numeric, it inherits all numeric
operations.
Numeric values can be summed or subtracted from a Term object numeric part.
term(1, "days") + 1
#> [1] "2 days"Arithmetic and comparison operations between Term objects work when both
have the same units. +, - and %% return a Term, / and %/% return
a numeric and comparisons return a logical.
term(1, "days") + term(2, "days")
#> [1] "3 days"
term(10, "days") / term(5, "days")
#> [1] 2
term(10, "days") > term(5, "days")
#> [1] TRUETerms with different units raise an error, because converting them
requires a daycount; use todays(), tomonths() or toyears() first,
or evaluate the operation with with_daycount().
try(term(1, "months") + term(12, "days"))
#> Error : Terms with different units: convert them first with todays(), tomonths() or toyears(), or use with_daycount()
todays(daycount("business/252"), term(1, "months")) + term(12, "days")
#> [1] "33 days"
with_daycount("business/252", term(1, "months") + term(12, "days"))
#> [1] "33 days"