Using RQuantLib FixedRateBond function when rates can be negative

久未见 提交于 2019-12-12 02:18:47

问题


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

回答1:


There might be two different issues at play.

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.

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

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

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.



来源:https://stackoverflow.com/questions/26592547/using-rquantlib-fixedratebond-function-when-rates-can-be-negative

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!