【发布时间】:2014-03-14 19:34:31
【问题描述】:
初步步骤
QuantLib 与Boost 一起安装,并按照Microsoft Visual C++ 2010 中的these 指令构建;测试代码继续进行,没有任何问题。
将 R 与以下示例代码一起使用得到了预期的结果:
install.packages("Rcpp")
library(Rcpp)
cppFunction('
int add(int x, int y, int z) {
int sum = x + y + z;
return sum;
}'
)
add(1, 2, 3)
# > add(1, 2, 3)
# [1] 6
由于使用单独的C++文件,下面的例子
#include <Rcpp.h>
using namespace Rcpp;
// Below is a simple example of exporting a C++ function to R. You can
// source this function into an R session using the Rcpp::sourceCpp
// function (or via the Source button on the editor toolbar)
// For more on using Rcpp click the Help button on the editor toolbar
// [[Rcpp::export]]
int timesTwo(int x) {
return x * 2;
}
R 中的结果成功
> timesTwo(7)
[1] 14
我想一切都很好。
我的问题
如果我的设置正确,我的问题是:假设我的QuantLib-vc100-mt-gd.lib 目标文件库在C:\DevTools\QuantLib-1.3\lib 中,如果从R 调用,我应该怎么做才能使下面的代码正常工作?
#include <ql/quantlib.hpp>
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
double timesTwo(double x) {
QuantLib::Calendar myCal = QuantLib::UnitedKingdom();
QuantLib::Date newYearsEve(31, QuantLib::Dec, 2008);
QuantLib::Rate zc3mQuote = x;
return zc3mQuote * 2;
}
【问题讨论】: