当利率可能为负时使用RQuantLib FixedRateBond函数 [英] Using RQuantLib FixedRateBond function when rates can be negative

查看:152
本文介绍了当利率可能为负时使用RQuantLib FixedRateBond函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用RQuantLib为债券定价,但是我使用的版本无法在负利率下使用.请参见下面的示例.有人知道解决方法吗?我以为QuantLib可以接受负利率?

I am trying to use RQuantLib to price bonds but the version I am using will not work with negative interest rates. See example below. Does anyone know a work around? I thought that QuantLib was able to accept negative rates?

require(RQuantLib)

today <- as.Date("2014-10-27")
setEvaluationDate(today)

times <- seq(today+2,as.Date("2024-12-30"),by=1)
maturity <- yearFraction(rep(today,length(times)),times,rep(2,length(times)))

zerorates <- seq(-.0001,.01,length.out=length(maturity))

curve <- list(table = data.frame(date=times, zeroRates=zerorates))
attr(curve,"class") <- "DiscountCurve"

FixedRateBond(
bond =list(issueDate=as.Date("2005-11-24"), maturityDate=as.Date("2016-01-03")),
rates=.035, discountCurve= curve,
dateparams=list(settlementDays=2,dayCounter=2,period=1))

Error: invalid value (-0.0001) at index 0

sessionInfo()


R version 3.1.1 (2014-07-10)
Platform: i386-w64-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252     LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] RQuantLib_0.3.12 rJava_0.9-6     

loaded via a namespace (and not attached):
[1] Rcpp_0.11.3 tools_3.1.1

推荐答案

可能有两个不同的问题在起作用.

There might be two different issues at play.

在1.2版及更高版本中,默认情况下,QuantLib用来拒绝负利率.在1.2.1版中,行为已更改,默认设置为接受负利率.

Up to and including version 1.2, QuantLib used to reject negative rates by default. In version 1.2.1, the behavior changed and the default is now to accept negative rates.

如果这是问题,则允许它们安装在RQuantLib中的唯一方法是重新编译该库.从1.0开始,所有版本的QuantLib都是向后兼容的,因此您可以下载较新的版本并将其替换为RQuantLib中使用的版本(也可能会解决一些错误).否则,您可以保留版本1.0.1并启用负费率;否则,您可以保留负费率.在基于自动工具的版本(使用MinGW的Linux,Mac OS X和Windows)中,您可以通过运行来实现

If this were the problem, the only way to allow them in your RQuantLib installation would be to recompile the library. All versions of QuantLib since 1.0 are backward-compatible, so you can download a more recent version and drop it in as a replacement for the one used in RQuantLib (possibly getting a few bug fixes out of the deal, too). Otherwise, you can keep version 1.0.1 and enable negative rates; in an autotools-based build (Linux, Mac OS X and Windows using MinGW) you do it by running

./configure --enable-negative-rates

在其他Windows编译器(Visual C ++,Dev-C ++)上,您必须编辑ql/userconfig.hpp并取消注释相关的#define.

while on other Windows compilers (Visual C++, Dev-C++) you'll have to edit ql/userconfig.hpp and uncomment the relevant #define.

但是,您遇到的错误(不是很全面,但也很不常见,所以grep会找到它)来自处理对数插值的部分代码反而.这表明该库已在启用负费率的情况下进行了编译(尽管其他人将不得不确认这一点),并且也未因此拒绝该费率.这可能是个好消息:这意味着,如果RQuantLib允许您选择其他插值,则无需重新编译就可以使其工作.再说一次,我不知道该怎么做.如果找到答案,请回答您自己的问题,并接受您的回答作为正确的答案.

However, the error you're getting (not very informative, but fortunately not very common either, so grep will locate it) comes from a part of the code that deals with log interpolation instead. This suggests that the library was already compiled with negative rates enabled (although someone else will have to confirm this) and that the rates weren't rejected as such. This might be good news: it means that, if RQuantLib allows you to choose a different interpolation, you'll be able to make it work without having to recompile. Again, I have no idea how this can be done; if you find out, please answer your own question and accept your answer as the correct one.

这篇关于当利率可能为负时使用RQuantLib FixedRateBond函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