[Rquantlib-commits] r318 - in pkg/RQuantLib: . src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Sep 9 17:03:40 CEST 2011


Author: edd
Date: 2011-09-09 17:03:39 +0200 (Fri, 09 Sep 2011)
New Revision: 318

Modified:
   pkg/RQuantLib/ChangeLog
   pkg/RQuantLib/src/bonds.cpp
   pkg/RQuantLib/src/discount.cpp
Log:
DiscountCurve used to set the global QL evaluation Date, which has side
effects, so we now cache on entry and reset


Modified: pkg/RQuantLib/ChangeLog
===================================================================
--- pkg/RQuantLib/ChangeLog	2011-05-03 02:05:48 UTC (rev 317)
+++ pkg/RQuantLib/ChangeLog	2011-09-09 15:03:39 UTC (rev 318)
@@ -1,3 +1,9 @@
+2011-09-09  Dirk Eddelbuettel  <edd at debian.org>
+
+	* src/discount.cpp (DiscountCurve): Cache the (global) value of
+	QuantLib::Settings::instance().evaluationDate() and reset it at end,
+	with thanks to Helmut Heiming for the bug report.
+
 2011-05-02  Dirk Eddelbuettel  <edd at debian.org>
 
 	* configure.in: If g++ version 4.6 or newer is detected, add the

Modified: pkg/RQuantLib/src/bonds.cpp
===================================================================
--- pkg/RQuantLib/src/bonds.cpp	2011-05-03 02:05:48 UTC (rev 317)
+++ pkg/RQuantLib/src/bonds.cpp	2011-09-09 15:03:39 UTC (rev 318)
@@ -982,6 +982,7 @@
 
         Rcpp::List misc(dateparams);      
         double settlementDays = Rcpp::as<double>(misc["settlementDays"]);
+
         std::string cal = Rcpp::as<std::string>(misc["calendar"]);
         double dayCounter = Rcpp::as<double>(misc["dayCounter"]);
         double frequency = Rcpp::as<double>(misc["period"]);
@@ -993,7 +994,7 @@
         } else if (cal == "uk"){
             calendar = QuantLib::UnitedKingdom(QuantLib::UnitedKingdom::Exchange);
         }
- 
+
         QuantLib::BusinessDayConvention bdc = getBusinessDayConvention(businessDayConvention);
         QuantLib::DayCounter dc = getDayCounter(dayCounter);
         QuantLib::Frequency freq = getFrequency(frequency);
@@ -1024,6 +1025,10 @@
                                QuantLib::Period(freq), calendar, bdc, bdc,
                                QuantLib::DateGeneration::Backward, false);        
 
+        //std::cout << "RQL SettleDate    : " << RQLContext::instance().settleDate << std::endl;
+        //std::cout << "RQL calendar      : " << RQLContext::instance().calendar << std::endl;
+        //std::cout << "RQL fixingDays    : " << RQLContext::instance().fixingDays << std::endl;
+
         QuantLib::CallableFixedRateBond bond(settlementDays, faceAmount, sch,
                                              Rcpp::as<std::vector <double> >(rates), 
                                              dc, bdc, redemption, issueDate, 

Modified: pkg/RQuantLib/src/discount.cpp
===================================================================
--- pkg/RQuantLib/src/discount.cpp	2011-05-03 02:05:48 UTC (rev 317)
+++ pkg/RQuantLib/src/discount.cpp	2011-09-09 15:03:39 UTC (rev 318)
@@ -35,6 +35,7 @@
         //std::cout << "TradeDate: " << todaysDate << std::endl << "Settle: " << settlementDate << std::endl;
 
         RQLContext::instance().settleDate = settlementDate;
+        QuantLib::Date evalDate = QuantLib::Settings::instance().evaluationDate();
         QuantLib::Settings::instance().evaluationDate() = todaysDate;
         std::string firstQuoteName = tsNames[0];
 
@@ -116,6 +117,8 @@
         //std::cout << "Settle " << settlementDate << std::endl;
         //n = std::min(300, n);
 
+        QuantLib::Settings::instance().evaluationDate() = evalDate;
+
         Rcpp::DateVector dates(n);
         Rcpp::NumericVector zeroRates(n);
         QuantLib::Date d = current; 



More information about the Rquantlib-commits mailing list