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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Aug 9 19:54:41 CEST 2010


Author: edd
Date: 2010-08-09 19:54:40 +0200 (Mon, 09 Aug 2010)
New Revision: 297

Modified:
   pkg/RQuantLib/inst/ChangeLog
   pkg/RQuantLib/src/asian.cpp
   pkg/RQuantLib/src/barrier_binary.cpp
   pkg/RQuantLib/src/bermudan.cpp
   pkg/RQuantLib/src/bonds.cpp
   pkg/RQuantLib/src/calendars.cpp
   pkg/RQuantLib/src/curves.cpp
   pkg/RQuantLib/src/daycounter.cpp
   pkg/RQuantLib/src/discount.cpp
   pkg/RQuantLib/src/hullwhite.cpp
   pkg/RQuantLib/src/implieds.cpp
   pkg/RQuantLib/src/rquantlib.h
   pkg/RQuantLib/src/utils.cpp
   pkg/RQuantLib/src/vanilla.cpp
   pkg/RQuantLib/src/zero.cpp
Log:
removed 'using namespace QuantLib;' in rquantlib.h
accordingly reworked all uses of QuantLib symbols to explicitly use QuantLib:: prefix


Modified: pkg/RQuantLib/inst/ChangeLog
===================================================================
--- pkg/RQuantLib/inst/ChangeLog	2010-08-07 18:42:14 UTC (rev 296)
+++ pkg/RQuantLib/inst/ChangeLog	2010-08-09 17:54:40 UTC (rev 297)
@@ -1,3 +1,20 @@
+2010-08-09  Dirk Eddelbuettel  <edd at debian.org>
+
+	* src/rquantlib.h: No longer use 'using namespace QuantLib'
+	* src/asian.cpp: Switch to explicitly reference all QuantLib objects
+	* src/barrier_binary.cpp: Idem
+	* src/bermudan.cpp: Idem
+	* src/bonds.cpp: Idem
+	* src/calendars.cpp: Idem
+	* src/curves.cpp: Idem
+	* src/daycounter.cpp: Idem
+	* src/discount.cpp: Idem
+	* src/hullwhite.cpp: Idem
+	* src/implieds.cpp: Idem
+	* src/utils.cpp: Idem
+	* src/vanilla.cpp: Idem
+	* src/zero.cpp: Idem
+
 2010-08-07  Dirk Eddelbuettel  <edd at debian.org>
 
 	* R/arrays.R: Rewrote EuropeanOptionArrays() to have vectorisation on
@@ -2,3 +19,3 @@
 	the C++ side rather than in R; external interface unchanged and the
-	old implementation is still available just in case
+	old implementation is still available as a fallback if needed
 	* src/vanilla.cpp: New function EuropeanOptionArrays() looping over a

Modified: pkg/RQuantLib/src/asian.cpp
===================================================================
--- pkg/RQuantLib/src/asian.cpp	2010-08-07 18:42:14 UTC (rev 296)
+++ pkg/RQuantLib/src/asian.cpp	2010-08-09 17:54:40 UTC (rev 297)
@@ -34,50 +34,50 @@
         std::string type = Rcpp::as<std::string>(rparam["type"]);
         double underlying = Rcpp::as<double>(rparam["underlying"]);
         double strike = Rcpp::as<double>(rparam["strike"]);
-        Spread dividendYield = Rcpp::as<double>(rparam["dividendYield"]);
-        Rate riskFreeRate = Rcpp::as<double>(rparam["riskFreeRate"]);
-        Time maturity = Rcpp::as<double>(rparam["maturity"]);
+        QuantLib::Spread dividendYield = Rcpp::as<double>(rparam["dividendYield"]);
+        QuantLib::Rate riskFreeRate = Rcpp::as<double>(rparam["riskFreeRate"]);
+        QuantLib::Time maturity = Rcpp::as<double>(rparam["maturity"]);
         //        int length = int(maturity*360 + 0.5); // FIXME: this could be better
         double volatility = Rcpp::as<double>(rparam["volatility"]);
 
-        Option::Type optionType = getOptionType(type);
+        QuantLib::Option::Type optionType = getOptionType(type);
 
         //from test-suite/asionoptions.cpp
-        DayCounter dc = Actual360();
-        Date today = Date::todaysDate();
-        Settings::instance().evaluationDate() = today;
+        QuantLib::DayCounter dc = QuantLib::Actual360();
+        QuantLib::Date today = QuantLib::Date::todaysDate();
+        QuantLib::Settings::instance().evaluationDate() = today;
 
