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.
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
Calendars are associated with three key methods:
shift. These are described below.
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 object is masked from 'package:base': #> #> date
library("fmdates") ausy <- AUSYCalendar() aume <- AUMECalendar() syme <- c(ausy, aume) # handy JointCalendar construction approach is_good(ymd(20140404), ausy)
#>  TRUE
#>  FALSE
#>  TRUE
There are a number of different ways to adjust a bad day to a good day using
adjust(). Some examples include:
#>  "2014-04-04"
#>  "2014-11-28"
#>  "2014-11-03"
#>  "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
#>  "2012-03-02"
#>  "2012-03-29"
#>  "2012-03-30"
#>  "2013-05-31"
#> The following period values are not supported by shift and are ignored: hour
#>  "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
# 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)
#>  2012-01-03 UTC--2012-04-03 UTC 2012-04-03 UTC--2012-07-03 UTC #>  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)
#>  2012-01-03 UTC--2012-03-05 UTC 2012-03-05 UTC--2012-06-04 UTC #>  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
#>  2
#>  2.087671