[Rquantlib-commits] r243 - in pkg/RQuantLib: inst src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Jun 12 17:58:27 CEST 2010


Author: edd
Date: 2010-06-12 17:58:27 +0200 (Sat, 12 Jun 2010)
New Revision: 243

Modified:
   pkg/RQuantLib/inst/ChangeLog
   pkg/RQuantLib/src/calendars.cpp
   pkg/RQuantLib/src/utils.cpp
Log:
merge Brazil and South Korea into getCalendar() 
move getCalendar from utils.cpp to calendars.cpp


Modified: pkg/RQuantLib/inst/ChangeLog
===================================================================
--- pkg/RQuantLib/inst/ChangeLog	2010-06-12 02:55:09 UTC (rev 242)
+++ pkg/RQuantLib/inst/ChangeLog	2010-06-12 15:58:27 UTC (rev 243)
@@ -1,3 +1,8 @@
+2010-06-12  Dirk Eddelbuettel  <edd at debian.org>
+
+	* src/utils.cpp: Add Brazil + South Korea to getCalendar()
+	* src/calendars.cpp: Move getCalendar() into this file
+
 2010-06-11  Dirk Eddelbuettel  <edd at debian.org>
 
 	* src/calendars.cpp: Simplified code by using more of Rcpp's new API

Modified: pkg/RQuantLib/src/calendars.cpp
===================================================================
--- pkg/RQuantLib/src/calendars.cpp	2010-06-12 02:55:09 UTC (rev 242)
+++ pkg/RQuantLib/src/calendars.cpp	2010-06-12 15:58:27 UTC (rev 243)
@@ -25,69 +25,74 @@
 
 #include "rquantlib.hpp"
 
