简体   繁体   English

RQuantlib 和 Mac OS X 10.8.2

[英]RQuantlib and Mac OS X 10.8.2

I'm a total newbie in Mac OS X, R and C++.我是 Mac OS X、R 和 C++ 的新手。 Sound like a good mix, doesn't it?听起来不错,不是吗?

I have the need to use RQuantLib, because I want to use some pricing functions part of the QuantLib package inside R, all on a Mac OS X-powered environment.我需要使用 RQuantLib,因为我想在 R 中使用 QuantLib 包的一些定价函数部分,所有这些都在 Mac OS X 驱动的环境中。

I've correctly installed QuantLib.我已经正确安装了 QuantLib。 I've already asked to the official QuantLib mailing list, and together we seem to have reached the conclusion that the problems I'm encountering are not related to my QuantLib installation, which seems ok and correctly configured.我已经询问了官方 QuantLib 邮件列表,我们似乎已经得出结论,我遇到的问题与我的 QuantLib 安装无关,这似乎没问题且配置正确。

So, I turned to R to try and solve the problem.所以,我转向 R 来尝试解决这个问题。 Whenever I try to run ZeroCouponBond from within R, copying and pasting the first example provided with the official documentation, I get the following error:每当我尝试从 R 中运行 ZeroCouponBond,复制并粘贴官方文档提供的第一个示例时,我都会收到以下错误:

"Error in DiscountCurve.default(discountCurve.param, list(flat = 0.05)) : 
cannot find function errorOccured"

Now, I would rule any syntax.related problem out, since I'm copying the very same example present in the official help.现在,我将排除任何与语法相关的问题,因为我正在复制官方帮助中的相同示例。

I don't know what I did wrong, but I know I need to find a solution at all costs.我不知道我做错了什么,但我知道我需要不惜一切代价找到解决方案。 I've installed Rcpp, and the configuration seems really ok.我已经安装了 Rcpp,配置看起来真的没问题。 Just one question I was not able to find an answert to: in my understanding, RQuantLib basically acts as a link between QuantLib and R. If that's correct, how can I tell RQuantLib where to look to find libQuantLib.a, that is, the compiled library resulting from the "make && sudo make install" commands performed while installing QuantLib itself?只有一个我无法找到答案的问题:在我的理解中,RQuantLib 基本上充当了 QuantLib 和 R 之间的链接。如果这是正确的,我怎么能告诉 RQuantLib 在哪里寻找 libQuantLib.a,即由安装 QuantLib 本身时执行的“make && sudo make install”命令产生的编译库?

Right, so, I've finally managed to get it to work.是的,所以,我终于设法让它工作了。

First of all, I would like to say that things would have been much easier if a thorough, step-by-step installation procedure had been provided.首先,我想说,如果提供了一个彻底的、逐步的安装过程,事情会容易得多。 I acknowledge I'm a total newbie, but I think other people approaching to R for the first time might encounter difficulties similar to those I had to overcome.我承认我是个新手,但我认为其他第一次接触 R 的人可能会遇到类似于我必须克服的困难。

Anyway, this is what I did:无论如何,这就是我所做的:

  • I've downloaded the .tar.gz source packages for both Rcpp and RQuantLib from cran.r-project.org我已经从 cran.r-project.org 下载了RcppRQuantLib的 .tar.gz
  • I've compiled them installing them from within the R environment.我已经编译它们并从 R 环境中安装它们。 This is where I was making a mistake.这是我犯错误的地方。 Indeed, I was trying to compile them by invoking the configure installation script from the terminal;事实上,我试图通过从终端调用configure安装脚本来编译它们; however, as Dirk said, the config script looks for QuantLib's quantlib-config script, and I didn't know the correct syntax to tell the configure script the correct path to QuantLib.然而,正如 Dirk 所说, config脚本寻找 QuantLib 的quantlib-config脚本,我不知道告诉configure脚本正确的 QuantLib 路径的正确语法。 Executing the procedure from R (by just installing the package) sorts out any problem, as all the dependencies are correctly located and loaded从 R 执行程序(只需安装包)可以解决任何问题,因为所有依赖项都已正确定位和加载

So, that's pretty much it: just install the .tar.gz source package as you would do with the binary version, and everything should work ok.所以,差不多就是这样:只需像使用二进制版本一样安装 .tar.gz包,一切都应该正常工作。

Of course, I'm still curious to understand:当然,我还是很好奇理解:

  • If it is possible to compile Rcpp and RQuantLib from the terminal;如果可以从终端编译Rcpp和RQuantLib; and
  • Why the binary version for Mac OS X will not work on my system, ie: why do I have to compile starting from the source code?为什么 Mac OS X 的二进制版本在我的系统上不起作用,即:为什么我必须从源代码开始编译?

Thank you so much to anyone willing to answer my (probably naive and silly) questions.非常感谢任何愿意回答我(可能是幼稚和愚蠢的)问题的人。 I'm eager to understand a bit more!我很想多了解一点!

Thanks!谢谢!

The RQuantLib package uses a tool called configure which determines the patch at package build-time. RQuantLib 包使用名为configure的工具在包构建时确定补丁。 It looks for the script quantlib-config from which it learns about the location of libQuantLib.a .它查找脚本quantlib-config ,从中了解libQuantLib.a的位置。

First, install boost ( brew install boost ) and, secondly, Quantlib (currently at 1.7.1) by following instructions at http://quantlib.org/install/macosx.shtml :首先,按照http://quantlib.org/install/macosx.shtml 上的说明安装 boost( brew install boost ),然后brew install boost Quantlib(目前为 1.7.1):

cd QuantLib-1.x.y
./configure --enable-static --with-boost-include=/opt/local/include/ \
            --with-boost-lib=/opt/local/lib/ --prefix=/opt/local/
make && sudo make install

It takes some time (~1 hour) for make . make需要一些时间(~1 小时)。

Then in R or Rstudio , install packages Rcpp and RQuantlib .然后在RRstudio ,安装包RcppRQuantlib The later requires type="source" since only source package is available.后者需要type="source"因为只有源包可用。

At this point, you should be able to use RQuantlib .此时,您应该能够使用RQuantlib The American Option value (SPY as of 4/1/2016, maturity 7/15/2016) can be calculated in R as美式期权价值(SPY 截至 4/1/2016,到期日 7/15/2016)可以在R中计算为

AmericanOption("put", strike=206, volatility=0.1525, underlying = 206.92, 0.021, 0.003, 73/252, engine="CrankNicolson")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM