SpotRate-class | R Documentation |
The SpotRate
class abstracts the interst rate and has methods
to handle many calculations on it.
The SpotRate
class fully specifies spot rates.
It has:
the spot rate values which are numeric values representing the rate.
the compounding regime that specifies how to compound the spot
rate. This is a Compounding
object.
the daycount rule to compute the compounding periods right adjusted to the spot rate frequency.
the calendar according to which the number of days are counted.
The SpotRate
class is a numeric
, that represents the
interest rate and that has the slots: compounding
, daycount
and calendar
.
For example, an annual simple interest rate of 6%, that compounds in calendar days, is defined as follows:
sr_simple <- spotrate(0.06, "simple", "actual/360", "actual") sr_simple #> [1] "0.06 simple actual/360 actual"
actual/360
is the daycount rule and actual
is the calendar.
Differently, an annual compound interest rate of 10%, that compounds
in business days according to calendar Brazil/ANBIMA
is
sr_disc <- spotrate(0.1, "discrete", "business/252", "Brazil/ANBIMA") sr_disc #> [1] "0.1 discrete business/252 Brazil/ANBIMA"
The calendar
slot is a bizdays
calendar.
An $100,000 investment in an instrument that pays that interst rate for 5 years has the future value.
100000 * compound(sr_disc, term(5, "years")) #> [1] 161051
for the simple interest rate we have
100000 * compound(sr_simple, term(5, "years")) #> [1] 130000
SpotRate objects can be created with vectors
rates <- c(1.69, 0.16, 0.07, 0.72, 0.10, 1.60, 0.18, 1.56, 0.60, 1.69) sr_vec <- spotrate(rates, "discrete", "business/252", "Brazil/ANBIMA") sr_vec #> [1] "1.69 discrete business/252 Brazil/ANBIMA" #> [2] "0.16 discrete business/252 Brazil/ANBIMA" #> [3] "0.07 discrete business/252 Brazil/ANBIMA" #> [4] "0.72 discrete business/252 Brazil/ANBIMA" #> [5] "0.10 discrete business/252 Brazil/ANBIMA" #> [6] "1.60 discrete business/252 Brazil/ANBIMA" #> [7] "0.18 discrete business/252 Brazil/ANBIMA" #> [8] "1.56 discrete business/252 Brazil/ANBIMA" #> [9] "0.60 discrete business/252 Brazil/ANBIMA" #> [10] "1.69 discrete business/252 Brazil/ANBIMA"
and can be put into a data.frame
data.frame(spot_rate = sr_vec) #> spot_rate #> 1 1.69 discrete business/252 Brazil/ANBIMA #> 2 0.16 discrete business/252 Brazil/ANBIMA #> 3 0.07 discrete business/252 Brazil/ANBIMA #> 4 0.72 discrete business/252 Brazil/ANBIMA #> 5 0.10 discrete business/252 Brazil/ANBIMA #> 6 1.60 discrete business/252 Brazil/ANBIMA #> 7 0.18 discrete business/252 Brazil/ANBIMA #> 8 1.56 discrete business/252 Brazil/ANBIMA #> 9 0.60 discrete business/252 Brazil/ANBIMA #> 10 1.69 discrete business/252 Brazil/ANBIMA
once in a data.frame
, dplyr verbs can be used to manipulate it.
require(dplyr, warn.conflicts = FALSE) #> Loading required package: dplyr data.frame(spot_rate = sr_vec) |> mutate(comp = compound(spot_rate, term(5, "months"))) #> spot_rate comp #> 1 1.69 discrete business/252 Brazil/ANBIMA 1.510301 #> 2 0.16 discrete business/252 Brazil/ANBIMA 1.063794 #> 3 0.07 discrete business/252 Brazil/ANBIMA 1.028592 #> 4 0.72 discrete business/252 Brazil/ANBIMA 1.253536 #> 5 0.10 discrete business/252 Brazil/ANBIMA 1.040512 #> 6 1.60 discrete business/252 Brazil/ANBIMA 1.489037 #> 7 0.18 discrete business/252 Brazil/ANBIMA 1.071398 #> 8 1.56 discrete business/252 Brazil/ANBIMA 1.479449 #> 9 0.60 discrete business/252 Brazil/ANBIMA 1.216326 #> 10 1.69 discrete business/252 Brazil/ANBIMA 1.510301
SpotRate is numeric
, so it executes arithmetic and comparison operations
with numeric
objects.
data.frame(spot_rate = sr_vec) |> mutate( new_spot_rate = spot_rate + 0.02, check_gt_1pp = spot_rate > 0.01, check_gt_nsr = spot_rate > new_spot_rate ) #> spot_rate #> 1 1.69 discrete business/252 Brazil/ANBIMA #> 2 0.16 discrete business/252 Brazil/ANBIMA #> 3 0.07 discrete business/252 Brazil/ANBIMA #> 4 0.72 discrete business/252 Brazil/ANBIMA #> 5 0.10 discrete business/252 Brazil/ANBIMA #> 6 1.60 discrete business/252 Brazil/ANBIMA #> 7 0.18 discrete business/252 Brazil/ANBIMA #> 8 1.56 discrete business/252 Brazil/ANBIMA #> 9 0.60 discrete business/252 Brazil/ANBIMA #> 10 1.69 discrete business/252 Brazil/ANBIMA #> new_spot_rate check_gt_1pp check_gt_nsr #> 1 1.71 discrete business/252 Brazil/ANBIMA TRUE FALSE #> 2 0.18 discrete business/252 Brazil/ANBIMA TRUE FALSE #> 3 0.09 discrete business/252 Brazil/ANBIMA TRUE FALSE #> 4 0.74 discrete business/252 Brazil/ANBIMA TRUE FALSE #> 5 0.12 discrete business/252 Brazil/ANBIMA TRUE FALSE #> 6 1.62 discrete business/252 Brazil/ANBIMA TRUE FALSE #> 7 0.20 discrete business/252 Brazil/ANBIMA TRUE FALSE #> 8 1.58 discrete business/252 Brazil/ANBIMA TRUE FALSE #> 9 0.62 discrete business/252 Brazil/ANBIMA TRUE FALSE #> 10 1.71 discrete business/252 Brazil/ANBIMA TRUE FALSE
SpotRate vectors also are created with the concatenation function c
.
c(sr_disc, 0.1, 0.13, 0.14, 0.15) #> [1] "0.10 discrete business/252 Brazil/ANBIMA" #> [2] "0.10 discrete business/252 Brazil/ANBIMA" #> [3] "0.13 discrete business/252 Brazil/ANBIMA" #> [4] "0.14 discrete business/252 Brazil/ANBIMA" #> [5] "0.15 discrete business/252 Brazil/ANBIMA"
Furtherly, all indexing operations of numeric objects are supported by SpotRate objects.
Operations involving SpotRate objects with different compounding
,
daycount
or calendar
, raise errors.
This happens with the following operations:
Compare: >, <, <=, >=
Arithmetic: +, -, *, /
Concatenation: c
try(sr_simple + sr_disc) #> Error in stop_if_spotrate_slots_differ(e1, e2, "SpotRate objects have different slots") : #> SpotRate objects have different slots try(sr_simple > sr_disc) #> Error in stop_if_spotrate_slots_differ(e1, e2, "SpotRate objects have different slots") : #> SpotRate objects have different slots try(c(sr_simple, sr_disc)) #> Error in stop_if_spotrate_slots_differ(x, values_, "SpotRate objects have different slots") : #> SpotRate objects have different slots
The SpotRate
objects are annual rates.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.