[Rquantlib-commits] r247 - in pkg/RQuantLib: . R inst src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Jun 15 05:02:09 CEST 2010


Author: edd
Date: 2010-06-15 05:02:09 +0200 (Tue, 15 Jun 2010)
New Revision: 247

Modified:
   pkg/RQuantLib/DESCRIPTION
   pkg/RQuantLib/R/calendars.R
   pkg/RQuantLib/inst/ChangeLog
   pkg/RQuantLib/src/calendars.cpp
Log:
more simplication in calendars.cpp using the new Rcpp API
leading to simpler calendars.R code
increased depedency on Rcpp as we need new RcppDate(time)?Vector functionality


Modified: pkg/RQuantLib/DESCRIPTION
===================================================================
--- pkg/RQuantLib/DESCRIPTION	2010-06-13 21:11:42 UTC (rev 246)
+++ pkg/RQuantLib/DESCRIPTION	2010-06-15 03:02:09 UTC (rev 247)
@@ -24,7 +24,7 @@
  Note that while RQuantLib's code is licensed under the GPL (v2 or later),
  QuantLib itself is released under a somewhat less restrictive Open Source
  license (see QuantLib-License.txt).
-Depends: R (>= 2.7.0), Rcpp (>= 0.8.2.3)
+Depends: R (>= 2.7.0), Rcpp (>= 0.8.2.4)
 LinkingTo: Rcpp
 SystemRequirements: QuantLib library (>= 0.9.9) from http://quantlib.org, 
  Boost library (>= 1.34.0) from http://www.boost.org

Modified: pkg/RQuantLib/R/calendars.R
===================================================================
--- pkg/RQuantLib/R/calendars.R	2010-06-13 21:11:42 UTC (rev 246)
+++ pkg/RQuantLib/R/calendars.R	2010-06-15 03:02:09 UTC (rev 247)
@@ -24,10 +24,8 @@
 businessDay <- function(calendar="TARGET", dates=Sys.Date()) {
   stopifnot(is.character(calendar))
   stopifnot(class(dates)=="Date")
-  val <- .Call("QL_isBusinessDay",
-               calendar, dates,
-               PACKAGE="RQuantLib")
-  val <- as.logical(val[[1]])
+  val <- .Call("QL_isBusinessDay", calendar, dates, PACKAGE="RQuantLib")
+  val <- as.logical(val)
   names(val) <- dates
   val
 }
@@ -35,10 +33,8 @@
 isHoliday <- function(calendar="TARGET", dates=Sys.Date()) {
   stopifnot(is.character(calendar))
   stopifnot(class(dates)=="Date")
-  val <- .Call("QL_isHoliday",
-               calendar, dates,
-               PACKAGE="RQuantLib")
-  val <- as.logical(val[[1]])
+  val <- .Call("QL_isHoliday", calendar, dates, PACKAGE="RQuantLib")
+  val <- as.logical(val)
   names(val) <- dates
   val
 }
@@ -46,10 +42,8 @@
 isWeekend <- function(calendar="TARGET", dates=Sys.Date()) {
   stopifnot(is.character(calendar))
   stopifnot(class(dates)=="Date")
-  val <- .Call("QL_isWeekend",
-               calendar, dates,
-               PACKAGE="RQuantLib")
-  val <- as.logical(val[[1]])
+  val <- .Call("QL_isWeekend", calendar, dates, PACKAGE="RQuantLib")
+  val <- as.logical(val)
   names(val) <- dates
   val
 }
@@ -57,10 +51,8 @@
 isEndOfMonth <- function(calendar="TARGET", dates=Sys.Date()) {
   stopifnot(is.character(calendar))
   stopifnot(class(dates)=="Date")
-  val <- .Call("QL_isEndOfMonth",
-               calendar, dates,
-               PACKAGE="RQuantLib")
-  val <- as.logical(val[[1]])
+  val <- .Call("QL_isEndOfMonth", calendar, dates, PACKAGE="RQuantLib")
+  val <- as.logical(val)
   names(val) <- dates
   val
 }
@@ -68,10 +60,7 @@
 endOfMonth <- function(calendar="TARGET", dates=Sys.Date()) {
   stopifnot(is.character(calendar))
   stopifnot(class(dates)=="Date")
-  val <- .Call("QL_endOfMonth",
-               calendar, dates,
-               PACKAGE="RQuantLib")
-  val <- val[[1]]
+  val <- .Call("QL_endOfMonth", calendar, dates, PACKAGE="RQuantLib")
   names(val) <- dates
   val
 }
@@ -79,10 +68,7 @@
 adjust <- function(calendar="TARGET", dates=Sys.Date(), bdc = 0 ) {
   stopifnot(is.character(calendar))
   stopifnot(class(dates)=="Date")
-  val <- .Call("QL_adjust",
-               calendar, as.double(bdc), dates,
-               PACKAGE="RQuantLib")
-  val <- val[[1]]
+  val <- .Call("QL_adjust", calendar, as.double(bdc), dates, PACKAGE="RQuantLib")
   names(val) <- dates
   val
 }
@@ -115,7 +101,6 @@
                  dates,
                  PACKAGE="RQuantLib")
   stopifnot( !is.null(val) )
-  val <- val[[1]]
   val
 }
 
@@ -134,7 +119,7 @@
                     includeLast = as.double(includeLast)),
                from, to,
                PACKAGE="RQuantLib")
-  val <- val[[1]]
+  val <- val
   val
 }
 

