forwardrate
method, for a SpotRateCurve
and with arguments t1
and t2
, computes the forward rate between
two future terms that exist in the term structure.
library(rb3)
library(fixedincome)
df_yc <- yc_get("2022-05-20")
crv <- spotratecurve(
df_yc$r_252, df_yc$biz_days, "discrete", "business/252", "Brazil/ANBIMA",
refdate = df_yc$refdate[1]
)
crv
# 10 days and 20 days exist in the term structure
forwardrate(crv, term(10, "days"), term(20, "days"))
#> ForwardRate
#> 10 days 0.1289007
#> discrete business/252 Brazil/ANBIMA
This is equivalent to:
t1 <- term(10, "days")
t2 <- term(20, "days")
fact1 <- compound(crv[[t1]])
fact2 <- compound(crv[[t2]])
fwd_term <- t2 - t1
tf <- toyears(crv@daycount, fwd_term)
rates(crv@compounding, tf, fact2 / fact1)
#> [1] 0.1289007
So, to use forwardrate
you must pass, as t1
and t2
, terms that exist in the term structure, otherwise it returns NA
.
I took note for an extension that uses interpolation, once defined, so any term could be used.