-RcppExport SEXP QL_isBusinessDay(SEXP calParameters, SEXP dateSexp){
+Calendar* getCalendar(SEXP calParameters){
+    RcppParams rparam(calParameters);
+    std::string    calstr = rparam.getStringValue("calendar");
+    Calendar* pcal = NULL;
 
-    try {
-        RcppParams rparam(calParameters);
+    if (calstr == "TARGET") { 		// generic calendar 
+        pcal = new TARGET();
+        
+    } else if (calstr == "Brazil") {
+        pcal = new Brazil();
 
-        std::string    calstr = rparam.getStringValue("calendar");
-        RcppDateVector dates  = RcppDateVector(dateSexp);
-
-        Calendar *pcal = NULL;
-
-        if (calstr == "TARGET") { 		// generic calendar 
-            pcal = new TARGET();
-
-        } else if (calstr == "Brazil") {
-            pcal = new Brazil();
-
-        } else if (calstr == "Canada" || calstr == "Canada/Settlement") {
-            pcal = new Canada(Canada::Settlement);
-        } else if (calstr == "Canada/TSX") {
-            pcal = new Canada(Canada::TSX);
-
-        } else if (calstr == "Germany" || calstr == "Germany/FrankfurtStockExchange") {
-            pcal = new Germany(Germany::FrankfurtStockExchange);
-        } else if (calstr == "Germany/Settlement") {
-            pcal = new Germany(Germany::Settlement);
-        } else if (calstr == "Germany/Xetra") {
-            pcal = new Germany(Germany::Xetra);
+    } else if (calstr == "Canada" || calstr == "Canada/Settlement") {
+        pcal = new Canada(Canada::Settlement);
+    } else if (calstr == "Canada/TSX") {
+        pcal = new Canada(Canada::TSX);
+        
+    } else if (calstr == "Germany" || calstr == "Germany/FrankfurtStockExchange") {
+        pcal = new Germany(Germany::FrankfurtStockExchange);
+    } else if (calstr == "Germany/Settlement") {
+        pcal = new Germany(Germany::Settlement);
+    } else if (calstr == "Germany/Xetra") {
+        pcal = new Germany(Germany::Xetra);
         } else if (calstr == "Germany/Eurex") {
-            pcal = new Germany(Germany::Eurex);
-
-        } else if (calstr == "Italy" || calstr == "Italy/Settlement") {
-            pcal = new Italy(Italy::Settlement);
+        pcal = new Germany(Germany::Eurex);
+        
+    } else if (calstr == "Italy" || calstr == "Italy/Settlement") {
+        pcal = new Italy(Italy::Settlement);
         } else if (calstr == "Italy/Exchange") {
-            pcal = new Italy(Italy::Exchange);
+        pcal = new Italy(Italy::Exchange);
+        
+    } else if (calstr == "Japan" || calstr == "Japan/Settlement") {
+        pcal = new Japan();
+        
+    } else if (calstr == "SouthKorea" || calstr == "SouthKorea/Settlement") {
+        pcal = new SouthKorea(SouthKorea::Settlement);
+    } else if (calstr == "SouthKorea/KRX") {
+        pcal = new SouthKorea(SouthKorea::KRX);
 
-        } else if (calstr == "Japan" || calstr == "Japan/Settlement") {
-            pcal = new Japan();
+    } else if (calstr == "UnitedKingdom" || calstr == "UnitedKingdom/Settlement") {
+        pcal = new UnitedKingdom(UnitedKingdom::Settlement);
+        } else if (calstr == "UnitedKingdom/Exchange") {
+        pcal = new UnitedKingdom(UnitedKingdom::Exchange);
+    } else if (calstr == "UnitedKingdom/Metals") {
+        pcal = new UnitedKingdom(UnitedKingdom::Metals);
+        
+    } else if (calstr == "UnitedStates" || calstr == "UnitedStates/Settlement") {
+        pcal = new UnitedStates(UnitedStates::Settlement);
+    } else if (calstr == "UnitedStates/NYSE") {
+        pcal = new UnitedStates(UnitedStates::NYSE);
+        } else if (calstr == "UnitedStates/GovernmentBond") {
+        pcal = new UnitedStates(UnitedStates::GovernmentBond);
+    } else if (calstr == "UnitedStates/NERC") {
+        pcal = new UnitedStates(UnitedStates::NERC);
 
-        } else if (calstr == "SouthKorea" || calstr == "SouthKorea/Settlement") {
-            pcal = new SouthKorea(SouthKorea::Settlement);
-        } else if (calstr == "SouthKorea/KRX") {
-            pcal = new SouthKorea(SouthKorea::KRX);
+    } else {
+        throw std::invalid_argument("Calendar " + calstr + " not recognised ");
+    }
 
-        } else if (calstr == "UnitedKingdom" || calstr == "UnitedKingdom/Settlement") {
-            pcal = new UnitedKingdom(UnitedKingdom::Settlement);
-        } else if (calstr == "UnitedKingdom/Exchange") {
-            pcal = new UnitedKingdom(UnitedKingdom::Exchange);
-        } else if (calstr == "UnitedKingdom/Metals") {
-            pcal = new UnitedKingdom(UnitedKingdom::Metals);
+    return pcal;
+}
 
-        } else if (calstr == "UnitedStates" || calstr == "UnitedStates/Settlement") {
-            pcal = new UnitedStates(UnitedStates::Settlement);
-        } else if (calstr == "UnitedStates/NYSE") {
-            pcal = new UnitedStates(UnitedStates::NYSE);
-        } else if (calstr == "UnitedStates/GovernmentBond") {
-            pcal = new UnitedStates(UnitedStates::GovernmentBond);
-        } else if (calstr == "UnitedStates/NERC") {
-            pcal = new UnitedStates(UnitedStates::NERC);
+RcppExport SEXP QL_isBusinessDay(SEXP calParameters, SEXP dateSexp){
 
-        } else {
-            throw std::invalid_argument("Calendar " + calstr + " not recognised ");
-        }
+    try {
+        Calendar *pcal = getCalendar(calParameters);
 
+        RcppDateVector dates  = RcppDateVector(dateSexp);
+
         int n = dates.size();
         std::vector<int> bizdays(n);
 

Modified: pkg/RQuantLib/src/utils.cpp
===================================================================
--- pkg/RQuantLib/src/utils.cpp	2010-06-12 02:55:09 UTC (rev 242)
+++ pkg/RQuantLib/src/utils.cpp	2010-06-12 15:58:27 UTC (rev 243)
@@ -2,8 +2,9 @@
 //
 // RQuantLib -- R interface to the QuantLib libraries
 //
-// Copyright (C) 2002 - 2009 Dirk Eddelbuettel <edd at debian.org>
+// Copyright (C) 2002 - 2009  Dirk Eddelbuettel 
 // Copyright (C) 2005 - 2006  Dominick Samperi
+// Copyright (C) 2010         Dirk Eddelbuettel and Khanh Nguyen
 //
 // $Id$
 //
@@ -317,6 +318,7 @@
 int dateFromR(const RcppDate &d) {
     return(d.getJDN() - RcppDate::Jan1970Offset + RcppDate::QLtoJan1970Offset);
 }
+
 DayCounter getDayCounter(const double n){
     if (n==0) return Actual360();
     else if (n==1) return Actual365Fixed();
@@ -326,6 +328,7 @@
     else if (n==5) return SimpleDayCounter();
     else  return Thirty360();
 }
+
 BusinessDayConvention getBusinessDayConvention(const double n){
     if (n==0) return Following;
     else if (n==1) return ModifiedFollowing;
@@ -333,12 +336,14 @@
     else if (n==3) return ModifiedPreceding;
     else  return Unadjusted;
 }
+
 Compounding getCompounding(const double n){
     if (n==0) return Simple;
     else if (n==1) return Compounded;
     else if (n==2) return Continuous;
     else return SimpleThenCompounded;
 }
+
 Frequency getFrequency(const double n){
 
     Frequency f;
@@ -358,8 +363,6 @@
     else f = OtherFrequency;   
 
     return f;
-
-
 }
 
 Period periodByTimeUnit(int length, std::string unit){
@@ -371,12 +374,14 @@
     return Period(length, tu);
 
 }
+
 TimeUnit getTimeUnit(const double n){
     if (n==0) return Days;
     else if (n==1) return Weeks;
     else if (n==2) return Months;
     else return Years;
 }
+
 DateGeneration::Rule getDateGenerationRule(const double n){
     if (n==0) return DateGeneration::Backward;
     else if (n==1) return DateGeneration::Forward;
@@ -384,61 +389,10 @@
     else if (n==3) return DateGeneration::ThirdWednesday;
     else if (n==4) return DateGeneration::Twentieth;
     else return DateGeneration::TwentiethIMM;
-
 }
-Calendar* getCalendar(SEXP calParameters){
-    RcppParams rparam(calParameters);
-    std::string    calstr = rparam.getStringValue("calendar");
-    Calendar* pcal = NULL;
-    if (calstr == "TARGET") { 		// generic calendar 
-        pcal = new TARGET();
-        
-    } else if (calstr == "Canada" || calstr == "Canada/Settlement") {
-        pcal = new Canada(Canada::Settlement);
-    } else if (calstr == "Canada/TSX") {
-        pcal = new Canada(Canada::TSX);
-        
-    } else if (calstr == "Germany" || calstr == "Germany/FrankfurtStockExchange") {
-        pcal = new Germany(Germany::FrankfurtStockExchange);
-    } else if (calstr == "Germany/Settlement") {
-        pcal = new Germany(Germany::Settlement);
-    } else if (calstr == "Germany/Xetra") {
-        pcal = new Germany(Germany::Xetra);
-        } else if (calstr == "Germany/Eurex") {
-        pcal = new Germany(Germany::Eurex);
-        
-    } else if (calstr == "Italy" || calstr == "Italy/Settlement") {
-        pcal = new Italy(Italy::Settlement);
-        } else if (calstr == "Italy/Exchange") {
-        pcal = new Italy(Italy::Exchange);
-        
-    } else if (calstr == "Japan") {
-        pcal = new Japan();
-        
-    } else if (calstr == "UnitedKingdom" || calstr == "UnitedKingdom/Settlement") {
-        pcal = new UnitedKingdom(UnitedKingdom::Settlement);
-        } else if (calstr == "UnitedKingdom/Exchange") {
-        pcal = new UnitedKingdom(UnitedKingdom::Exchange);
-    } else if (calstr == "UnitedKingdom/Metals") {
-        pcal = new UnitedKingdom(UnitedKingdom::Metals);
-        
-    } else if (calstr == "UnitedStates" || calstr == "UnitedStates/Settlement") {
-        pcal = new UnitedStates(UnitedStates::Settlement);
-    } else if (calstr == "UnitedStates/NYSE") {
-        pcal = new UnitedStates(UnitedStates::NYSE);
-        } else if (calstr == "UnitedStates/GovernmentBond") {
-        pcal = new UnitedStates(UnitedStates::GovernmentBond);
-    } else if (calstr == "UnitedStates/NERC") {
-        pcal = new UnitedStates(UnitedStates::NERC);
-    }
 
-    return pcal;
-}
-
-
 boost::shared_ptr<IborIndex> buildIborIndex(std::string type,
                                             const Handle<YieldTermStructure>& iborStrc){
-
     if (type == "Euribor10M") 
         return boost::shared_ptr<IborIndex>(new Euribor10M(iborStrc));
     if (type == "Euribor11M") 



More information about the Rquantlib-commits mailing list