Learn R Programming

fmbasics - Financial Market Building Blocks

Implements basic financial market objects like currencies, currency pairs, interest rates and interest rate indices. You will be able to use Benchmark instances of these objects which have been defined using their most common conventions or those defined by International Swap Dealer Association (ISDA, https://www.isda.org) legal documentation.

Basic objects

You can create instances of key currencies and currency pairs (and of course create your own implementations):

library("fmdates")
library("fmbasics")
AUD()
#> <Currency> AUD
AUDUSD()
#> <CurrencyPair> AUDUSD

These come with implementations of handy methods:

library("lubridate")
to_fx_value(dates = ymd(20171230), tenor = "spot", x = AUDUSD())
#> [1] "2018-01-03"
to_fx_value(ymd(20171230), months(3), AUDUSD())
#> [1] "2018-04-03"

You can create instances of key IBOR or ONIA interest rate indices:

USDLIBOR(months(3))
#> <IborIndex> 3m USD LIBOR
EONIA()
#> <CashIndex> EONIA

These also come with implementations of handy methods:

to_reset(dates = as.Date("2017-01-20"), index = USDLIBOR(months(3)))
#> [1] "2017-01-18"
to_value(as.Date("2017-01-20"), USDLIBOR(months(3)))
#> [1] "2017-01-24"
to_maturity(as.Date("2017-01-20"), USDLIBOR(months(3)))
#> [1] "2017-04-20"

Interest rates and discount factors

You can create and perform basic manipulation of interest rates and discount factors:

rr <- InterestRate(value = 0.01, compounding = Inf, day_basis = "act/365")
as_DiscountFactor(rr, d1 = ymd(20170120), d2 = ymd(20210120))
#> <DiscountFactor> 0.960763116514576, 2017-01-20--2021-01-20
# Convert to different rate basis
as_InterestRate(rr, day_basis = "act/360")
#> <InterestRate> 0.9863014%, CONTINUOUS, ACT/360
as_InterestRate(rr, compounding = 2, day_basis = "act/360")
#> <InterestRate> 0.9887373%, SEMI-ANNUAL, ACT/360
dd <- DiscountFactor(0.75, d1 = ymd(20170120), d2 = ymd(20210120))
as_InterestRate(dd, compounding = Inf, day_basis = "act/360")
#> <InterestRate> 7.088675%, CONTINUOUS, ACT/360

Pricing objects

It is also possible to create and interpolate on zero coupon interest rate curves:

zc <- build_zero_curve()
plot(zc$pillar_times, zc$pillar_zeros, xlab = 'Years', ylab = 'Zero')

interpolate(zc, year_frac(zc$reference_date, ymd(20170331), "act/365"))
#> [1] 0.0187453
interpolate_zeros(zc, ymd(20170331))
#> <InterestRate> 1.87453%, CONTINUOUS, ACT/365
interpolate_fwds(zc, ymd(20170331), ymd(20170630))
#> <InterestRate> 1.837274%, SIMPLE, ACT/365
interpolate_dfs(zc, ymd(20170331), ymd(20170630))
#> <DiscountFactor> 0.995440285935839, 2017-03-31--2017-06-30

Further details can be found in this package's help pages and vignettes (vignette(package = "fmbasics"))

Copy Link

Version

Install

install.packages('fmbasics')

Monthly Downloads

35

Version

0.3.0

License

GPL-2

Issues

Pull Requests

Stars

Forks

Maintainer

Imanuel Costigan

Last Published

January 6th, 2018

Functions in fmbasics (0.3.0)

DiscountFactor

DiscountFactor class
IborIndex

IborIndex class
as_DiscountFactor

Coerce to DiscountFactor
as_InterestRate

Coerce to InterestRate
fmbasics

fmbasics: Financial Market Building Blocks
iborindices

Standard IBOR
is.CurrencyPair

Inherits from CurrencyPair class
is.DiscountFactor

Inherits from DiscountFactor
Interpolation

Interpolation
MultiCurrencyMoney

MultiCurrencyMoney
is.ZeroCurve

Inherits from ZeroCurve
is_valid_compounding

Compounding frequencies
CurrencyPair

CurrencyPair class
CurrencyPairConstructors

Handy CurrencyPair constructors
interpolate

Interpolate values from an object
interpolate.ZeroCurve

Interpolate a ZeroCurve
CashFlow

Create a CashFlow
CashIndex

CashIndex class
is.Currency

Inherits from Currency
is.MultiCurrencyMoney

Inherits from MultiCurrencyMoney
is.SingleCurrencyMoney

Inherits from SingleCurrencyMoney
SingleCurrencyMoney

SingleCurrencyMoney
ZeroCurve

ZeroCurve class
is.CashFlow

Inherits from CashFlow
as_tibble.ZeroCurve

ZeroCurve attributes as a data frame
build_zero_curve

Build a ZeroCurve from example data set
Currency

Build a Currency
CurrencyConstructors

Handy Currency constructors
is.InterestRate

Inherits from InterestRate
is.Interpolation

Check Interpolation class
interpolate_dfs

Interpolate forward rates and discount factors
interpolate_zeros

Interpolate zeros
iso.CurrencyPair

Get ISO
oniaindices

Standard ONIA
CurrencyPairMethods

CurrencyPair methods
DiscountFactor-operators

DiscountFactor operations
indexcheckers

Index class checkers
indexshifters

Index date shifters
InterestRate-operators

InterestRate operations
InterestRate

InterestRate class