[R-SIG-Finance] RQuantLib possible bug in yearFraction and dayCount
Guillaume Horel
guillaume.horel at gmail.com
Fri Jun 8 16:38:46 CEST 2012
Ok thanks, this makes sense. Any way to make it work with a vector?
The example from the doc with startDates, endDates makes clear that it
should return a vector but I can only get a single value.
Guillaume
On Thu, Jun 7, 2012 at 10:57 PM, R. Michael Weylandt
<michael.weylandt at gmail.com> wrote:
> Hmmmm... looking at the source code, you see the return value is
> wrapped in invisible() so it won't auto-print but it is returned
> --it's not a bug, but I don't know exactly why Dirk would have done
> that. There are other functions that return invisibly (e.g., most plot
> functions) but those are usually side-effect functions.
>
> The invisible() was added not too long ago in r322 it seems, but the
> log doesn't quite explain why. Perhaps Dirk can chime in?
>
> Michael
>
> On Thu, Jun 7, 2012 at 5:07 PM, Guillaume Horel
> <guillaume.horel at gmail.com> wrote:
>> 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
>>
>> _______________________________________________
>> R-SIG-Finance at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>> -- Subscriber-posting only. If you want to post, subscribe first.
>> -- Also note that this is not the r-help list where general R questions should go.
More information about the R-SIG-Finance
mailing list