Skip to content

Commit

Permalink
Merge pull request #116 from eddelbuettel/feature/add_remove_holidays
Browse files Browse the repository at this point in the history
add and remove dates (closes #115)
  • Loading branch information
eddelbuettel committed Aug 22, 2018
2 parents 348dbfb + b04be62 commit 366201e
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ src/*.so
src/*.dll
/FIXME
windows
GPATH
GRTAGS
GTAGS
*\.tar.gz
9 changes: 8 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
2018-08-22 Dirk Eddelbuettel <edd@debian.org>

* DESCRIPTION (Version, Date): Roll minor version

* src/calendars.cpp (addHolidays, removeHolidays): New functions
* man/Calendars.Rd: Added documentation

2018-08-16 Dirk Eddelbuettel <edd@debian.org>

* .travis.yml): Prettification for Travis file
* .travis.yml: Prettification for Travis file

2018-08-14 Dirk Eddelbuettel <edd@debian.org>

Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: RQuantLib
Title: R Interface to the 'QuantLib' Library
Version: 0.4.5
Date: 2018-08-10
Version: 0.4.5.1
Date: 2018-08-22
Maintainer: Dirk Eddelbuettel <edd@debian.org>
Author: Dirk Eddelbuettel, Khanh Nguyen (2009-2010), Terry Leitch (since 2016)
Description: The 'RQuantLib' package makes parts of 'QuantLib' accessible from R
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export(
"businessDaysBetween",
"getHolidayList", "holidayList",
"setCalendarContext",
"addHolidays",
"removeHolidays",
##--dayCounter.R
"dayCount",
"yearFraction",
Expand Down
8 changes: 8 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ getHolidayList <- function(calendar, from, to, includeWeekends = FALSE) {
.Call(`_RQuantLib_getHolidayList`, calendar, from, to, includeWeekends)
}

addHolidays <- function(calendar, dates) {
invisible(.Call(`_RQuantLib_addHolidays`, calendar, dates))
}

removeHolidays <- function(calendar, dates) {
invisible(.Call(`_RQuantLib_removeHolidays`, calendar, dates))
}

advanceDate <- function(issueDate, days) {
.Call(`_RQuantLib_advanceDate`, issueDate, days)
}
Expand Down
10 changes: 10 additions & 0 deletions man/Calendars.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
\alias{yearFraction}
\alias{setEvaluationDate}
\alias{advanceDate}
\alias{addHolidays}
\alias{removeHolidays}
\title{Calendar functions from QuantLib}
\description{
The \code{isBusinessDay} function evaluates the given dates in the context
Expand Down Expand Up @@ -72,6 +74,12 @@ the QuantLib pricing engines.
The \code{advanceDate} function advances the given date by the given
number of days in the current calendar instance.

The \code{addHolidays} and \code{removeHolidays} add (and remove)
holidays to (from) the given calendar. Note that this change is
transitory and does not persist the session as all actual calendar
information comes from the QuantLib library that this package is linked
against.

}
\usage{
isBusinessDay(calendar, dates)
Expand All @@ -92,6 +100,8 @@ dayCount(startDates, endDates, dayCounters)
yearFraction(startDates, endDates, dayCounters)
setCalendarContext(calendar, fixingDays, settleDate)
setEvaluationDate(evalDate)
addHolidays(calendar, dates)
removeHolidays(calendar, dates)
}
\arguments{
\item{calendar}{A string identifying one of the supported QuantLib
Expand Down
24 changes: 24 additions & 0 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,28 @@ BEGIN_RCPP
return rcpp_result_gen;
END_RCPP
}
// addHolidays
void addHolidays(std::string calendar, std::vector<QuantLib::Date> dates);
RcppExport SEXP _RQuantLib_addHolidays(SEXP calendarSEXP, SEXP datesSEXP) {
BEGIN_RCPP
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< std::string >::type calendar(calendarSEXP);
Rcpp::traits::input_parameter< std::vector<QuantLib::Date> >::type dates(datesSEXP);
addHolidays(calendar, dates);
return R_NilValue;
END_RCPP
}
// removeHolidays
void removeHolidays(std::string calendar, std::vector<QuantLib::Date> dates);
RcppExport SEXP _RQuantLib_removeHolidays(SEXP calendarSEXP, SEXP datesSEXP) {
BEGIN_RCPP
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< std::string >::type calendar(calendarSEXP);
Rcpp::traits::input_parameter< std::vector<QuantLib::Date> >::type dates(datesSEXP);
removeHolidays(calendar, dates);
return R_NilValue;
END_RCPP
}
// advanceDate
QuantLib::Date advanceDate(QuantLib::Date issueDate, int days);
static SEXP _RQuantLib_advanceDate_try(SEXP issueDateSEXP, SEXP daysSEXP) {
Expand Down Expand Up @@ -1694,6 +1716,8 @@ static const R_CallMethodDef CallEntries[] = {
{"_RQuantLib_advance2", (DL_FUNC) &_RQuantLib_advance2, 5},
{"_RQuantLib_businessDaysBetween", (DL_FUNC) &_RQuantLib_businessDaysBetween, 5},
{"_RQuantLib_getHolidayList", (DL_FUNC) &_RQuantLib_getHolidayList, 4},
{"_RQuantLib_addHolidays", (DL_FUNC) &_RQuantLib_addHolidays, 2},
{"_RQuantLib_removeHolidays", (DL_FUNC) &_RQuantLib_removeHolidays, 2},
{"_RQuantLib_advanceDate", (DL_FUNC) &_RQuantLib_advanceDate, 2},
{"_RQuantLib_dayCount", (DL_FUNC) &_RQuantLib_dayCount, 3},
{"_RQuantLib_yearFraction", (DL_FUNC) &_RQuantLib_yearFraction, 3},
Expand Down
18 changes: 18 additions & 0 deletions src/calendars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,3 +304,21 @@ std::vector<QuantLib::Date> getHolidayList(std::string calendar,
std::vector<QuantLib::Date> holidays = QuantLib::Calendar::holidayList(*pcal, from, to, includeWeekends);
return holidays;
}

// [[Rcpp::export]]
void addHolidays(std::string calendar, std::vector<QuantLib::Date> dates) {
boost::shared_ptr<QuantLib::Calendar> pcal(getCalendar(calendar));
int n = dates.size();
for (int i=0; i<n; i++) {
pcal->addHoliday(dates[i]);
}
}

// [[Rcpp::export]]
void removeHolidays(std::string calendar, std::vector<QuantLib::Date> dates) {
boost::shared_ptr<QuantLib::Calendar> pcal(getCalendar(calendar));
int n = dates.size();
for (int i=0; i<n; i++) {
pcal->removeHoliday(dates[i]);
}
}

0 comments on commit 366201e

Please sign in to comment.