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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri May 31 03:33:56 CEST 2013


Author: edd
Date: 2013-05-31 03:33:55 +0200 (Fri, 31 May 2013)
New Revision: 330

Added:
   pkg/RQuantLib/R/mod.R
   pkg/RQuantLib/src/modules.cpp
Modified:
   pkg/RQuantLib/DESCRIPTION
   pkg/RQuantLib/NAMESPACE
Log:
adding initial modules explorations done three days ago

Modified: pkg/RQuantLib/DESCRIPTION
===================================================================
--- pkg/RQuantLib/DESCRIPTION	2013-05-31 01:32:17 UTC (rev 329)
+++ pkg/RQuantLib/DESCRIPTION	2013-05-31 01:33:55 UTC (rev 330)
@@ -24,8 +24,9 @@
  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.10.0), Rcpp (>= 0.8.7)
+Depends: R (>= 2.10.0), Rcpp (>= 0.8.7), methods
 Suggests: rgl, zoo, RUnit
+Imports: methods, Rcpp
 LinkingTo: Rcpp
 SystemRequirements: QuantLib library (>= 0.9.9) from http://quantlib.org, 
  Boost library from http://www.boost.org

Modified: pkg/RQuantLib/NAMESPACE
===================================================================
--- pkg/RQuantLib/NAMESPACE	2013-05-31 01:32:17 UTC (rev 329)
+++ pkg/RQuantLib/NAMESPACE	2013-05-31 01:33:55 UTC (rev 330)
@@ -1,4 +1,5 @@
-import("Rcpp")
+
+import(Rcpp,methods)
 useDynLib(RQuantLib)
 
 exportPattern("*.default")

Added: pkg/RQuantLib/R/mod.R
===================================================================
--- pkg/RQuantLib/R/mod.R	                        (rev 0)
+++ pkg/RQuantLib/R/mod.R	2013-05-31 01:33:55 UTC (rev 330)
@@ -0,0 +1,3 @@
+
+loadModule("BondsMod", TRUE)
+loadModule("BlackMod", TRUE)

Added: pkg/RQuantLib/src/modules.cpp
===================================================================
--- pkg/RQuantLib/src/modules.cpp	                        (rev 0)
+++ pkg/RQuantLib/src/modules.cpp	2013-05-31 01:33:55 UTC (rev 330)
@@ -0,0 +1,67 @@
+// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
+
+// trying something with Rcpp modules
+
+#include <rquantlib.h>
+
+using namespace QuantLib;
+
+Real BlackFormula(std::string type, Real strike, Real fwd, Real stdDev, Real discount, Real displacement) {
+    if (type=="call")
+        return blackFormula(Option::Call, strike, fwd, stdDev, discount, displacement);
+    else if (type=="put")
+        return blackFormula(Option::Put, strike, fwd, stdDev, discount, displacement);
+    else {
+        Rcpp::stop("Unrecognised option type");
+        return(-42);            // never reached
+    }
+}
+
+Real BlackFormulaImpliedStdDevApproximation(std::string type, Real strike, Real fwd, Real blackPrice,
+                                            Real discount, Real displacement) {
+    if (type=="call")
+        return blackFormulaImpliedStdDevApproximation(Option::Call, strike, fwd, blackPrice, discount, displacement);
+    else if (type=="put")
+        return blackFormulaImpliedStdDevApproximation(Option::Put, strike, fwd, blackPrice, discount, displacement);
+    else {
+        Rcpp::stop("Unrecognised option type");
+        return(-42);            // never reached
+    }
+}
+
+RCPP_MODULE(BlackMod) {
+
+    using namespace Rcpp;
+
+    function("BlackFormula",   			// name of the identifier at the R level
+             &BlackFormula,       		// function pointer to helper function defined above
+             List::create(Named("type")         = "character",
+                          Named("strike")       = "numeric",    // function arguments including default value
+                          Named("fwd")          = "numeric",
+                          Named("stddev")       = "numeric",
+                          Named("discount")     = 1.0,  // cf ql/pricingengines/blackformula.hpp                          
+                          Named("displacement") = 0.0), // cf ql/pricingengines/blackformula.hpp
+             "Black (1976) formula for an option [note that stdev=vol*sqrt(timeToExp)]");
+
+    function("BlackFormulaImpliedStdDevApproximation",   		// name of the identifier at the R level
+             &BlackFormulaImpliedStdDevApproximation,       		// function pointer to helper function defined above
+             List::create(Named("type")         = "character",
+                          Named("strike")       = "numeric",    // function arguments including default value
+                          Named("fwd")          = "numeric",
+                          Named("blackPrice")   = "numeric",
+                          Named("discount")     = 1.0,  // cf ql/pricingengines/blackformula.hpp                          
+                          Named("displacement") = 0.0), // cf ql/pricingengines/blackformula.hpp
+             "Approximated Black 1976 implied standard deviation, i.e. volatility*sqrt(timeToMaturityBlack");
+
+    // also see blackFormulaImpliedStdDev() 
+
+}
+
+
+
+class Bonds;
+RCPP_EXPOSED_CLASS(Bonds)
+RCPP_MODULE(BondsMod) {
+    Rcpp::class_<Bond>("Bond")
+        ;
+}



More information about the Rquantlib-commits mailing list