diff --git a/R/R-bizdays-package.r b/R/R-bizdays-package.r index 1dc55fd..5445388 100644 --- a/R/R-bizdays-package.r +++ b/R/R-bizdays-package.r @@ -22,7 +22,7 @@ #' handle the recycle rule. #' #' @author -#' Wilson Freitas +#' Wilson Freitas <\url{http://aboutwilson.net}> #' #' @seealso #' CRAN Task View: Empirical Finance diff --git a/R/calendar.R b/R/calendar.R index 10323cf..320d674 100644 --- a/R/calendar.R +++ b/R/calendar.R @@ -167,6 +167,16 @@ print.Calendar <- function(x, ...) { #' @param dates dates to be adjusted #' @param cal an instance of \code{Calendar} #' +#' @section Date types accepted: +#' +#' The argument \code{dates} accepts \code{Date} objects and any +#' object that returns a valid \code{Date} object when passed through +#' \code{as.Date}, which include all \code{POSIX*} classes and \code{character} +#' objects with ISO formatted dates. +#' +#' @return +#' \code{Date} objects adjusted accordingly. +#' #' @name adjust.date NULL @@ -214,30 +224,60 @@ adjust.previous.Date <- function(dates, cal=bizdays.options$get('default.calenda #' Computes business days between two dates. #' -#' This function computes the amount of business days between 2 taking into -#' account the holidays passed to the Calendar function. +#' Returns the amount of business days between 2 dates taking into account the +#' provided \code{Calendar} (or \code{bizdays.options$get("default.calendar")}). #' -#' @param from the initial date (or a vector of dates) -#' @param to the final date (or a vector of dates). +#' @param from the initial dates +#' @param to the final dates #' @param cal an instance of \code{Calendar} -#' @export +#' +#' @section Date types accepted: +#' +#' The arguments \code{from} and \code{to} accept \code{Date} objects and any +#' object that returns a valid \code{Date} object when passed through +#' \code{as.Date}, which include all \code{POSIX*} classes and \code{character} +#' objects with ISO formatted dates. +#' +#' @section Recycle rule: +#' +#' These arguments handle the recycle rule so vectors of dates can be provided +#' and once those vectors differs in length the recycle rule is applied. +#' +#' @section Date adjustment: +#' +#' \code{from} and \code{to} are adjusted when nonworking dates are +#' provided. Since \code{bizdays} function returns the amount of business days +#' between 2 dates, it must start and end in business days. +#' The default behavior, that is defined in \code{Calendar}'s instantiation with +#' \code{adjust.from} and \code{adjust.to}, reproduces the Excel's NETWORKDAYS. +#' A common and useful setting is \code{adjust.to=adjust.next} which moves +#' expiring maturities to the next business day, once it is not. +#' +#' @return +#' \code{integer} objects representing the amount of business days. +#' #' @examples #' data(holidaysANBIMA) #' cal <- Calendar(holidaysANBIMA, weekdays=c("saturday", "sunday")) +#' #' bizdays("2013-01-02", "2013-01-31", cal) -#' # Once you have a default calendar set +#' +#' # Once you have a default calendar set, cal does not need to be provided #' bizdays.options$set(default.calendar=cal) #' bizdays("2013-01-02", "2013-01-31") -bizdays <- function(from, to, cal) UseMethod('bizdays') +#' +#' dates <- bizseq("2013-01-01", "2013-01-10") +#' bizdays(dates, "2014-01-31") +#' +#' @export +bizdays <- function(from, to, cal=bizdays.options$get('default.calendar')) UseMethod('bizdays') -#' @rdname bizdays #' @export bizdays.default <- function(from, to, cal=bizdays.options$get('default.calendar')) { from <- as.Date(from) bizdays(from, to, cal) } -#' @rdname bizdays #' @export bizdays.Date <- function(from, to, cal=bizdays.options$get('default.calendar')) { to <- as.Date(to) @@ -257,31 +297,45 @@ bizdays.Date <- function(from, to, cal=bizdays.options$get('default.calendar')) cal$bizdays(as.integer(from), as.integer(to)) } -#' Checks if the given date is a business day. +#' Checks if the given dates are business days. #' -#' This function returns TRUE if the given date is a business day and FALSE +#' Returns \code{TRUE} if the given date is a business day and \code{FALSE} #' otherwise. #' -#' @param dates a date or a vector of dates to be checked +#' @param dates dates to be checked #' @param cal an instance of \code{Calendar} -#' @export +#' +#' @section Date types accepted: +#' +#' The argument \code{dates} accepts \code{Date} objects and any +#' object that returns a valid \code{Date} object when passed through +#' \code{as.Date}, which include all \code{POSIX*} classes and \code{character} +#' objects with ISO formatted dates. +#' +#' @return +#' \code{logical} objects informing that given dates are or are not business days. +#' #' @examples #' data(holidaysANBIMA) #' cal <- Calendar(holidaysANBIMA, weekdays=c("saturday", "sunday")) +#' #' is.bizday("2013-01-02", cal) -#' # Using the default Calendar +#' +#' # Once you have a default calendar set, cal does not need to be provided +#' bizdays.options$set(default.calendar=cal) +#' #' dates <- seq(as.Date("2013-01-01"), as.Date("2013-01-05"), by="day") #' is.bizday(dates) -is.bizday <- function(dates, cal) UseMethod("is.bizday") +#' +#' @export +is.bizday <- function(dates, cal=bizdays.options$get('default.calendar')) UseMethod("is.bizday") -#' @rdname is.bizday #' @export is.bizday.default <- function(dates, cal=bizdays.options$get('default.calendar')) { dates <- as.Date(dates) is.bizday(dates, cal) } -#' @rdname is.bizday #' @export is.bizday.Date <- function(dates, cal=bizdays.options$get('default.calendar')) { if ( ! any(dates >= cal$start.date & dates <= cal$end.date) ) @@ -289,29 +343,39 @@ is.bizday.Date <- function(dates, cal=bizdays.options$get('default.calendar')) { cal$is.bizday(as.integer(dates)) } -#' Create a sequence of business days. +#' Create a sequence of business days #' -#' This function returns a sequence of business days according to the given -#' calendar. +#' Returns a sequence of dates with business days only. #' #' @param from the initial date -#' @param to the final date. This date must be greater that the initial date +#' @param to the final date (must be greater than \code{from}) #' @param cal an instance of \code{Calendar} -#' @export +#' +#' @return +#' A vector of \code{Date} objects that are business days according to the +#' provided \code{Calendar}. +#' +#' @section Date types accepted: +#' +#' The arguments \code{from} and \code{to} accept \code{Date} objects and any +#' object that returns a valid \code{Date} object when passed through +#' \code{as.Date}, which include all \code{POSIX*} classes and \code{character} +#' objects with ISO formatted dates. +#' #' @examples #' data(holidaysANBIMA) #' cal <- Calendar(holidaysANBIMA, weekdays=c("saturday", "sunday")) #' bizseq("2013-01-02", "2013-01-31", cal) -bizseq <- function(from, to, cal) UseMethod('bizseq') +#' +#' @export +bizseq <- function(from, to, cal=bizdays.options$get('default.calendar')) UseMethod('bizseq') -#' @rdname bizseq #' @export bizseq.default <- function(from, to, cal=bizdays.options$get('default.calendar')) { from <- as.Date(from) bizseq(from, to, cal) } -#' @rdname bizseq #' @export bizseq.Date <- function(from, to, cal=bizdays.options$get('default.calendar')) { to <- as.Date(to) @@ -342,13 +406,36 @@ bizseq.Date <- function(from, to, cal=bizdays.options$get('default.calendar')) { #' differs from \code{dates}' length, the recycle rule is applied to fulfill the #' gap. #' +#' @return +#' \code{Date} objects offset by the amount of days defined. +#' +#' @section Date types accepted: +#' +#' The argument \code{dates} accepts \code{Date} objects and any +#' object that returns a valid \code{Date} object when passed through +#' \code{as.Date}, which include all \code{POSIX*} classes and \code{character} +#' objects with ISO formatted dates. +#' +#' @section Recycle rule: +#' +#' These arguments handle the recycle rule so a vector of dates and a vector of +#' numbers can be provided and once those vectors differs in length the recycle +#' rule is applied. +#' #' @name offset +#' #' @examples #' data(holidaysANBIMA) #' cal <- Calendar(holidaysANBIMA, weekdays=c("saturday", "sunday")) +#' #' offset("2013-01-02", 5, cal) +#' +#' # Once you have a default calendar set, cal does not need to be provided +#' bizdays.options$set(default.calendar=cal) +#' #' dates <- seq(as.Date("2013-01-01"), as.Date("2013-01-05"), by="day") -#' offset(dates, 1, cal) +#' offset(dates, 1) +#' #' @export offset <- function(dates, n, cal=bizdays.options$get('default.calendar')) UseMethod('add.bizdays') @@ -384,12 +471,12 @@ offset.Date <- add.bizdays.Date #' ANBIMA's holidays list #' -#' A dataset containing a list of holidays delivered by ANBIMA +#' A dataset containing the list of holidays delivered by ANBIMA #' (www.anbima.com.br). #' #' @docType data #' @keywords datasets -#' @format a vector with Date objects +#' @format a vector with \code{Date} objects that represent holidays #' @name holidaysANBIMA NULL @@ -431,47 +518,148 @@ new_defaults <- function(value=list()) { #' bizdays' options #' -#' \code{bizdays.options} defines the default calendar to be used when -#' calling to the functions: \code{bizdays}, \code{adjust.next}, -#' \code{adjust.previous}, \code{is.bizday}, \code{bizseq}, \code{offset}; -#' without providing a \code{Calendar} instance as a parameter. +#' \code{bizdays.options} defines option parameters used internally in \code{bizdays}. #' -#' @format a \code{list} with \code{get} and \code{set} functions attached -#' \preformatted{ -#' bizdays.options$set(key=value) -#' bizdays.options$get("key") +#' @usage +#' bizdays.options$set(option.key=value) +#' bizdays.options$get("option.key") +#' +#' @format A \code{list} object with \emph{methods} \code{get} and \code{set} attached to. +#' +#' @details +#' \code{bizdays} supports the following parameter: +#' +#' \itemize{ +#' \item{\code{default.calendar}: }{the default calendar to be used with the +#' functions: \code{bizdays}, \code{bizdayse}, \code{adjust.next}, +#' \code{adjust.previous}, \code{is.bizday}, \code{bizseq}, \code{offset}, +#' \code{bizyears}, \code{bizyearse}} #' } -#' @usage -#' bizdays.options -#' @export +#' #' @examples -#' cal <- Calendar(name="Weekdays") +#' cal <- Calendar(name="Actual/365", dib=365) #' bizdays.options$set(default.calendar=cal) -#' bizdays.options$get("default.calendar") #' bizdays("2013-07-12", "2013-07-22") +#' +#' @export bizdays.options <- new_defaults() -bizdays.options$set(default.calendar=Calendar(name="Actual", dib=365)) +bizdays.options$set(default.calendar=Calendar(name="Actual/365", dib=365)) -#' Computes the period between two dates in years taking into account business days +#' Business days and current days equivalence +#' +#' \code{bizdayse} stands for business days equivalent, it returns the amount +#' of business days equivalent to a given number of current days. #' -#' @param from the initial date (or a vector of dates) -#' @param to the final date (or a vector of dates). +#' @param dates the reference dates +#' @param curd the amount of current days #' @param cal an instance of \code{Calendar} +#' +#' @return +#' An \code{integer} representing an amount of business days. +#' +#' @details +#' Let us suppose I have a reference date \code{dates} and I offset that date +#' by \code{curd} current days. \code{bizdayse} returns the business days +#' between the reference date and the new date offset by \code{curd} current +#' days. +#' +#' This is equivalent to +#' \preformatted{ +#' refdate <- Sys.Date() +#' curd <- 10 +#' newdate <- refdate + 10 # offset refdate by 10 days +#' bizdays(refdate, newdate) # bizdayse(refdate, 10) +#' } +#' +#' @section Date types accepted: +#' +#' The argument \code{dates} accepts \code{Date} objects and any +#' object that returns a valid \code{Date} object when passed through +#' \code{as.Date}, which include all \code{POSIX*} classes and \code{character} +#' objects with ISO formatted dates. +#' +#' @section Recycle rule: +#' +#' These arguments handle the recycle rule so a vector of dates and a vector of +#' numbers can be provided and once those vectors differs in length the recycle +#' rule is applied. +#' +#' @examples +#' data(holidaysANBIMA) +#' cal <- Calendar(holidaysANBIMA, weekdays=c("saturday", "sunday"), dib=252) +#' bizdayse("2013-01-02", 3, cal) +#' +#' @export +bizdayse <- function(dates, curd, cal=bizdays.options$get('default.calendar')) UseMethod('bizdayse') + +#' @export +bizdayse.default <- function(dates, curd, cal=bizdays.options$get('default.calendar')) { + dates <- as.Date(dates) + bizdayse(dates, curd, cal) +} + #' @export +bizdayse.Date <- function(dates, curd, cal=bizdays.options$get('default.calendar')) { + bizdays(dates, dates+curd, cal) +} + +#' Computes business days between two dates in years +#' +#' Returns the business days between 2 dates in years taking into account the +#' provided \code{Calendar} (or \code{bizdays.options$get("default.calendar")}). +#' +#' @details +#' The business days are converted to years by a division by \code{Calendar}'s +#' \code{dib} attribute. This is equivalent to +#' +#' \preformatted{ +#' cal <- Calendar(holidays, weekdays=c("saturday", "sunday"), dib=252) +#' bizdays("2013-01-02", "2013-01-31", cal)/cal$dib +#' } +#' +#' @param from the initial dates +#' @param to the final dates +#' @param cal an instance of \code{Calendar} +#' +#' @section Date types accepted: +#' +#' The arguments \code{from} and \code{to} accept \code{Date} objects and any +#' object that returns a valid \code{Date} object when passed through +#' \code{as.Date}, which include all \code{POSIX*} classes and \code{character} +#' objects with ISO formatted dates. +#' +#' @section Recycle rule: +#' +#' These arguments handle the recycle rule so vectors of dates can be provided +#' and once those vectors differs in length the recycle rule is applied. +#' +#' @section Date adjustment: +#' +#' \code{from} and \code{to} are adjusted when nonworking dates are +#' provided. Since \code{bizdays} function returns the amount of business days +#' between 2 dates, it must start and end in business days. +#' The default behavior, that is defined in \code{Calendar}'s instantiation with +#' \code{adjust.from} and \code{adjust.to}, reproduces the Excel's NETWORKDAYS. +#' A common and useful setting is \code{adjust.to=adjust.next} which moves +#' expiring maturities to the next business day, once it is not. +#' +#' @return +#' \code{numeric} objects representing the amount of business days in years. +#' #' @examples #' data(holidaysANBIMA) #' cal <- Calendar(holidaysANBIMA, weekdays=c("saturday", "sunday"), dib=252) #' bizyears("2013-01-02", "2013-01-31", cal) -bizyears <- function(from, to, cal) UseMethod('bizyears') +#' +#' @export +bizyears <- function(from, to, cal=bizdays.options$get('default.calendar')) UseMethod('bizyears') -#' @rdname bizyears #' @export bizyears.default <- function(from, to, cal=bizdays.options$get('default.calendar')) { from <- as.Date(from) bizyears(from, to, cal) } -#' @rdname bizyears #' @export bizyears.Date <- function(from, to, cal=bizdays.options$get('default.calendar')) { if (is.null(cal$dib)) @@ -480,48 +668,45 @@ bizyears.Date <- function(from, to, cal=bizdays.options$get('default.calendar')) bizdays(from, to, cal)/cal$dib } -#' Business days and current days equivalence +#' Business days and current days equivalence in years #' -#' \code{bizdayse} stands for business days equivalent, it returns the amount -#' of business days equivalent to a given number of current days. +#' \code{bizyearse} is a counterparty of \code{bizdayse} which returns the +#' amount of business days in years. #' -#' @param dates the initial date (or a vector of dates) -#' @param curd the amount of current days (or a vector of numeric) +#' @param dates the initial dates +#' @param curd the amount of current days #' @param cal an instance of \code{Calendar} -#' @export +#' +#' @return +#' \code{numeric} objects representing the amount of business days in years. +#' +#' @section Date types accepted: +#' +#' The argument \code{dates} accepts \code{Date} objects and any +#' object that returns a valid \code{Date} object when passed through +#' \code{as.Date}, which include all \code{POSIX*} classes and \code{character} +#' objects with ISO formatted dates. +#' +#' @section Recycle rule: +#' +#' These arguments handle the recycle rule so a vector of dates and a vector of +#' numbers can be provided and once those vectors differs in length the recycle +#' rule is applied. +#' #' @examples #' data(holidaysANBIMA) #' cal <- Calendar(holidaysANBIMA, weekdays=c("saturday", "sunday"), dib=252) -#' bizdayse("2013-01-02", 3, cal) -bizdayse <- function(dates, curd, cal) UseMethod('bizdayse') - -#' @rdname bizdayse -#' @export -bizdayse.default <- function(dates, curd, cal=bizdays.options$get('default.calendar')) { - dates <- as.Date(dates) - bizdayse(dates, curd, cal) -} - -#' @rdname bizdayse -#' @export -bizdayse.Date <- function(dates, curd, cal=bizdays.options$get('default.calendar')) { - bizdays(dates, dates+curd, cal) -} - -#' @rdname bizdayse -#' @export -#' @examples #' bizyearse("2013-01-02", 3, cal) -bizyearse <- function(dates, curd, cal) UseMethod('bizyearse') +#' +#' @export +bizyearse <- function(dates, curd, cal=bizdays.options$get('default.calendar')) UseMethod('bizyearse') -#' @rdname bizdayse #' @export bizyearse.default <- function(dates, curd, cal=bizdays.options$get('default.calendar')) { dates <- as.Date(dates) bizyearse(dates, curd, cal) } -#' @rdname bizdayse #' @export bizyearse.Date <- function(dates, curd, cal=bizdays.options$get('default.calendar')) { bizyears(dates, dates+curd, cal) diff --git a/man/adjust.date.Rd b/man/adjust.date.Rd index f9e80c2..88d4eff 100644 --- a/man/adjust.date.Rd +++ b/man/adjust.date.Rd @@ -14,10 +14,21 @@ adjust.previous(dates, cal = bizdays.options$get("default.calendar")) \item{cal}{an instance of \code{Calendar}} } +\value{ +\code{Date} objects adjusted accordingly. +} \description{ If the given dates are business days it returns the given dates, but once it is not, it returns the next/previous business days. } +\section{Date types accepted}{ + + +The argument \code{dates} accepts \code{Date} objects and any +object that returns a valid \code{Date} object when passed through +\code{as.Date}, which include all \code{POSIX*} classes and \code{character} +objects with ISO formatted dates. +} \examples{ data(holidaysANBIMA) cal <- Calendar(holidaysANBIMA, weekdays=c("saturday", "sunday")) diff --git a/man/bizdays-package.Rd b/man/bizdays-package.Rd index 320d7a4..0320c96 100644 --- a/man/bizdays-package.Rd +++ b/man/bizdays-package.Rd @@ -25,7 +25,7 @@ character strings and all methods have support for vectorized operations and handle the recycle rule. } \author{ -Wilson Freitas +Wilson Freitas <\url{http://aboutwilson.net}> } \seealso{ CRAN Task View: Empirical Finance diff --git a/man/bizdays.Rd b/man/bizdays.Rd index 697de60..10cda39 100644 --- a/man/bizdays.Rd +++ b/man/bizdays.Rd @@ -1,35 +1,62 @@ % Generated by roxygen2 (4.0.2): do not edit by hand \name{bizdays} \alias{bizdays} -\alias{bizdays.Date} -\alias{bizdays.default} \title{Computes business days between two dates.} \usage{ -bizdays(from, to, cal) - -\method{bizdays}{default}(from, to, - cal = bizdays.options$get("default.calendar")) - -\method{bizdays}{Date}(from, to, - cal = bizdays.options$get("default.calendar")) +bizdays(from, to, cal = bizdays.options$get("default.calendar")) } \arguments{ -\item{from}{the initial date (or a vector of dates)} +\item{from}{the initial dates} -\item{to}{the final date (or a vector of dates).} +\item{to}{the final dates} \item{cal}{an instance of \code{Calendar}} } +\value{ +\code{integer} objects representing the amount of business days. +} \description{ -This function computes the amount of business days between 2 taking into -account the holidays passed to the Calendar function. +Returns the amount of business days between 2 dates taking into account the +provided \code{Calendar} (or \code{bizdays.options$get("default.calendar")}). +} +\section{Date types accepted}{ + + +The arguments \code{from} and \code{to} accept \code{Date} objects and any +object that returns a valid \code{Date} object when passed through +\code{as.Date}, which include all \code{POSIX*} classes and \code{character} +objects with ISO formatted dates. +} + +\section{Recycle rule}{ + + +These arguments handle the recycle rule so vectors of dates can be provided +and once those vectors differs in length the recycle rule is applied. +} + +\section{Date adjustment}{ + + +\code{from} and \code{to} are adjusted when nonworking dates are +provided. Since \code{bizdays} function returns the amount of business days +between 2 dates, it must start and end in business days. +The default behavior, that is defined in \code{Calendar}'s instantiation with +\code{adjust.from} and \code{adjust.to}, reproduces the Excel's NETWORKDAYS. +A common and useful setting is \code{adjust.to=adjust.next} which moves +expiring maturities to the next business day, once it is not. } \examples{ data(holidaysANBIMA) cal <- Calendar(holidaysANBIMA, weekdays=c("saturday", "sunday")) + bizdays("2013-01-02", "2013-01-31", cal) -# Once you have a default calendar set + +# Once you have a default calendar set, cal does not need to be provided bizdays.options$set(default.calendar=cal) bizdays("2013-01-02", "2013-01-31") + +dates <- bizseq("2013-01-01", "2013-01-10") +bizdays(dates, "2014-01-31") } diff --git a/man/bizdays.options.Rd b/man/bizdays.options.Rd index 746666e..4c481d55 100644 --- a/man/bizdays.options.Rd +++ b/man/bizdays.options.Rd @@ -3,24 +3,27 @@ \name{bizdays.options} \alias{bizdays.options} \title{bizdays' options} -\format{a \code{list} with \code{get} and \code{set} functions attached -\preformatted{ -bizdays.options$set(key=value) -bizdays.options$get("key") -}} +\format{A \code{list} object with \emph{methods} \code{get} and \code{set} attached to.} \usage{ -bizdays.options +bizdays.options$set(option.key=value) +bizdays.options$get("option.key") } \description{ -\code{bizdays.options} defines the default calendar to be used when -calling to the functions: \code{bizdays}, \code{adjust.next}, -\code{adjust.previous}, \code{is.bizday}, \code{bizseq}, \code{offset}; -without providing a \code{Calendar} instance as a parameter. +\code{bizdays.options} defines option parameters used internally in \code{bizdays}. +} +\details{ +\code{bizdays} supports the following parameter: + +\itemize{ +\item{\code{default.calendar}: }{the default calendar to be used with the +functions: \code{bizdays}, \code{bizdayse}, \code{adjust.next}, +\code{adjust.previous}, \code{is.bizday}, \code{bizseq}, \code{offset}, +\code{bizyears}, \code{bizyearse}} +} } \examples{ -cal <- Calendar(name="Weekdays") +cal <- Calendar(name="Actual/365", dib=365) bizdays.options$set(default.calendar=cal) -bizdays.options$get("default.calendar") bizdays("2013-07-12", "2013-07-22") } \keyword{datasets} diff --git a/man/bizdayse.Rd b/man/bizdayse.Rd index 55e84c7..2a7ed5e 100644 --- a/man/bizdayse.Rd +++ b/man/bizdayse.Rd @@ -1,44 +1,57 @@ % Generated by roxygen2 (4.0.2): do not edit by hand \name{bizdayse} \alias{bizdayse} -\alias{bizdayse.Date} -\alias{bizdayse.default} -\alias{bizyearse} -\alias{bizyearse.Date} -\alias{bizyearse.default} \title{Business days and current days equivalence} \usage{ -bizdayse(dates, curd, cal) - -\method{bizdayse}{default}(dates, curd, - cal = bizdays.options$get("default.calendar")) - -\method{bizdayse}{Date}(dates, curd, - cal = bizdays.options$get("default.calendar")) - -bizyearse(dates, curd, cal) - -\method{bizyearse}{default}(dates, curd, - cal = bizdays.options$get("default.calendar")) - -\method{bizyearse}{Date}(dates, curd, - cal = bizdays.options$get("default.calendar")) +bizdayse(dates, curd, cal = bizdays.options$get("default.calendar")) } \arguments{ -\item{dates}{the initial date (or a vector of dates)} +\item{dates}{the reference dates} -\item{curd}{the amount of current days (or a vector of numeric)} +\item{curd}{the amount of current days} \item{cal}{an instance of \code{Calendar}} } +\value{ +An \code{integer} representing an amount of business days. +} \description{ \code{bizdayse} stands for business days equivalent, it returns the amount of business days equivalent to a given number of current days. } +\details{ +Let us suppose I have a reference date \code{dates} and I offset that date +by \code{curd} current days. \code{bizdayse} returns the business days +between the reference date and the new date offset by \code{curd} current +days. + +This is equivalent to +\preformatted{ +refdate <- Sys.Date() +curd <- 10 +newdate <- refdate + 10 # offset refdate by 10 days +bizdays(refdate, newdate) # bizdayse(refdate, 10) +} +} +\section{Date types accepted}{ + + +The argument \code{dates} accepts \code{Date} objects and any +object that returns a valid \code{Date} object when passed through +\code{as.Date}, which include all \code{POSIX*} classes and \code{character} +objects with ISO formatted dates. +} + +\section{Recycle rule}{ + + +These arguments handle the recycle rule so a vector of dates and a vector of +numbers can be provided and once those vectors differs in length the recycle +rule is applied. +} \examples{ data(holidaysANBIMA) cal <- Calendar(holidaysANBIMA, weekdays=c("saturday", "sunday"), dib=252) bizdayse("2013-01-02", 3, cal) -bizyearse("2013-01-02", 3, cal) } diff --git a/man/bizseq.Rd b/man/bizseq.Rd index 8b0ccaf..ed60e5d 100644 --- a/man/bizseq.Rd +++ b/man/bizseq.Rd @@ -1,27 +1,31 @@ % Generated by roxygen2 (4.0.2): do not edit by hand \name{bizseq} \alias{bizseq} -\alias{bizseq.Date} -\alias{bizseq.default} -\title{Create a sequence of business days.} +\title{Create a sequence of business days} \usage{ -bizseq(from, to, cal) - -\method{bizseq}{default}(from, to, - cal = bizdays.options$get("default.calendar")) - -\method{bizseq}{Date}(from, to, cal = bizdays.options$get("default.calendar")) +bizseq(from, to, cal = bizdays.options$get("default.calendar")) } \arguments{ \item{from}{the initial date} -\item{to}{the final date. This date must be greater that the initial date} +\item{to}{the final date (must be greater than \code{from})} \item{cal}{an instance of \code{Calendar}} } +\value{ +A vector of \code{Date} objects that are business days according to the +provided \code{Calendar}. +} \description{ -This function returns a sequence of business days according to the given -calendar. +Returns a sequence of dates with business days only. +} +\section{Date types accepted}{ + + +The arguments \code{from} and \code{to} accept \code{Date} objects and any +object that returns a valid \code{Date} object when passed through +\code{as.Date}, which include all \code{POSIX*} classes and \code{character} +objects with ISO formatted dates. } \examples{ data(holidaysANBIMA) diff --git a/man/bizyears.Rd b/man/bizyears.Rd index 4db70f5..9211907 100644 --- a/man/bizyears.Rd +++ b/man/bizyears.Rd @@ -1,27 +1,59 @@ % Generated by roxygen2 (4.0.2): do not edit by hand \name{bizyears} \alias{bizyears} -\alias{bizyears.Date} -\alias{bizyears.default} -\title{Computes the period between two dates in years taking into account business days} +\title{Computes business days between two dates in years} \usage{ -bizyears(from, to, cal) - -\method{bizyears}{default}(from, to, - cal = bizdays.options$get("default.calendar")) - -\method{bizyears}{Date}(from, to, - cal = bizdays.options$get("default.calendar")) +bizyears(from, to, cal = bizdays.options$get("default.calendar")) } \arguments{ -\item{from}{the initial date (or a vector of dates)} +\item{from}{the initial dates} -\item{to}{the final date (or a vector of dates).} +\item{to}{the final dates} \item{cal}{an instance of \code{Calendar}} } +\value{ +\code{numeric} objects representing the amount of business days in years. +} \description{ -Computes the period between two dates in years taking into account business days +Returns the business days between 2 dates in years taking into account the +provided \code{Calendar} (or \code{bizdays.options$get("default.calendar")}). +} +\details{ +The business days are converted to years by a division by \code{Calendar}'s +\code{dib} attribute. This is equivalent to + +\preformatted{ +cal <- Calendar(holidays, weekdays=c("saturday", "sunday"), dib=252) +bizdays("2013-01-02", "2013-01-31", cal)/cal$dib +} +} +\section{Date types accepted}{ + + +The arguments \code{from} and \code{to} accept \code{Date} objects and any +object that returns a valid \code{Date} object when passed through +\code{as.Date}, which include all \code{POSIX*} classes and \code{character} +objects with ISO formatted dates. +} + +\section{Recycle rule}{ + + +These arguments handle the recycle rule so vectors of dates can be provided +and once those vectors differs in length the recycle rule is applied. +} + +\section{Date adjustment}{ + + +\code{from} and \code{to} are adjusted when nonworking dates are +provided. Since \code{bizdays} function returns the amount of business days +between 2 dates, it must start and end in business days. +The default behavior, that is defined in \code{Calendar}'s instantiation with +\code{adjust.from} and \code{adjust.to}, reproduces the Excel's NETWORKDAYS. +A common and useful setting is \code{adjust.to=adjust.next} which moves +expiring maturities to the next business day, once it is not. } \examples{ data(holidaysANBIMA) diff --git a/man/bizyearse.Rd b/man/bizyearse.Rd new file mode 100644 index 0000000..ec28593 --- /dev/null +++ b/man/bizyearse.Rd @@ -0,0 +1,43 @@ +% Generated by roxygen2 (4.0.2): do not edit by hand +\name{bizyearse} +\alias{bizyearse} +\title{Business days and current days equivalence in years} +\usage{ +bizyearse(dates, curd, cal = bizdays.options$get("default.calendar")) +} +\arguments{ +\item{dates}{the initial dates} + +\item{curd}{the amount of current days} + +\item{cal}{an instance of \code{Calendar}} +} +\value{ +\code{numeric} objects representing the amount of business days in years. +} +\description{ +\code{bizyearse} is a counterparty of \code{bizdayse} which returns the +amount of business days in years. +} +\section{Date types accepted}{ + + +The argument \code{dates} accepts \code{Date} objects and any +object that returns a valid \code{Date} object when passed through +\code{as.Date}, which include all \code{POSIX*} classes and \code{character} +objects with ISO formatted dates. +} + +\section{Recycle rule}{ + + +These arguments handle the recycle rule so a vector of dates and a vector of +numbers can be provided and once those vectors differs in length the recycle +rule is applied. +} +\examples{ +data(holidaysANBIMA) +cal <- Calendar(holidaysANBIMA, weekdays=c("saturday", "sunday"), dib=252) +bizyearse("2013-01-02", 3, cal) +} + diff --git a/man/holidaysANBIMA.Rd b/man/holidaysANBIMA.Rd index 6a8b4a4..6232829 100644 --- a/man/holidaysANBIMA.Rd +++ b/man/holidaysANBIMA.Rd @@ -3,9 +3,9 @@ \name{holidaysANBIMA} \alias{holidaysANBIMA} \title{ANBIMA's holidays list} -\format{a vector with Date objects} +\format{a vector with \code{Date} objects that represent holidays} \description{ -A dataset containing a list of holidays delivered by ANBIMA +A dataset containing the list of holidays delivered by ANBIMA (www.anbima.com.br). } \keyword{datasets} diff --git a/man/is.bizday.Rd b/man/is.bizday.Rd index 9ed4741..dd44dd2 100644 --- a/man/is.bizday.Rd +++ b/man/is.bizday.Rd @@ -1,31 +1,39 @@ % Generated by roxygen2 (4.0.2): do not edit by hand \name{is.bizday} \alias{is.bizday} -\alias{is.bizday.Date} -\alias{is.bizday.default} -\title{Checks if the given date is a business day.} +\title{Checks if the given dates are business days.} \usage{ -is.bizday(dates, cal) - -\method{is.bizday}{default}(dates, - cal = bizdays.options$get("default.calendar")) - -\method{is.bizday}{Date}(dates, cal = bizdays.options$get("default.calendar")) +is.bizday(dates, cal = bizdays.options$get("default.calendar")) } \arguments{ -\item{dates}{a date or a vector of dates to be checked} +\item{dates}{dates to be checked} \item{cal}{an instance of \code{Calendar}} } +\value{ +\code{logical} objects informing that given dates are or are not business days. +} \description{ -This function returns TRUE if the given date is a business day and FALSE +Returns \code{TRUE} if the given date is a business day and \code{FALSE} otherwise. } +\section{Date types accepted}{ + + +The argument \code{dates} accepts \code{Date} objects and any +object that returns a valid \code{Date} object when passed through +\code{as.Date}, which include all \code{POSIX*} classes and \code{character} +objects with ISO formatted dates. +} \examples{ data(holidaysANBIMA) cal <- Calendar(holidaysANBIMA, weekdays=c("saturday", "sunday")) + is.bizday("2013-01-02", cal) -# Using the default Calendar + +# Once you have a default calendar set, cal does not need to be provided +bizdays.options$set(default.calendar=cal) + dates <- seq(as.Date("2013-01-01"), as.Date("2013-01-05"), by="day") is.bizday(dates) } diff --git a/man/offset.Rd b/man/offset.Rd index 941ced7..ed93ca0 100644 --- a/man/offset.Rd +++ b/man/offset.Rd @@ -15,6 +15,9 @@ add.bizdays(dates, n, cal = bizdays.options$get("default.calendar")) \item{cal}{an instance of \code{Calendar}} } +\value{ +\code{Date} objects offset by the amount of days defined. +} \description{ Returns the given \code{dates} offset by the given amount of \code{n} business days. @@ -24,11 +27,32 @@ The argument \code{n} accepts a sequence of integers and if its length differs from \code{dates}' length, the recycle rule is applied to fulfill the gap. } +\section{Date types accepted}{ + + +The argument \code{dates} accepts \code{Date} objects and any +object that returns a valid \code{Date} object when passed through +\code{as.Date}, which include all \code{POSIX*} classes and \code{character} +objects with ISO formatted dates. +} + +\section{Recycle rule}{ + + +These arguments handle the recycle rule so a vector of dates and a vector of +numbers can be provided and once those vectors differs in length the recycle +rule is applied. +} \examples{ data(holidaysANBIMA) cal <- Calendar(holidaysANBIMA, weekdays=c("saturday", "sunday")) + offset("2013-01-02", 5, cal) + +# Once you have a default calendar set, cal does not need to be provided +bizdays.options$set(default.calendar=cal) + dates <- seq(as.Date("2013-01-01"), as.Date("2013-01-05"), by="day") -offset(dates, 1, cal) +offset(dates, 1) }