Over-the-counter (OTC) derivatives comprise a significant proportion of trading activity in global financial markets. Their general contractual conventions are specified in what are known as International Swap and Derivatives Association (ISDA) definitions. For example, FX and currency option transactions are governed by the 1998 FX and Currency Options Definitions and swap transactions are governed by the 2006 ISDA Definitions. They describe in meticulous detail, among other things, how the dates of certain financial events should be determined. This includes how dates are defined to be good or bad and how bad dates are to be adjusted to good dates. They also define how to determine the length of time between two dates.
The Calendar
class is extended by city specific calendar
classes (e.g. USNYCalendar
). The functions that create such
city calendars have a name prefixed by four upper case letters: the
first two being a country code (e.g. US
) and the latter two
being a city code (e.g. NY
). Supported calendars are
documented in ?Calendar
.
Calendars are associated with three key methods:
is_good
, adjust
and shift
. These
are described below.
The is_good()
method determines whether a date or vector
of dates is a business day in a given locale (usually a city). Some
examples of its use are:
#>
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#>
#> date, intersect, setdiff, union
library("fmdates")
ausy <- AUSYCalendar()
aume <- AUMECalendar()
syme <- c(ausy, aume) # handy JointCalendar construction approach
is_good(ymd(20140404), ausy)
#> [1] TRUE
#> [1] FALSE
#> [1] TRUE
There are a number of different ways to adjust a bad day to a good
day using adjust()
. Some examples include:
#> [1] "2014-04-04"
#> [1] "2014-11-28"
#> [1] "2014-11-03"
#> [1] "2014-11-14"
Occasionally it is necessary to shift a date by a certain period or
to a certain epoch. The can be done by using shift()
.
#> [1] "2012-03-02"
#> [1] "2012-03-29"
#> [1] "2012-03-30"
#> [1] "2013-05-31"
#> The following period values are not supported by shift and are ignored: hour
#> [1] "2012-02-29"
With the aforementioned machinery, it is now possible to determine a
schedule of dates that are required for a given financial contract. For
example, counterparties to a vanilla interest rate swaps exchanged fixed
rate payments in return for floating rate payments with regular
frequency during the life of the contract. These form payment periods
which can be determined using generate_schedule()
.
# No stub
generate_schedule(effective_date = ymd(20120103), termination_date = ymd(20130103),
tenor = months(3), calendar = AUSYCalendar(), bdc = "mf", stub = "short_front",
eom_rule = FALSE)
#> [1] 2012-01-03 UTC--2012-04-03 UTC 2012-04-03 UTC--2012-07-03 UTC
#> [3] 2012-07-03 UTC--2012-10-03 UTC 2012-10-03 UTC--2013-01-03 UTC
# Front stub
generate_schedule(effective_date = ymd(20120103), termination_date = ymd(20121203),
tenor = months(3), calendar = AUSYCalendar(), bdc = "mf", stub = "short_front",
eom_rule = FALSE)
#> [1] 2012-01-03 UTC--2012-03-05 UTC 2012-03-05 UTC--2012-06-04 UTC
#> [3] 2012-06-04 UTC--2012-09-03 UTC 2012-09-03 UTC--2012-12-03 UTC
It is possible to determine the length of a period. This known as the
day count fraction, year fraction or day count. The package has
implemented a number of common day counters (see
?year_frac
).
#> [1] 2
#> [1] 2.087671