[R-SIG-Finance] RQuantLib possible bug in yearFraction and dayCount
Guillaume Horel
guillaume.horel at gmail.com
Fri Jun 8 16:52:34 CEST 2012
Thanks, it works here too. The reason was indeed that I only provided
one dayCounter.
On Fri, Jun 8, 2012 at 10:44 AM, R. Michael Weylandt
<michael.weylandt at gmail.com> wrote:
> Well, I don't really know what you're doing wrong: it works just fine
> to give me a vector so please provide a reproducible example of it not
> doing so:
>
> # From the examples
> startDates <- structure(c(14341, 14342, 14343, 14344, 14345, 14346, 14347,
> 14348), class = "Date")
>
> endDates structure(c(14555, 14556, 14557, 14558, 14559, 14560, 14561,
> 14562), class = "Date")
>
> dayCounters <- c(0,1,2,3,4,5,6,1)
>
> print(yearFraction(startDates, endDates, dayCounters))
> print(yearFraction(startDates[1:4], endDates[rep(1,4)], rep(0, 4)))
>
> I haven't really played with it, but it seems that you'll only get as
> many outputs as you provide "dayCounter"s so that might be part of
> your problem.
>
> Best,
> Michael
>
> On Fri, Jun 8, 2012 at 9:38 AM, Guillaume Horel
> <guillaume.horel at gmail.com> wrote:
>> 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