[Rquantlib-commits] r328 - in pkg/RQuantLib: . R inst inst/include src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Sun May 26 15:24:26 CEST 2013
Author: edd
Date: 2013-05-26 15:24:25 +0200 (Sun, 26 May 2013)
New Revision: 328
Added:
pkg/RQuantLib/R/inline.R
pkg/RQuantLib/inst/include/
pkg/RQuantLib/inst/include/rquantlib.h
Removed:
pkg/RQuantLib/src/rquantlib.h
Modified:
pkg/RQuantLib/ChangeLog
pkg/RQuantLib/DESCRIPTION
pkg/RQuantLib/src/Makevars.in
pkg/RQuantLib/src/Makevars.win
Log:
Adding a plugin for use by Rcpp attribute or inline
Required move of header file to inst/include and corresponding Makevars changes
Header file may need to get trimmed to more properly define the API we need
Modified: pkg/RQuantLib/ChangeLog
===================================================================
--- pkg/RQuantLib/ChangeLog 2013-02-17 21:10:52 UTC (rev 327)
+++ pkg/RQuantLib/ChangeLog 2013-05-26 13:24:25 UTC (rev 328)
@@ -1,3 +1,14 @@
+2013-05-26 Dirk Eddelbuettel <edd at debian.org>
+
+ * R/inline.R: Adding a plugin for use by Rcpp attribute or inline
+
+ * inst/include/rquantlib.h: Moved from src/ to expose the RQuantLib
+ API for use by the plugin (and the header file / API needs to be
+ properly defined; this file is probably too large)
+
+ * src/Makevars.in: Adjust for header file move
+ * src/Makevars.win: Idem
+
2013-02-17 Dirk Eddelbuettel <edd at debian.org>
* DESCRIPTION: Release 0.3.10
@@ -9,7 +20,7 @@
* man/ZeroCouponBond.Rd: Idem
* R/arrays.R (plotOptionSurface): Use explicit `rgl::' prefix for all
- function from the rgl package to suppress spurious codetools warning
+ functions from the rgl package to suppress spurious codetools warning
* demo/OptionSurfaces.R: Reindented
Modified: pkg/RQuantLib/DESCRIPTION
===================================================================
--- pkg/RQuantLib/DESCRIPTION 2013-02-17 21:10:52 UTC (rev 327)
+++ pkg/RQuantLib/DESCRIPTION 2013-05-26 13:24:25 UTC (rev 328)
@@ -1,6 +1,6 @@
Package: RQuantLib
Title: R interface to the QuantLib library
-Version: 0.3.10
+Version: 0.3.10.1
Date: $Date$
Maintainer: Dirk Eddelbuettel <edd at debian.org>
Author: Dirk Eddelbuettel <edd at debian.org> and Khanh Nguyen <knguyen at cs.umb.edu>
Added: pkg/RQuantLib/R/inline.R
===================================================================
--- pkg/RQuantLib/R/inline.R (rev 0)
+++ pkg/RQuantLib/R/inline.R 2013-05-26 13:24:25 UTC (rev 328)
@@ -0,0 +1,61 @@
+## RQuantLib -- R interface to the QuantLib libraries
+##
+## Copyright (C) 2002 - 2013 Dirk Eddelbuettel <edd at debian.org>
+##
+## $Id$
+##
+## This file is part of the RQuantLib library for GNU R.
+## It is made available under the terms of the GNU General Public
+## License, version 2, or at your option, any later version,
+## incorporated herein by reference.
+##
+## This program is distributed in the hope that it will be
+## useful, but WITHOUT ANY WARRANTY; without even the implied
+## warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+## PURPOSE. See the GNU General Public License for more
+## details.
+##
+## You should have received a copy of the GNU General Public License
+## along with Rcpp. If not, see <http://www.gnu.org/licenses/>.
+
+.pkgglobalenv <- new.env(parent=emptyenv())
+
+.onLoad <- function(libname, pkgname) {
+ if (.Platform$OS.type=="windows") {
+ ## by convention with CRAN, on Windows we expect these two
+ ## variables to be set, and to be pointing to the respective
+ ## helper installations
+ qlroot <- Sys.getenv("QUANTLIB_ROOT")
+ boostlib <- Sys.getenv("BOOSTLIB")
+ rarch <- Sys.getenv("R_ARCH")
+ qlcflags <- sprintf("-I%s -I. -I\"%s\"", qlroot, boostlib)
+ qllibs <- sprintf("%s -L%s/lib%s -lQuantLib", Rcpp:::LdFlags(), rarch)
+ } else {
+ qlcflags <- system( "quantlib-config --cflags", intern = TRUE)
+ qllibs <- system( "quantlib-config --libs", intern = TRUE)
+ }
+
+ assign("ql_cflags", qlcflags, envir=.pkgglobalenv)
+ assign("ql_libs", qllibs, envir=.pkgglobalenv)
+}
+
+LdFlags <- function(print = TRUE) {
+ if (print) cat(.pkgglobalenv$ql_libs) else .pkgglobalenv$ql_libs
+}
+
+CFlags <- function(print = TRUE) {
+ if (print) cat(.pkgglobalenv$ql_cflags) else .pkgglobalenv$ql_cflags
+}
+
+inlineCxxPlugin <- function(...) {
+ plugin <-
+ Rcpp:::Rcpp.plugin.maker(include.before = "#include <rquantlib.h>",
+ libs = sprintf("%s $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)", LdFlags(FALSE)),
+ package = "RQuantLib", Makevars = NULL, Makevars.win = NULL)
+ settings <- plugin()
+ settings$env$PKG_CPPFLAGS <- CFlags(FALSE)
+ settings
+}
+
+
+
Copied: pkg/RQuantLib/inst/include/rquantlib.h (from rev 308, pkg/RQuantLib/src/rquantlib.h)
===================================================================
--- pkg/RQuantLib/inst/include/rquantlib.h (rev 0)
+++ pkg/RQuantLib/inst/include/rquantlib.h 2013-05-26 13:24:25 UTC (rev 328)
@@ -0,0 +1,172 @@
+// -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+//
+// RQuantLib function prototypes and macros
+//
+// Copyright 2002 - 2013 Dirk Eddelbuettel <edd at debian.org>
+// Copyright 2005 - 2006 Dominick Samperi
+//
+// $Id$
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with RcppArmadillo. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef rquantlib_h
+#define rquantlib_h
+
+#include <ql/quantlib.hpp>
+#include <boost/algorithm/string.hpp>
+#include <boost/lexical_cast.hpp>
+
+//using namespace QuantLib;
+
+#include <Rcpp.h>
+
+//#define NULL_RateHelper (boost::shared_ptr<RateHelper>)Null<boost::shared_ptr<RateHelper> >()
+
+// Prototypes for convenience functions (some macros)
+//void insertListElement(SEXP &list, SEXP &names,
+// const int pos, const double value,
+// const char *label);
+//SEXP getListElement(SEXP list, char *str);
+
+// Used to maintain context while in an R function.
+class RQLContext : public QuantLib::Singleton<RQLContext> {
+public:
+ RQLContext() {
+ fixingDays = 2;
+ calendar = QuantLib::TARGET();
+ settleDate = QuantLib::Date::todaysDate()+2;
+ }
+ // The tradeDate (evaluation date) is maintained by Settings,
+ // (which is a singleton structure provided by QuantLib)
+ // and used to translate between dates and real-valued times.
+ QuantLib::Date settleDate;
+ QuantLib::Calendar calendar;
+ QuantLib::Integer fixingDays;
+};
+
+// Instrument types used to construct the yield curve.
+enum RQLObservableType { RQLDeposit, RQLSwap, RQLFuture, RQLFRA };
+
+// Used to identify the specifics of a particular contract.
+class RQLObservable {
+public:
+ RQLObservable(RQLObservableType type,
+ int n1, int n2,
+ QuantLib::TimeUnit units)
+ : type_(type), n1_(n1), n2_(n2), units_(units) {}
+ RQLObservableType getType() { return type_; }
+ int getN1() { return n1_; }
+ int getN2() { return n2_; }
+ QuantLib::TimeUnit getUnits() { return units_; }
+private:
+ RQLObservableType type_;
+ int n1_, n2_; // n2 used for FRA's
+ QuantLib::TimeUnit units_; // not used for futures and FRA's
+};
+
+typedef std::map<std::string, RQLObservable*> RQLMap;
+typedef std::map<std::string, RQLObservable*>::const_iterator RQLMapIterator;
+
+// Database used to maintain curve construction instrument details.
+class ObservableDB : public QuantLib::Singleton<ObservableDB> {
+public:
+ ObservableDB();
+ boost::shared_ptr<QuantLib::RateHelper> getRateHelper(std::string& ticker, QuantLib::Rate r);
+private:
+ RQLMap db_;
+};
+
+boost::shared_ptr<QuantLib::YieldTermStructure>
+getTermStructure(std::string& interpWhat, std::string& interpHow,
+ const QuantLib::Date& settleDate,
+ const std::vector<boost::shared_ptr<QuantLib::RateHelper> >& curveInput,
+ QuantLib::DayCounter& dayCounter, QuantLib::Real tolerance);
+
+boost::shared_ptr<QuantLib::YieldTermStructure>
+makeFlatCurve(const QuantLib::Date& today,
+ const boost::shared_ptr<QuantLib::Quote>& forward,
+ const QuantLib::DayCounter& dc);
+
+boost::shared_ptr<QuantLib::YieldTermStructure>
+flatRate(const QuantLib::Date& today,
+ const boost::shared_ptr<QuantLib::Quote>& forward,
+ const QuantLib::DayCounter& dc);
+
+boost::shared_ptr<QuantLib::BlackVolTermStructure>
+makeFlatVolatility(const QuantLib::Date& today,
+ const boost::shared_ptr<QuantLib::Quote>& vol,
+ QuantLib::DayCounter dc);
+
+boost::shared_ptr<QuantLib::BlackVolTermStructure>
+flatVol(const QuantLib::Date& today,
+ const boost::shared_ptr<QuantLib::Quote>& vol,
+ const QuantLib::DayCounter& dc);
+
+enum EngineType {Analytic,
+ JR, CRR, EQP, TGEO, TIAN, LR, JOSHI,
+ FiniteDifferences, Integral,
+ PseudoMonteCarlo, QuasiMonteCarlo };
+
+boost::shared_ptr<QuantLib::VanillaOption>
+makeOption(const boost::shared_ptr<QuantLib::StrikedTypePayoff>& payoff,
+ const boost::shared_ptr<QuantLib::Exercise>& exercise,
+ const boost::shared_ptr<QuantLib::Quote>& u,
+ const boost::shared_ptr<QuantLib::YieldTermStructure>& q,
+ const boost::shared_ptr<QuantLib::YieldTermStructure>& r,
+ const boost::shared_ptr<QuantLib::BlackVolTermStructure>& vol,
+ EngineType engineType = Analytic,
+ QuantLib::Size binomialSteps=128,
+ QuantLib::Size samples=100);
+
+boost::shared_ptr<QuantLib::GeneralizedBlackScholesProcess>
+makeProcess(const boost::shared_ptr<QuantLib::Quote>& u,
+ const boost::shared_ptr<QuantLib::YieldTermStructure>& q,
+ const boost::shared_ptr<QuantLib::YieldTermStructure>& r,
+ const boost::shared_ptr<QuantLib::BlackVolTermStructure>& vol);
+
+// int dateFromR(const RcppDate &d); // using 'classic' API's RcppDate
+int dateFromR(const Rcpp::Date &d); // using 'new' API's Rcpp::Date
+
+//utility functions for parameters of fixed-income instrument function
+QuantLib::Frequency getFrequency(const double n);
+QuantLib::TimeUnit getTimeUnit(const double n);
+QuantLib::Compounding getCompounding(const double n);
+QuantLib::BusinessDayConvention getBusinessDayConvention(const double n);
+QuantLib::DayCounter getDayCounter(const double n);
+QuantLib::DateGeneration::Rule getDateGenerationRule(const double n);
+boost::shared_ptr<QuantLib::YieldTermStructure> buildTermStructure(SEXP params,
+ SEXP tsQuotes,
+ SEXP times);
+QuantLib::Schedule getSchedule(SEXP sch);
+boost::shared_ptr<QuantLib::IborIndex> getIborIndex(SEXP index, const QuantLib::Date today);
+std::vector<double> getDoubleVector(SEXP vector);
+boost::shared_ptr<QuantLib::YieldTermStructure> getFlatCurve(SEXP flatcurve);
+boost::shared_ptr<QuantLib::YieldTermStructure> rebuildCurveFromZeroRates(SEXP dateSexp, SEXP zeroSexp);
+boost::shared_ptr<QuantLib::IborIndex>
+ buildIborIndex(std::string type,
+ const QuantLib::Handle<QuantLib::YieldTermStructure>& iborStrc);
+QuantLib::Calendar* getCalendar(SEXP calParameters);
+QuantLib::Period periodByTimeUnit(int length, std::string unit);
+
+// simple option type creator based on string
+QuantLib::Option::Type getOptionType(const std::string &t);
+
+// create a data.frame with dates and amounts
+Rcpp::DataFrame getCashFlowDataFrame(const QuantLib::Leg &bondCashFlow);
+
+// fill QL data structures based on data.frames
+QuantLib::DividendSchedule getDividendSchedule(SEXP dividendScheduleFrame);
+QuantLib::CallabilitySchedule getCallabilitySchedule(SEXP callabilityScheduleFrame);
+
+#endif
Modified: pkg/RQuantLib/src/Makevars.in
===================================================================
--- pkg/RQuantLib/src/Makevars.in 2013-02-17 21:10:52 UTC (rev 327)
+++ pkg/RQuantLib/src/Makevars.in 2013-05-26 13:24:25 UTC (rev 328)
@@ -1,2 +1,2 @@
-PKG_CXXFLAGS=@CXXFLAGS@ -I.
+PKG_CXXFLAGS=@CXXFLAGS@ -I../inst/include -I.
PKG_LIBS=@LDFLAGS@
Modified: pkg/RQuantLib/src/Makevars.win
===================================================================
--- pkg/RQuantLib/src/Makevars.win 2013-02-17 21:10:52 UTC (rev 327)
+++ pkg/RQuantLib/src/Makevars.win 2013-05-26 13:24:25 UTC (rev 328)
@@ -2,7 +2,7 @@
#
# Copyright 2005 - 2006 Dominick Samperi
# Copyright 2005 Uwe Ligges
-# Copyright 2008 - 2011 Dirk Eddelbuettel
+# Copyright 2008 - 2013 Dirk Eddelbuettel
# Copyright 2011 Uwe Ligges, Brian Ripley, and Josh Ulrich
## This assumes that we can call Rscript to ask Rcpp about its locations
@@ -11,5 +11,5 @@
## The environment variable QUANTLIB_ROOT has to point to an existing build of QuantLib
## With R 2.12.0 and later, we also support 32 and 64 bit builds and need to differentiate
-PKG_CXXFLAGS=-I$(QUANTLIB_ROOT) -I. -I"$(BOOSTLIB)"
+PKG_CXXFLAGS=-I$(QUANTLIB_ROOT) -I../inst/include -I. -I"$(BOOSTLIB)"
PKG_LIBS=$(RCPP_LDFLAGS) -L$(QUANTLIB_ROOT)/lib${R_ARCH} -lQuantLib
Deleted: pkg/RQuantLib/src/rquantlib.h
===================================================================
--- pkg/RQuantLib/src/rquantlib.h 2013-02-17 21:10:52 UTC (rev 327)
+++ pkg/RQuantLib/src/rquantlib.h 2013-05-26 13:24:25 UTC (rev 328)
@@ -1,173 +0,0 @@
-// -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
-//
-// RQuantLib function prototypes and macros
-//
-// Copyright 2002 - 2009 Dirk Eddelbuettel <edd at debian.org>
-// Copyright 2005 - 2006 Dominick Samperi
-//
-// $Id$
-//
-// This program is free software; you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-#ifndef rquantlib_h
-#define rquantlib_h
-
-#include <ql/quantlib.hpp>
-#include <boost/algorithm/string.hpp>
-#include <boost/lexical_cast.hpp>
-
-//using namespace QuantLib;
-
-#include <Rcpp.h>
-
-//#define NULL_RateHelper (boost::shared_ptr<RateHelper>)Null<boost::shared_ptr<RateHelper> >()
-
-// Prototypes for convenience functions (some macros)
-//void insertListElement(SEXP &list, SEXP &names,
-// const int pos, const double value,
-// const char *label);
-//SEXP getListElement(SEXP list, char *str);
-
-// Used to maintain context while in an R function.
-class RQLContext : public QuantLib::Singleton<RQLContext> {
-public:
- RQLContext() {
- fixingDays = 2;
- calendar = QuantLib::TARGET();
- settleDate = QuantLib::Date::todaysDate()+2;
- }
- // The tradeDate (evaluation date) is maintained by Settings,
- // (which is a singleton structure provided by QuantLib)
- // and used to translate between dates and real-valued times.
- QuantLib::Date settleDate;
- QuantLib::Calendar calendar;
- QuantLib::Integer fixingDays;
-};
-
-// Instrument types used to construct the yield curve.
-enum RQLObservableType { RQLDeposit, RQLSwap, RQLFuture, RQLFRA };
-
-// Used to identify the specifics of a particular contract.
-class RQLObservable {
-public:
- RQLObservable(RQLObservableType type,
- int n1, int n2,
- QuantLib::TimeUnit units)
- : type_(type), n1_(n1), n2_(n2), units_(units) {}
- RQLObservableType getType() { return type_; }
- int getN1() { return n1_; }
- int getN2() { return n2_; }
- QuantLib::TimeUnit getUnits() { return units_; }
-private:
- RQLObservableType type_;
- int n1_, n2_; // n2 used for FRA's
- QuantLib::TimeUnit units_; // not used for futures and FRA's
-};
-
-typedef std::map<std::string, RQLObservable*> RQLMap;
-typedef std::map<std::string, RQLObservable*>::const_iterator RQLMapIterator;
-
-// Database used to maintain curve construction instrument details.
-class ObservableDB : public QuantLib::Singleton<ObservableDB> {
-public:
- ObservableDB();
- boost::shared_ptr<QuantLib::RateHelper> getRateHelper(std::string& ticker, QuantLib::Rate r);
-private:
- RQLMap db_;
-};
-
-boost::shared_ptr<QuantLib::YieldTermStructure>
-getTermStructure(std::string& interpWhat, std::string& interpHow,
- const QuantLib::Date& settleDate,
- const std::vector<boost::shared_ptr<QuantLib::RateHelper> >& curveInput,
- QuantLib::DayCounter& dayCounter, QuantLib::Real tolerance);
-
-boost::shared_ptr<QuantLib::YieldTermStructure>
-makeFlatCurve(const QuantLib::Date& today,
- const boost::shared_ptr<QuantLib::Quote>& forward,
- const QuantLib::DayCounter& dc);
-
-boost::shared_ptr<QuantLib::YieldTermStructure>
-flatRate(const QuantLib::Date& today,
- const boost::shared_ptr<QuantLib::Quote>& forward,
- const QuantLib::DayCounter& dc);
-
-boost::shared_ptr<QuantLib::BlackVolTermStructure>
-makeFlatVolatility(const QuantLib::Date& today,
- const boost::shared_ptr<QuantLib::Quote>& vol,
- QuantLib::DayCounter dc);
-
-boost::shared_ptr<QuantLib::BlackVolTermStructure>
-flatVol(const QuantLib::Date& today,
- const boost::shared_ptr<QuantLib::Quote>& vol,
- const QuantLib::DayCounter& dc);
-
-enum EngineType {Analytic,
- JR, CRR, EQP, TGEO, TIAN, LR, JOSHI,
- FiniteDifferences, Integral,
- PseudoMonteCarlo, QuasiMonteCarlo };
-
-boost::shared_ptr<QuantLib::VanillaOption>
-makeOption(const boost::shared_ptr<QuantLib::StrikedTypePayoff>& payoff,
- const boost::shared_ptr<QuantLib::Exercise>& exercise,
- const boost::shared_ptr<QuantLib::Quote>& u,
- const boost::shared_ptr<QuantLib::YieldTermStructure>& q,
- const boost::shared_ptr<QuantLib::YieldTermStructure>& r,
- const boost::shared_ptr<QuantLib::BlackVolTermStructure>& vol,
- EngineType engineType = Analytic,
- QuantLib::Size binomialSteps=128,
- QuantLib::Size samples=100);
-
-boost::shared_ptr<QuantLib::GeneralizedBlackScholesProcess>
-makeProcess(const boost::shared_ptr<QuantLib::Quote>& u,
- const boost::shared_ptr<QuantLib::YieldTermStructure>& q,
- const boost::shared_ptr<QuantLib::YieldTermStructure>& r,
- const boost::shared_ptr<QuantLib::BlackVolTermStructure>& vol);
-
-// int dateFromR(const RcppDate &d); // using 'classic' API's RcppDate
-int dateFromR(const Rcpp::Date &d); // using 'new' API's Rcpp::Date
-
-//utility functions for parameters of fixed-income instrument function
-QuantLib::Frequency getFrequency(const double n);
-QuantLib::TimeUnit getTimeUnit(const double n);
-QuantLib::Compounding getCompounding(const double n);
-QuantLib::BusinessDayConvention getBusinessDayConvention(const double n);
-QuantLib::DayCounter getDayCounter(const double n);
-QuantLib::DateGeneration::Rule getDateGenerationRule(const double n);
-boost::shared_ptr<QuantLib::YieldTermStructure> buildTermStructure(SEXP params,
- SEXP tsQuotes,
- SEXP times);
-QuantLib::Schedule getSchedule(SEXP sch);
-boost::shared_ptr<QuantLib::IborIndex> getIborIndex(SEXP index, const QuantLib::Date today);
-std::vector<double> getDoubleVector(SEXP vector);
-boost::shared_ptr<QuantLib::YieldTermStructure> getFlatCurve(SEXP flatcurve);
-boost::shared_ptr<QuantLib::YieldTermStructure> rebuildCurveFromZeroRates(SEXP dateSexp, SEXP zeroSexp);
-boost::shared_ptr<QuantLib::IborIndex>
- buildIborIndex(std::string type,
- const QuantLib::Handle<QuantLib::YieldTermStructure>& iborStrc);
-QuantLib::Calendar* getCalendar(SEXP calParameters);
-QuantLib::Period periodByTimeUnit(int length, std::string unit);
-
-// simple option type creator based on string
-QuantLib::Option::Type getOptionType(const std::string &t);
-
-// create a data.frame with dates and amounts
-Rcpp::DataFrame getCashFlowDataFrame(const QuantLib::Leg &bondCashFlow);
-
-// fill QL data structures based on data.frames
-QuantLib::DividendSchedule getDividendSchedule(SEXP dividendScheduleFrame);
-QuantLib::CallabilitySchedule getCallabilitySchedule(SEXP callabilityScheduleFrame);
-
-#endif
More information about the Rquantlib-commits
mailing list