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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Jun 20 16:18:47 CEST 2010


Author: edd
Date: 2010-06-20 16:18:47 +0200 (Sun, 20 Jun 2010)
New Revision: 262

Modified:
   pkg/RQuantLib/inst/ChangeLog
   pkg/RQuantLib/src/asian.cpp
   pkg/RQuantLib/src/barrier_binary.cpp
   pkg/RQuantLib/src/implieds.cpp
   pkg/RQuantLib/src/rquantlib.hpp
   pkg/RQuantLib/src/utils.cpp
   pkg/RQuantLib/src/vanilla.cpp
   pkg/RQuantLib/src/zero.cpp
Log:
some minor cleanup and reindentation,
ensure Settings::instance().evaluationDate() is set


Modified: pkg/RQuantLib/inst/ChangeLog
===================================================================
--- pkg/RQuantLib/inst/ChangeLog	2010-06-19 21:33:44 UTC (rev 261)
+++ pkg/RQuantLib/inst/ChangeLog	2010-06-20 14:18:47 UTC (rev 262)
@@ -1,3 +1,8 @@
+2010-06-20  Dirk Eddelbuettel  <edd at debian.org>
+
+	* src/*.cpp: Some minor cleanup and reindentation,
+	  ensure Settings::instance().evaluationDate() is set
+
 2010-06-19  Dirk Eddelbuettel  <edd at debian.org>
 
 	* src/bonds.cpp: Converted to new API

Modified: pkg/RQuantLib/src/asian.cpp
===================================================================
--- pkg/RQuantLib/src/asian.cpp	2010-06-19 21:33:44 UTC (rev 261)
+++ pkg/RQuantLib/src/asian.cpp	2010-06-20 14:18:47 UTC (rev 262)
@@ -45,20 +45,18 @@
         Average::Type averageType = Average::Geometric;
         if (avgType=="geometric"){
             averageType = Average::Geometric;
-        }
-        else if (avgType=="arithmetic"){
+        } else if (avgType=="arithmetic"){
             averageType = Average::Arithmetic;
-        }
-        else{
+        } else {
             throw std::range_error("Unknown average type " + type);
         }
         
 
         //from test-suite/asionoptions.cpp
-
         DayCounter dc = Actual360();
         Date today = Date::todaysDate();
-        
+        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);

Modified: pkg/RQuantLib/src/barrier_binary.cpp
===================================================================
--- pkg/RQuantLib/src/barrier_binary.cpp	2010-06-19 21:33:44 UTC (rev 261)
+++ pkg/RQuantLib/src/barrier_binary.cpp	2010-06-20 14:18:47 UTC (rev 262)
@@ -47,6 +47,8 @@
         // 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));
@@ -145,6 +147,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;
         DayCounter dc = Actual360();
         boost::shared_ptr<SimpleQuote> spot(new SimpleQuote(underlying));
         boost::shared_ptr<SimpleQuote> qRate(new SimpleQuote(dividendYield));
@@ -220,6 +223,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));

Modified: pkg/RQuantLib/src/implieds.cpp
===================================================================
--- pkg/RQuantLib/src/implieds.cpp	2010-06-19 21:33:44 UTC (rev 261)
+++ pkg/RQuantLib/src/implieds.cpp	2010-06-20 14:18:47 UTC (rev 262)
@@ -47,6 +47,7 @@
         Option::Type optionType = getOptionType(type);
 
         Date today = Date::todaysDate();
+        Settings::instance().evaluationDate() = today;
 
         // new framework as per QuantLib 0.3.5
         // updated for 0.3.7
@@ -108,6 +109,7 @@
         Option::Type optionType = getOptionType(type);
 
         Date today = Date::todaysDate();
+        Settings::instance().evaluationDate() = today;
 
         // new framework as per QuantLib 0.3.5
         DayCounter dc = Actual360();
@@ -120,6 +122,8 @@
         boost::shared_ptr<YieldTermStructure> rTS = flatRate(today,rRate,dc);
 
         Date exDate = today + length;
+        Settings::instance().evaluationDate() = today;
+
         //boost::shared_ptr<Exercise> exercise(new EuropeanExercise(exDate));
         boost::shared_ptr<Exercise> exercise(new AmericanExercise(today, exDate));
         boost::shared_ptr<StrikedTypePayoff> payoff(new PlainVanillaPayoff(optionType, strike));

Modified: pkg/RQuantLib/src/rquantlib.hpp
===================================================================
--- pkg/RQuantLib/src/rquantlib.hpp	2010-06-19 21:33:44 UTC (rev 261)
+++ pkg/RQuantLib/src/rquantlib.hpp	2010-06-20 14:18:47 UTC (rev 262)
@@ -35,10 +35,10 @@
 //#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);
+//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 Singleton<RQLContext> {
@@ -49,6 +49,7 @@
         settleDate = 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.
     Date settleDate;
     Calendar calendar;
@@ -151,9 +152,7 @@
 boost::shared_ptr<IborIndex> getIborIndex(SEXP index, const Date today);
 std::vector<double> getDoubleVector(SEXP vector);
 boost::shared_ptr<YieldTermStructure> getFlatCurve(SEXP flatcurve);
-boost::shared_ptr<YieldTermStructure> rebuildCurveFromZeroRates(
-                                                                SEXP dateSexp,
-                                                                SEXP zeroSexp);
+boost::shared_ptr<YieldTermStructure> rebuildCurveFromZeroRates(SEXP dateSexp, SEXP zeroSexp);
 boost::shared_ptr<IborIndex> buildIborIndex(std::string type,
                                             const Handle<YieldTermStructure>& iborStrc);
 Calendar* getCalendar(SEXP calParameters);

Modified: pkg/RQuantLib/src/utils.cpp
===================================================================
--- pkg/RQuantLib/src/utils.cpp	2010-06-19 21:33:44 UTC (rev 261)
+++ pkg/RQuantLib/src/utils.cpp	2010-06-20 14:18:47 UTC (rev 262)
@@ -268,8 +268,7 @@
 makeFlatVolatility(const Date& today,
                    const boost::shared_ptr<Quote>& vol,
                    const DayCounter dc) {
-    return boost::shared_ptr<BlackVolTermStructure>(
-                                                    new BlackConstantVol(today, 
+    return boost::shared_ptr<BlackVolTermStructure>(new BlackConstantVol(today, 
                                                                          NullCalendar(), 
                                                                          Handle<Quote>(vol), dc));
 }
@@ -284,15 +283,16 @@
                                 Handle<Quote>(vol), dc));
 }
 
+typedef BlackScholesMertonProcess BSMProcess; // shortcut
 boost::shared_ptr<GeneralizedBlackScholesProcess>
 makeProcess(const boost::shared_ptr<Quote>& u,
             const boost::shared_ptr<YieldTermStructure>& q,
             const boost::shared_ptr<YieldTermStructure>& r,
             const boost::shared_ptr<BlackVolTermStructure>& vol) {
-    return boost::shared_ptr<BlackScholesMertonProcess>(new BlackScholesMertonProcess(Handle<Quote>(u),
-                                                                                      Handle<YieldTermStructure>(q),
-                                                                                      Handle<YieldTermStructure>(r),
-                                                                                      Handle<BlackVolTermStructure>(vol)));
+    return boost::shared_ptr<BSMProcess>(new BSMProcess(Handle<Quote>(u),
+                                                        Handle<YieldTermStructure>(q),
+                                                        Handle<YieldTermStructure>(r),
+                                                        Handle<BlackVolTermStructure>(vol)));
 }
 
 // R uses dates indexed to Jan 1, 1970. Rcpp uses an internal Julian Date representation,

Modified: pkg/RQuantLib/src/vanilla.cpp
===================================================================
--- pkg/RQuantLib/src/vanilla.cpp	2010-06-19 21:33:44 UTC (rev 261)
+++ pkg/RQuantLib/src/vanilla.cpp	2010-06-20 14:18:47 UTC (rev 262)
@@ -28,20 +28,21 @@
 
     try {
 
-        Rcpp::List rparam(optionParameters);    	// Parameters via list
+        Rcpp::List rparam(optionParameters);    	// Parameters via R list object
 
-        std::string type = Rcpp::as<std::string>(rparam["type"]);
-        double underlying = Rcpp::as<double>(rparam["underlying"]);
-        double strike = Rcpp::as<double>(rparam["strike"]);
+        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"]);
-        int length = int(maturity*360 + 0.5); // FIXME: this could be better
-        double volatility = Rcpp::as<double>(rparam["volatility"]);
+        Rate riskFreeRate    = Rcpp::as<double>(rparam["riskFreeRate"]);
+        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);
 
         Date today = Date::todaysDate();
+        Settings::instance().evaluationDate() = today;
 
         // new framework as per QuantLib 0.3.5
         DayCounter dc = Actual360();
@@ -49,9 +50,9 @@
         boost::shared_ptr<SimpleQuote> vol(new SimpleQuote( volatility ));
         boost::shared_ptr<BlackVolTermStructure> volTS = flatVol(today, vol, dc);
         boost::shared_ptr<SimpleQuote> qRate(new SimpleQuote( dividendYield ));
-        boost::shared_ptr<YieldTermStructure> qTS = flatRate(today,qRate,dc);
+        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<YieldTermStructure> rTS = flatRate(today, rRate, dc);
 
         Date exDate = today + length;
         boost::shared_ptr<Exercise> exercise(new EuropeanExercise(exDate));
@@ -97,6 +98,7 @@
         // new framework as per QuantLib 0.3.5, updated for 0.3.7
         // updated again for 0.9.0, see eg test-suite/americanoption.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));

Modified: pkg/RQuantLib/src/zero.cpp
===================================================================
--- pkg/RQuantLib/src/zero.cpp	2010-06-19 21:33:44 UTC (rev 261)
+++ pkg/RQuantLib/src/zero.cpp	2010-06-20 14:18:47 UTC (rev 262)
@@ -149,7 +149,6 @@
 
         Calendar calendar = UnitedStates(UnitedStates::GovernmentBond);
         Date todaysDate = calendar.advance(SettleDates[0], -2, Days);
-        // nothing to do with Date::todaysDate
         Settings::instance().evaluationDate() = todaysDate;
         Period p(getFrequency(2));
         double faceAmount = 100;



More information about the Rquantlib-commits mailing list