knitr::opts_chunk$set(collapse = TRUE, comment = "#>")
fmbasics makes it easy to work with interest rates and discount factors. You can convert interest rates to discount factors and vice-versa.
Let's make an interest rate object:
library("fmdates") library("fmbasics") # Quarterly compounding, with Actual/365 day basis (rate <- InterestRate(value = 0.04, compounding = 4, day_basis = 'act/365'))
You can convert this rate to another rate with a different compounding/day basis:
as_InterestRate(rate, compounding = 2) as_InterestRate(rate, day_basis = 'act/360') as_InterestRate(rate, compounding = Inf, day_basis = '30/360us')
You can perform arithmetic on interest rates. Rates are implicitly converted to equivalent day basis and compounding before the operation is performed on the rates' values.
rate1 <- InterestRate(0.04, 2, 'act/365') rate2 <- InterestRate(0.01, Inf, 'act/360') rate1 + rate2
You can also convert interest rates into discount factors:
library("lubridate") df <- as_DiscountFactor(rate, ymd(20140101), ymd(20140401))
The InterestRate
class is vectorised.
rates <- InterestRate(seq(0.04, 0.05, 1e-4), 2, 'act/365') rates[23:26] rates[23:26] <- InterestRate(0.05, 2, 'act/365') rates[23:26]
Let's make a discount factor object:
(df <- DiscountFactor(0.9, ymd(20140101), ymd(20150101)))
You can convert discount factors to interest rates.
as_InterestRate(df, compounding = 2, day_basis = 'act/365')
The DiscountFactor
class is vectorised.
dfs <- DiscountFactor(seq(1, 0.9, -1e-3), ymd(20140101), ymd(20150101) + days(0:100)) dfs[23:26]
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.