-        boost::shared_ptr<SimpleQuote> spot(new SimpleQuote(underlying));
-        boost::shared_ptr<SimpleQuote> qRate(new SimpleQuote(dividendYield));
-        boost::shared_ptr<YieldTermStructure> qTS = flatRate(today, qRate, dc);
-        boost::shared_ptr<SimpleQuote> rRate(new SimpleQuote(riskFreeRate));
-        boost::shared_ptr<YieldTermStructure> rTS = flatRate(today, rRate, dc);
-        boost::shared_ptr<SimpleQuote> vol(new SimpleQuote(volatility));
-        boost::shared_ptr<BlackVolTermStructure> volTS = flatVol(today, vol, dc);
+        boost::shared_ptr<QuantLib::SimpleQuote> spot(new QuantLib::SimpleQuote(underlying));
+        boost::shared_ptr<QuantLib::SimpleQuote> qRate(new QuantLib::SimpleQuote(dividendYield));
+        boost::shared_ptr<QuantLib::YieldTermStructure> qTS = flatRate(today, qRate, dc);
+        boost::shared_ptr<QuantLib::SimpleQuote> rRate(new QuantLib::SimpleQuote(riskFreeRate));
+        boost::shared_ptr<QuantLib::YieldTermStructure> rTS = flatRate(today, rRate, dc);
+        boost::shared_ptr<QuantLib::SimpleQuote> vol(new QuantLib::SimpleQuote(volatility));
+        boost::shared_ptr<QuantLib::BlackVolTermStructure> volTS = flatVol(today, vol, dc);
         
-        boost::shared_ptr<BlackScholesMertonProcess>
+        boost::shared_ptr<QuantLib::BlackScholesMertonProcess>
             stochProcess(new
-                         BlackScholesMertonProcess(Handle<Quote>(spot),
-                                                   Handle<YieldTermStructure>(qTS),
-                                                   Handle<YieldTermStructure>(rTS),
-                                                   Handle<BlackVolTermStructure>(volTS)));
+                         QuantLib::BlackScholesMertonProcess(QuantLib::Handle<QuantLib::Quote>(spot),
+                                                             QuantLib::Handle<QuantLib::YieldTermStructure>(qTS),
+                                                             QuantLib::Handle<QuantLib::YieldTermStructure>(rTS),
+                                                             QuantLib::Handle<QuantLib::BlackVolTermStructure>(volTS)));
 
-        boost::shared_ptr<StrikedTypePayoff> payoff(new PlainVanillaPayoff(optionType,strike));
+        boost::shared_ptr<QuantLib::StrikedTypePayoff> payoff(new QuantLib::PlainVanillaPayoff(optionType,strike));
 
       
 
-        Average::Type averageType = Average::Geometric;
+        QuantLib::Average::Type averageType = QuantLib::Average::Geometric;
         Rcpp::List rl = R_NilValue;
    
         if (avgType=="geometric"){
-            averageType = Average::Geometric;
-            boost::shared_ptr<PricingEngine> 
+            averageType = QuantLib::Average::Geometric;
+            boost::shared_ptr<QuantLib::PricingEngine> 
                 engine(new
-                       AnalyticContinuousGeometricAveragePriceAsianEngine(stochProcess));        
+                       QuantLib::AnalyticContinuousGeometricAveragePriceAsianEngine(stochProcess));
             
