[R-SIG-Finance] RQuantLib possible bug in yearFraction and dayCount

Guillaume Horel guillaume.horel at gmail.com
Fri Jun 8 00:07:02 CEST 2012


Hello,

I'm trying to use the yearFraction function from the RQuantLib
library. However the function behaves strangely. This small example
should make the problem clear:

> yearFraction(Sys.Date(),Sys.Date()+10,0)
> dt <- yearFraction(Sys.Date(),Sys.Date()+10,0)
> dt
[1] 0.02777778
> dtvec <- yearFraction(Sys.Date(),Sys.Date()+10:20,0)
> dtvec
[1] 0.02777778

The first issue is that just calling yearFraction alone doesn't return
anything. However the output is just hidden, because if I store the
result to a variable it works fine.
However this trick doesn't work if you want to apply it to a vector as
shown with the dtvec variable.

This is the output from example(yearFraction), which shows that
dayCount also exhibits the same issue (no output).

yrFrct>   startDates <- seq(from=as.Date("2009-04-07"),
to=as.Date("2009-04-14"),by=1)

yrFrct>   endDates <- seq(from=as.Date("2009-11-07"),
to=as.Date("2009-11-14"), by=1)

yrFrct>   dayCounters <- c(0,1,2,3,4,5,6,1)

yrFrct>   dayCount(startDates, endDates, dayCounters)

yrFrct>   yearFraction(startDates, endDates, dayCounters)


Can anybody else reproduce this? I'm trying to figure out if there is
something wrong with my setup or if it's an actual bug in
yearFraction.

Thanks,
Guillaume



More information about the R-SIG-Finance mailing list