Modified: pkg/RQuantLib/inst/ChangeLog
===================================================================
--- pkg/RQuantLib/inst/ChangeLog	2010-06-13 21:11:42 UTC (rev 246)
+++ pkg/RQuantLib/inst/ChangeLog	2010-06-15 03:02:09 UTC (rev 247)
@@ -1,3 +1,8 @@
+2010-06-14  Dirk Eddelbuettel  <edd at debian.org>
+
+	* src/calendars.cpp: Yet more simplification from "new" Rcpp API
+	* R/calendars.R: Simpler too as we get simpler result objects back
+
 2010-06-12  Dirk Eddelbuettel  <edd at debian.org>
 
 	* src/calendars.cpp: More code simplification using "new" Rcpp API

Modified: pkg/RQuantLib/src/calendars.cpp
===================================================================
--- pkg/RQuantLib/src/calendars.cpp	2010-06-13 21:11:42 UTC (rev 246)
+++ pkg/RQuantLib/src/calendars.cpp	2010-06-15 03:02:09 UTC (rev 247)
@@ -23,7 +23,7 @@
 // Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
 // MA 02111-1307, USA
 
-#include "rquantlib.hpp"
+#include <rquantlib.hpp>
 
 Calendar* getCalendar(const std::string &calstr) {
     Calendar* pcal = NULL;
@@ -100,14 +100,13 @@
         }
         delete pcal;
 
-        return Rcpp::List::create(Rcpp::Named("bizday") = bizdays);
+        return Rcpp::wrap(bizdays);
 
     } catch(std::exception &ex) { 
         forward_exception_to_r(ex); 
     } catch(...) { 
         ::Rf_error("c++ exception (unknown reason)"); 
     }
-
     return R_NilValue;
 }
 
@@ -126,7 +125,7 @@
         }
         delete pcal;
 
-        return Rcpp::List::create(Rcpp::Named("holidays") = hdays);
+        return Rcpp::wrap(hdays);
 
     } catch(std::exception &ex) { 
         forward_exception_to_r(ex); 
@@ -151,7 +150,7 @@
         }
         delete pcal;
 
-        return Rcpp::List::create(Rcpp::Named("weekend") = weekends);
+        return Rcpp::wrap(weekends);
 
     } catch(std::exception &ex) { 
         forward_exception_to_r(ex); 
@@ -177,7 +176,7 @@
         }
         delete pcal;
 
-        return Rcpp::List::create(Rcpp::Named("End.Of.Month") = eom);
+        return Rcpp::wrap(eom);
 
     } catch(std::exception &ex) { 
         forward_exception_to_r(ex); 
@@ -204,7 +203,7 @@
         }
         delete pcal;
        
-        return Rcpp::List::create(Rcpp::Named("ret") = dates);
+        return Rcpp::wrap(dates);
 
     } catch(std::exception &ex) { 
         forward_exception_to_r(ex); 
@@ -233,7 +232,7 @@
         }
         delete pcal;        
 
-        return Rcpp::List::create(Rcpp::Named("ret") = dates);
+        return Rcpp::wrap(dates);
 
     } catch(std::exception &ex) { 
         forward_exception_to_r(ex); 
@@ -267,7 +266,7 @@
         }
         delete pcal;        
         
-        return Rcpp::List::create(Rcpp::Named("ret") = dates);
+        return Rcpp::wrap(dates);
 
     } catch(std::exception &ex) { 
         forward_exception_to_r(ex); 
@@ -301,7 +300,7 @@
         }
         delete pcal;        
 
-        return Rcpp::List::create(Rcpp::Named("ret") = dates);
+        return Rcpp::wrap(dates);
 
     } catch(std::exception &ex) { 
         forward_exception_to_r(ex); 
@@ -331,12 +330,12 @@
             QuantLib::Date day1( dateFromR(dates1(i)) );
             QuantLib::Date day2( dateFromR(dates2(i)) );
             between[i] = pcal->businessDaysBetween(day1, day2,
-                                                   (ifirst == 1)?true:false,
-                                                   (ilast ==1)?true:false);
+                                                   (ifirst == 1) ? true: false,
+                                                   (ilast == 1) ? true: false);
         }
         delete pcal;        
         
-        return Rcpp::List::create(Rcpp::Named("ret") = between);
+        return Rcpp::wrap(between);
 
     } catch(std::exception &ex) { 
         forward_exception_to_r(ex); 
@@ -359,31 +358,16 @@
         std::vector<QuantLib::Date> 
             holidays = QuantLib::Calendar::holidayList(*pcal,
                                                        Date(dateFromR(d1)), 
-                                                       Date(dateFromR(d2)), (iw == 1)?true:false);                
+                                                       Date(dateFromR(d2)), 
+                                                       iw == 1 ? true : false);                
 
-        int numCol = 1;
-        std::vector<std::string> colNames(numCol);
-        colNames[0] = "Date";
-        RcppFrame frame(colNames);
-
+        RcppDateVector dv( holidays.size() );
         for (unsigned int i = 0; i< holidays.size(); i++){
-            std::vector<ColDatum> row(numCol);
-
-            row[0].setDateValue(RcppDate(holidays[i].month(), 
-                                         holidays[i].dayOfMonth(), 
-                                         holidays[i].year()));
- 
-            frame.addRow(row);
+            dv.set(i, RcppDate(holidays[i].month(), holidays[i].dayOfMonth(), holidays[i].year()));
         }
         delete pcal;
+        return Rcpp::wrap(dv);
 
-        RcppResultSet rs;
-        if (holidays.size() > 0)
-            rs.add("ret", frame);
-        else 
-            rs.add("ret", -1);
-        return rs.getReturnList();
-
     } catch(std::exception &ex) { 
         forward_exception_to_r(ex); 
     } catch(...) { 



More information about the Rquantlib-commits mailing list