-            Date exDate = today + int(maturity * 360 + 0.5);
-            boost::shared_ptr<Exercise> exercise(new EuropeanExercise(exDate));        
-            ContinuousAveragingAsianOption option(averageType, payoff, exercise);
+            QuantLib::Date exDate = today + int(maturity * 360 + 0.5);
+            boost::shared_ptr<QuantLib::Exercise> exercise(new QuantLib::EuropeanExercise(exDate));
+            QuantLib::ContinuousAveragingAsianOption option(averageType, payoff, exercise);
             option.setPricingEngine(engine);
             
             rl = Rcpp::List::create(Rcpp::Named("value") = option.NPV(),
@@ -90,10 +90,10 @@
                                     Rcpp::Named("parameters") = optionParameters);
             
         } else if (avgType=="arithmetic"){
-            averageType = Average::Arithmetic;
+            averageType = QuantLib::Average::Arithmetic;
 
-            boost::shared_ptr<PricingEngine> engine =
-                MakeMCDiscreteArithmeticAPEngine<LowDiscrepancy>(stochProcess)
+            boost::shared_ptr<QuantLib::PricingEngine> engine =
+                QuantLib::MakeMCDiscreteArithmeticAPEngine<QuantLib::LowDiscrepancy>(stochProcess)
                 .withSamples(2047)
                 .withControlVariate();
             
@@ -102,31 +102,31 @@
             //    .withSeed(3456789)
             //    .withSamples(1023);
             
-            Size fixings = Rcpp::as<double>(rparam["fixings"]);
-            Time length = Rcpp::as<double>(rparam["length"]);
-            Time first = Rcpp::as<double>(rparam["first"]);
-            Time dt = length / (fixings - 1);
+            QuantLib::Size fixings = Rcpp::as<double>(rparam["fixings"]);
+            QuantLib::Time length = Rcpp::as<double>(rparam["length"]);
+            QuantLib::Time first = Rcpp::as<double>(rparam["first"]);
+            QuantLib::Time dt = length / (fixings - 1);
 
-            std::vector<Time> timeIncrements(fixings);
-            std::vector<Date> fixingDates(fixings);
+            std::vector<QuantLib::Time> timeIncrements(fixings);
+            std::vector<QuantLib::Date> fixingDates(fixings);
             timeIncrements[0] = first;
-            fixingDates[0] = today + Integer(timeIncrements[0] * 360 + 0.5);
-            for (Size i=1; i<fixings; i++) {
+            fixingDates[0] = today + QuantLib::Integer(timeIncrements[0] * 360 + 0.5);
+            for (QuantLib::Size i=1; i<fixings; i++) {
                 timeIncrements[i] = i*dt + first;
-                fixingDates[i] = today + Integer(timeIncrements[i]*360+0.5);
+                fixingDates[i] = today + QuantLib::Integer(timeIncrements[i]*360+0.5);
             }
-            Real runningSum = 0.0;
-            Size pastFixing = 0;
+            QuantLib::Real runningSum = 0.0;
+            QuantLib::Size pastFixing = 0;
 
-            boost::shared_ptr<Exercise> exercise(new
-                                                 EuropeanExercise(fixingDates[fixings-1]));
+            boost::shared_ptr<QuantLib::Exercise> 
+                exercise(new QuantLib::EuropeanExercise(fixingDates[fixings-1]));
 
-            DiscreteAveragingAsianOption option(Average::Arithmetic, 
-                                                runningSum,
-                                                pastFixing, 
-                                                fixingDates,
-                                                payoff, 
-                                                exercise);
+            QuantLib::DiscreteAveragingAsianOption option(QuantLib::Average::Arithmetic, 
+                                                          runningSum,
+                                                          pastFixing, 
+                                                          fixingDates,
+                                                          payoff, 
+                                                          exercise);
             option.setPricingEngine(engine);
             rl = Rcpp::List::create(Rcpp::Named("value") = option.NPV(),
                                     Rcpp::Named("delta") = R_NaN,

Modified: pkg/RQuantLib/src/barrier_binary.cpp
===================================================================
--- pkg/RQuantLib/src/barrier_binary.cpp	2010-08-07 18:42:14 UTC (rev 296)
+++ pkg/RQuantLib/src/barrier_binary.cpp	2010-08-09 17:54:40 UTC (rev 297)
@@ -34,74 +34,74 @@
         std::string excType = Rcpp::as<std::string>(rparam["excType"]);
         double underlying = Rcpp::as<double>(rparam["underlying"]);
         double strike = Rcpp::as<double>(rparam["strike"]);
-        Spread dividendYield = Rcpp::as<double>(rparam["dividendYield"]);
-        Rate riskFreeRate = Rcpp::as<double>(rparam["riskFreeRate"]);
-        Time maturity = Rcpp::as<double>(rparam["maturity"]);
+        QuantLib::Spread dividendYield = Rcpp::as<double>(rparam["dividendYield"]);
+        QuantLib::Rate riskFreeRate = Rcpp::as<double>(rparam["riskFreeRate"]);
+        QuantLib::Time maturity = Rcpp::as<double>(rparam["maturity"]);
         int length = int(maturity*360 + 0.5); // FIXME: this could be better, but same rounding in QL
         double volatility = Rcpp::as<double>(rparam["volatility"]);
         double cashPayoff = Rcpp::as<double>(rparam["cashPayoff"]);
     
-        Option::Type optionType = getOptionType(type);
+        QuantLib::Option::Type optionType = getOptionType(type);
 
         // new QuantLib 0.3.5 framework: digitals, updated for 0.3.7
         // updated again for QuantLib 0.9.0, 
         // cf QuantLib-0.9.0/test-suite/digitaloption.cpp
-        Date today = Date::todaysDate();
-        Settings::instance().evaluationDate() = today;
+        QuantLib::Date today = QuantLib::Date::todaysDate();
+        QuantLib::Settings::instance().evaluationDate() = today;
 
-        DayCounter dc = Actual360();
-        boost::shared_ptr<SimpleQuote> spot(new SimpleQuote(underlying));
-        boost::shared_ptr<SimpleQuote> qRate(new SimpleQuote(dividendYield));
-        boost::shared_ptr<YieldTermStructure> qTS = flatRate(today,qRate,dc);
-        boost::shared_ptr<SimpleQuote> rRate(new SimpleQuote(riskFreeRate));
-        boost::shared_ptr<YieldTermStructure> rTS = flatRate(today,rRate,dc);
-        boost::shared_ptr<SimpleQuote> vol(new SimpleQuote(volatility));
-        boost::shared_ptr<BlackVolTermStructure> volTS = flatVol(today, vol, dc);
+        QuantLib::DayCounter dc = QuantLib::Actual360();
+        boost::shared_ptr<QuantLib::SimpleQuote> spot(new QuantLib::SimpleQuote(underlying));
+        boost::shared_ptr<QuantLib::SimpleQuote> qRate(new QuantLib::SimpleQuote(dividendYield));
+        boost::shared_ptr<QuantLib::YieldTermStructure> qTS = flatRate(today,qRate,dc);
+        boost::shared_ptr<QuantLib::SimpleQuote> rRate(new QuantLib::SimpleQuote(riskFreeRate));
+        boost::shared_ptr<QuantLib::YieldTermStructure> rTS = flatRate(today,rRate,dc);
+        boost::shared_ptr<QuantLib::SimpleQuote> vol(new QuantLib::SimpleQuote(volatility));
+        boost::shared_ptr<QuantLib::BlackVolTermStructure> volTS = flatVol(today, vol, dc);
 
-        boost::shared_ptr<StrikedTypePayoff> payoff;
+        boost::shared_ptr<QuantLib::StrikedTypePayoff> payoff;
         if (binType=="cash") {
-            boost::shared_ptr<StrikedTypePayoff> con(new CashOrNothingPayoff(optionType, strike, cashPayoff));
+            boost::shared_ptr<QuantLib::StrikedTypePayoff> con(new QuantLib::CashOrNothingPayoff(optionType, strike, cashPayoff));
             payoff = con;
         } else if (binType=="asset") {
-            boost::shared_ptr<StrikedTypePayoff> aon(new AssetOrNothingPayoff(optionType, strike));
+            boost::shared_ptr<QuantLib::StrikedTypePayoff> aon(new QuantLib::AssetOrNothingPayoff(optionType, strike));
             payoff = aon;
         } else if (binType=="gap") {
-            boost::shared_ptr<StrikedTypePayoff> gap(new GapPayoff(optionType, strike, cashPayoff));
+            boost::shared_ptr<QuantLib::StrikedTypePayoff> gap(new QuantLib::GapPayoff(optionType, strike, cashPayoff));
             payoff = gap;
         } else {
             throw std::range_error("Unknown binary option type " + binType);
         }
 
-        Date exDate = today + length;
-        boost::shared_ptr<Exercise> exercise;
+        QuantLib::Date exDate = today + length;
+        boost::shared_ptr<QuantLib::Exercise> exercise;
         if (excType=="american") {
-            boost::shared_ptr<Exercise> amEx(new AmericanExercise(today, exDate));
+            boost::shared_ptr<QuantLib::Exercise> amEx(new QuantLib::AmericanExercise(today, exDate));
             exercise = amEx;
         } else if (excType=="european") {
-            boost::shared_ptr<Exercise> euEx(new EuropeanExercise(exDate));
+            boost::shared_ptr<QuantLib::Exercise> euEx(new QuantLib::EuropeanExercise(exDate));
             exercise = euEx;
         } else {
             throw std::range_error("Unknown binary exercise type " + excType);
         }
 
-        boost::shared_ptr<BlackScholesMertonProcess> stochProcess(new 
-              BlackScholesMertonProcess(Handle<Quote>(spot),
-                                        Handle<YieldTermStructure>(qTS),
-                                        Handle<YieldTermStructure>(rTS),
-                                        Handle<BlackVolTermStructure>(volTS)));
+        boost::shared_ptr<QuantLib::BlackScholesMertonProcess> stochProcess(new 
+              QuantLib::BlackScholesMertonProcess(QuantLib::Handle<QuantLib::Quote>(spot),
+                                                  QuantLib::Handle<QuantLib::YieldTermStructure>(qTS),
+                                                  QuantLib::Handle<QuantLib::YieldTermStructure>(rTS),
+                                                  QuantLib::Handle<QuantLib::BlackVolTermStructure>(volTS)));
 
-        boost::shared_ptr<PricingEngine> engine;
+        boost::shared_ptr<QuantLib::PricingEngine> engine;
         if (excType=="american") {
-            boost::shared_ptr<PricingEngine> amEng(new AnalyticDigitalAmericanEngine(stochProcess));
+            boost::shared_ptr<QuantLib::PricingEngine> amEng(new QuantLib::AnalyticDigitalAmericanEngine(stochProcess));
             engine = amEng;
         } else if (excType=="european") {
-            boost::shared_ptr<PricingEngine> euEng(new AnalyticEuropeanEngine(stochProcess));
+            boost::shared_ptr<QuantLib::PricingEngine> euEng(new QuantLib::AnalyticEuropeanEngine(stochProcess));
             engine = euEng;
         } else {
             throw std::range_error("Unknown binary exercise type " + excType);
         }
 
-        VanillaOption opt(payoff, exercise);
+        QuantLib::VanillaOption opt(payoff, exercise);
         opt.setPricingEngine(engine);
 
         Rcpp::List rl = Rcpp::List::create(Rcpp::Named("value") = opt.NPV(),
@@ -135,43 +135,43 @@
         double value = Rcpp::as<double>(rparam["value"]);
         double underlying = Rcpp::as<double>(rparam["underlying"]);
         double strike = Rcpp::as<double>(rparam["strike"]);
-        Spread dividendYield = Rcpp::as<double>(rparam["dividendYield"]);
-        Rate riskFreeRate = Rcpp::as<double>(rparam["riskFreeRate"]);
-        Time maturity = Rcpp::as<double>(rparam["maturity"]);
+        QuantLib::Spread dividendYield = Rcpp::as<double>(rparam["dividendYield"]);
+        QuantLib::Rate riskFreeRate = Rcpp::as<double>(rparam["riskFreeRate"]);
+        QuantLib::Time maturity = Rcpp::as<double>(rparam["maturity"]);
         int length = int(maturity*360 + 0.5); // FIXME: this could be better
         double volatility = Rcpp::as<double>(rparam["volatility"]);
         double cashPayoff = Rcpp::as<double>(rparam["cashPayoff"]);
 
-        Option::Type optionType = getOptionType(type);
+        QuantLib::Option::Type optionType = getOptionType(type);
 
         // updated again for QuantLib 0.9.0, 
         // cf QuantLib-0.9.0/test-suite/digitaloption.cpp
-        Date today = Date::todaysDate();
-        Settings::instance().evaluationDate() = today;
-        DayCounter dc = Actual360();
-        boost::shared_ptr<SimpleQuote> spot(new SimpleQuote(underlying));
-        boost::shared_ptr<SimpleQuote> qRate(new SimpleQuote(dividendYield));
-        boost::shared_ptr<YieldTermStructure> qTS = flatRate(today, qRate, dc);
-        boost::shared_ptr<SimpleQuote> rRate(new SimpleQuote(riskFreeRate));
-        boost::shared_ptr<YieldTermStructure> rTS = flatRate(today, rRate, dc);
-        boost::shared_ptr<SimpleQuote> vol(new SimpleQuote(volatility));
-        boost::shared_ptr<BlackVolTermStructure> volTS = flatVol(today, vol, dc);
+        QuantLib::Date today = QuantLib::Date::todaysDate();
+        QuantLib::Settings::instance().evaluationDate() = today;
+        QuantLib::DayCounter dc = QuantLib::Actual360();
+        boost::shared_ptr<QuantLib::SimpleQuote> spot(new QuantLib::SimpleQuote(underlying));
+        boost::shared_ptr<QuantLib::SimpleQuote> qRate(new QuantLib::SimpleQuote(dividendYield));
+        boost::shared_ptr<QuantLib::YieldTermStructure> qTS = flatRate(today, qRate, dc);
+        boost::shared_ptr<QuantLib::SimpleQuote> rRate(new QuantLib::SimpleQuote(riskFreeRate));
+        boost::shared_ptr<QuantLib::YieldTermStructure> rTS = flatRate(today, rRate, dc);
+        boost::shared_ptr<QuantLib::SimpleQuote> vol(new QuantLib::SimpleQuote(volatility));
+        boost::shared_ptr<QuantLib::BlackVolTermStructure> volTS = flatVol(today, vol, dc);
 
-        boost::shared_ptr<StrikedTypePayoff> 
-            payoff(new CashOrNothingPayoff(optionType, strike, cashPayoff));
+        boost::shared_ptr<QuantLib::StrikedTypePayoff> 
+            payoff(new QuantLib::CashOrNothingPayoff(optionType, strike, cashPayoff));
 
-        Date exDate = today + length;
-        boost::shared_ptr<Exercise> exercise(new EuropeanExercise(exDate));
+        QuantLib::Date exDate = today + length;
+        boost::shared_ptr<QuantLib::Exercise> exercise(new QuantLib::EuropeanExercise(exDate));
 
-        boost::shared_ptr<BlackScholesMertonProcess> stochProcess(new 
-               BlackScholesMertonProcess(Handle<Quote>(spot),
-                                         Handle<YieldTermStructure>(qTS),
-                                         Handle<YieldTermStructure>(rTS),
-                                         Handle<BlackVolTermStructure>(volTS)));
+        boost::shared_ptr<QuantLib::BlackScholesMertonProcess> stochProcess(new 
+               QuantLib::BlackScholesMertonProcess(QuantLib::Handle<QuantLib::Quote>(spot),
+                                                   QuantLib::Handle<QuantLib::YieldTermStructure>(qTS),
+                                                   QuantLib::Handle<QuantLib::YieldTermStructure>(rTS),
+                                                   QuantLib::Handle<QuantLib::BlackVolTermStructure>(volTS)));
         //boost::shared_ptr<PricingEngine> engine(new AnalyticEuropeanEngine(stochProcess));
-        boost::shared_ptr<PricingEngine> engine(new AnalyticBarrierEngine(stochProcess));
+        boost::shared_ptr<QuantLib::PricingEngine> engine(new QuantLib::AnalyticBarrierEngine(stochProcess));
 
-        VanillaOption opt(payoff, exercise);
+        QuantLib::VanillaOption opt(payoff, exercise);
         opt.setPricingEngine(engine);
 
         return Rcpp::List::create(Rcpp::Named("impliedVol") = opt.impliedVolatility(value, stochProcess),
@@ -196,54 +196,54 @@
         std::string type = Rcpp::as<std::string>(rparam["type"]);
         double underlying = Rcpp::as<double>(rparam["underlying"]);
         double strike = Rcpp::as<double>(rparam["strike"]);
-        Spread dividendYield = Rcpp::as<double>(rparam["dividendYield"]);
-        Rate riskFreeRate = Rcpp::as<double>(rparam["riskFreeRate"]);
-        Time maturity = Rcpp::as<double>(rparam["maturity"]);
+        QuantLib::Spread dividendYield = Rcpp::as<double>(rparam["dividendYield"]);
+        QuantLib::Rate riskFreeRate = Rcpp::as<double>(rparam["riskFreeRate"]);
+        QuantLib::Time maturity = Rcpp::as<double>(rparam["maturity"]);
         int length = int(maturity*360 + 0.5); // FIXME: this could be better
         double volatility = Rcpp::as<double>(rparam["volatility"]);
         double barrier = Rcpp::as<double>(rparam["barrier"]);
         double rebate = Rcpp::as<double>(rparam["rebate"]);
         
-        Barrier::Type barrierType=Barrier::DownIn;
+        QuantLib::Barrier::Type barrierType = QuantLib::Barrier::DownIn;
         if (barrType=="downin") {
-            barrierType = Barrier::DownIn;
+            barrierType = QuantLib::Barrier::DownIn;
         } else if (barrType=="upin") {
-            barrierType = Barrier::UpIn;
+            barrierType = QuantLib::Barrier::UpIn;
         } else if (barrType=="downout") {
-            barrierType = Barrier::DownOut;
+            barrierType = QuantLib::Barrier::DownOut;
         } else if (barrType=="upout") {
-            barrierType = Barrier::UpOut;
+            barrierType = QuantLib::Barrier::UpOut;
         } else {
             throw std::range_error("Unknown barrier type " + type);
         }
 
-        Option::Type optionType = getOptionType(type);
+        QuantLib::Option::Type optionType = getOptionType(type);
 
         // new QuantLib 0.3.5 framework, updated for 0.3.7
         // updated again for QuantLib 0.9.0, 
         // cf QuantLib-0.9.0/test-suite/barrieroption.cpp
-        Date today = Date::todaysDate();
-        Settings::instance().evaluationDate() = today;
-        DayCounter dc = Actual360();
-        boost::shared_ptr<SimpleQuote> spot(new SimpleQuote(underlying));
-        boost::shared_ptr<SimpleQuote> qRate(new SimpleQuote(dividendYield));
-        boost::shared_ptr<YieldTermStructure> qTS = flatRate(today, qRate, dc);
-        boost::shared_ptr<SimpleQuote> rRate(new SimpleQuote(riskFreeRate));
-        boost::shared_ptr<YieldTermStructure> rTS = flatRate(today,rRate,dc);
-        boost::shared_ptr<SimpleQuote> vol(new SimpleQuote(volatility));
-        boost::shared_ptr<BlackVolTermStructure> volTS = flatVol(today, vol, dc);
+        QuantLib::Date today = QuantLib::Date::todaysDate();
+        QuantLib::Settings::instance().evaluationDate() = today;
+        QuantLib::DayCounter dc = QuantLib::Actual360();
+        boost::shared_ptr<QuantLib::SimpleQuote> spot(new QuantLib::SimpleQuote(underlying));
+        boost::shared_ptr<QuantLib::SimpleQuote> qRate(new QuantLib::SimpleQuote(dividendYield));
+        boost::shared_ptr<QuantLib::YieldTermStructure> qTS = flatRate(today, qRate, dc);
+        boost::shared_ptr<QuantLib::SimpleQuote> rRate(new QuantLib::SimpleQuote(riskFreeRate));
+        boost::shared_ptr<QuantLib::YieldTermStructure> rTS = flatRate(today,rRate,dc);
+        boost::shared_ptr<QuantLib::SimpleQuote> vol(new QuantLib::SimpleQuote(volatility));
+        boost::shared_ptr<QuantLib::BlackVolTermStructure> volTS = flatVol(today, vol, dc);
 
-        Date exDate = today + length;
-        boost::shared_ptr<Exercise> exercise(new EuropeanExercise(exDate));
+        QuantLib::Date exDate = today + length;
+        boost::shared_ptr<QuantLib::Exercise> exercise(new QuantLib::EuropeanExercise(exDate));
         
-        boost::shared_ptr<StrikedTypePayoff> payoff(new PlainVanillaPayoff(optionType, strike));
+        boost::shared_ptr<QuantLib::StrikedTypePayoff> payoff(new QuantLib::PlainVanillaPayoff(optionType, strike));
 
-        boost::shared_ptr<BlackScholesMertonProcess> 
-            stochProcess(new BlackScholesMertonProcess(
-                	Handle<Quote>(spot),
-                	Handle<YieldTermStructure>(qTS),
-                	Handle<YieldTermStructure>(rTS),
-                	Handle<BlackVolTermStructure>(volTS)));
+        boost::shared_ptr<QuantLib::BlackScholesMertonProcess> 
+            stochProcess(new QuantLib::BlackScholesMertonProcess(
+                	QuantLib::Handle<QuantLib::Quote>(spot),
+                	QuantLib::Handle<QuantLib::YieldTermStructure>(qTS),
+                	QuantLib::Handle<QuantLib::YieldTermStructure>(rTS),
+                	QuantLib::Handle<QuantLib::BlackVolTermStructure>(volTS)));
 
         // Size timeSteps = 1;
         // bool antitheticVariate = false;
@@ -253,7 +253,7 @@
         // Size maxSamples = 1000000;
         // bool isBiased = false;
 
-        boost::shared_ptr<PricingEngine> engine(new AnalyticBarrierEngine(stochProcess));
+        boost::shared_ptr<QuantLib::PricingEngine> engine(new QuantLib::AnalyticBarrierEngine(stochProcess));
 
         // need to explicitly reference BarrierOption from QuantLib here
         QuantLib::BarrierOption barrierOption(barrierType,

Modified: pkg/RQuantLib/src/bermudan.cpp
===================================================================
--- pkg/RQuantLib/src/bermudan.cpp	2010-08-07 18:42:14 UTC (rev 296)
+++ pkg/RQuantLib/src/bermudan.cpp	2010-08-09 17:54:40 UTC (rev 297)
@@ -20,24 +20,24 @@
 #include "rquantlib.h"
 
 // Calibrates underlying swaptions to the input volatility matrix.
-void calibrateModel(const boost::shared_ptr<ShortRateModel>& model,
-                    const std::vector<boost::shared_ptr<CalibrationHelper> > &helpers,
-                    Real lambda,
+void calibrateModel(const boost::shared_ptr<QuantLib::ShortRateModel>& model,
+                    const std::vector<boost::shared_ptr<QuantLib::CalibrationHelper> > &helpers,
+                    QuantLib::Real lambda,
                     Rcpp::NumericVector &swaptionMat, 
                     Rcpp::NumericVector &swapLengths, 
                     Rcpp::NumericMatrix &swaptionVols) {
 
-    Size numRows = swaptionVols.nrow();
-    Size numCols = swaptionVols.ncol();
-    LevenbergMarquardt om;
-    model->calibrate(helpers, om, EndCriteria(400,100,1.0e-8, 1.0e-8, 1.0e-8));
+    QuantLib::Size numRows = swaptionVols.nrow();
+    QuantLib::Size numCols = swaptionVols.ncol();
+    QuantLib::LevenbergMarquardt om;
+    model->calibrate(helpers, om,QuantLib:: EndCriteria(400,100,1.0e-8, 1.0e-8, 1.0e-8));
 
     // Output the implied Black volatilities
-    for (Size i=0; i<numRows; i++) {
-	Real npv = helpers[i]->modelValue();
-	Volatility implied = helpers[i]->impliedVolatility(npv, 1e-4,
+    for (QuantLib::Size i=0; i<numRows; i++) {
+	QuantLib::Real npv = helpers[i]->modelValue();
+	QuantLib::Volatility implied = helpers[i]->impliedVolatility(npv, 1e-4,
                                                            1000, 0.05, 0.50);
-	Volatility diff = implied - swaptionVols(i, numCols-i-1);
+	QuantLib::Volatility diff = implied - swaptionVols(i, numCols-i-1);
 
 	Rprintf((char*) "%dx%d: model %lf, market %lf, diff %lf\n",
             swaptionMat[i], swapLengths[numCols-i-1], implied, 
@@ -55,18 +55,18 @@
         Rcpp::List tslist(tsQuotes);
         std::vector<std::string> tsnames = tslist.names();
 
-        Size i;
+        QuantLib::Size i;
         //int *swaptionMat=0, *swapLengths=0;
         //double **swaptionVols=0;
 
         double notional = 10000; // prices in basis points
 
-        Date todaysDate(dateFromR(Rcpp::as<int>(rparam["tradeDate"]))); 
-        Date settlementDate(dateFromR(Rcpp::as<int>(rparam["settleDate"]))); 
+        QuantLib::Date todaysDate(dateFromR(Rcpp::as<Rcpp::Date>(rparam["tradeDate"]))); 
+        QuantLib::Date settlementDate(dateFromR(Rcpp::as<Rcpp::Date>(rparam["settleDate"]))); 
         //cout << "TradeDate: " << todaysDate << endl << "Settle: " << settlementDate << endl;
 
         RQLContext::instance().settleDate = settlementDate;
-        Settings::instance().evaluationDate() = todaysDate;
+        QuantLib::Settings::instance().evaluationDate() = todaysDate;
 
         double strike = Rcpp::as<double>(rparam["strike"]);
         std::string method = Rcpp::as<std::string>(rparam["method"]);
@@ -81,31 +81,31 @@
         }
 
         // initialise from the singleton instance
-        Calendar calendar = RQLContext::instance().calendar;
+        QuantLib::Calendar calendar = RQLContext::instance().calendar;
         //Integer fixingDays = RQLContext::instance().fixingDays;
 
         // Any DayCounter would be fine.
         // ActualActual::ISDA ensures that 30 years is 30.0
-        DayCounter termStructureDayCounter = ActualActual(ActualActual::ISDA);
+        QuantLib::DayCounter termStructureDayCounter = QuantLib::ActualActual(QuantLib::ActualActual::ISDA);
         double tolerance = 1.0e-15;
 
-        boost::shared_ptr<YieldTermStructure> curve;
+        boost::shared_ptr<QuantLib::YieldTermStructure> curve;
         if(firstQuoteName.compare("flat") == 0) {
             // Get flat yield curve
             double rateQuote = tslist[0]; //tslist.getValue(0);
-            boost::shared_ptr<Quote> flatRate(new SimpleQuote(rateQuote));
-            boost::shared_ptr<FlatForward> ts(new FlatForward(settlementDate,
-                                                              Handle<Quote>(flatRate),
-                                                              Actual365Fixed()));
+            boost::shared_ptr<QuantLib::Quote> flatRate(new QuantLib::SimpleQuote(rateQuote));
+            boost::shared_ptr<QuantLib::FlatForward> ts(new QuantLib::FlatForward(settlementDate,
+                                                                                  QuantLib::Handle<QuantLib::Quote>(flatRate),
+                                                                                  QuantLib::Actual365Fixed()));
             curve = ts;
         }
         else {
             // Get yield curve based on a set of market rates and/or prices.
-            std::vector<boost::shared_ptr<RateHelper> > curveInput;
-            for(i = 0; i < (Size)tslist.size(); i++) {
+            std::vector<boost::shared_ptr<QuantLib::RateHelper> > curveInput;
+            for(i = 0; i < (QuantLib::Size)tslist.size(); i++) {
                 std::string name = tsnames[i]; //tslist.getName(i);
                 double val = tslist[i]; //tslist.getValue(i);
-                boost::shared_ptr<RateHelper> rh = 
+                boost::shared_ptr<QuantLib::RateHelper> rh = 
                     ObservableDB::instance().getRateHelper(name, val);
                 // edd 2009-11-01 FIXME NULL_RateHelper no longer builds under 0.9.9
                 // if(rh == NULL_RateHelper)
@@ -113,7 +113,7 @@
                     throw std::range_error("Unknown rate in getRateHelper");
                 curveInput.push_back(rh);
             }
-            boost::shared_ptr<YieldTermStructure> ts =
+            boost::shared_ptr<QuantLib::YieldTermStructure> ts =
                 getTermStructure(interpWhat, interpHow, 
                                  settlementDate, curveInput,
                                  termStructureDayCounter, tolerance);
@@ -121,11 +121,11 @@
         }
         //Handle<YieldTermStructure> rhTermStructure;
         //rhTermStructure.linkTo(curve);
-        boost::shared_ptr<Quote> flatRate(new SimpleQuote(0.04875825));  // FIXME: hardcoded?
-        Handle<YieldTermStructure> 
-            rhTermStructure(boost::shared_ptr<FlatForward>(new FlatForward(settlementDate, 
-                                                                           Handle<Quote>(flatRate),
-                                                                           Actual365Fixed())));
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/rquantlib -r 297


More information about the Rquantlib-commits mailing list