[R-SIG-Finance] Warning: timeLastNdayInMonth gets Fridays one week off

Enrico Schumann es at enricoschumann.net
Thu Jun 13 07:54:21 CEST 2013


On Wed, 12 Jun 2013, Ilya Kipnis <ilya.kipnis at gmail.com> writes:

> For those of you looking to find the last Fridays in a month (quarter,
> etc.), I just wanted to issue a warning about using the timeLastNdayInMonth
> function.  For instance, run these lines:
>
>  #dates<-seq(as.Date("2010-01-01"),as.Date("2013-04-02"),by="day") test case
>   friDates<-dates[which(weekdays(dates)=="Friday")]
>   buggedLastMonthlyFridays<-unique(timeLastNdayInMonth(friDates,5)) #gives
> one week after the last friday of the month
>
> and one will notice that the dates are often at the beginning of the next
> month.  This is my fix:
>
> buggedLastMonthlyFridays[which(as.numeric(substr(buggedLastMonthlyFridays,9,10))<20)]<-
>
> as.Date(buggedLastMonthlyFridays[which(as.numeric(substr(buggedLastMonthlyFridays,9,10))<20)])-7
>
> It's not exactly pretty, but I hope this helps someone out there.
>
> -Ilya Kipnis
>

I suppose the 'timeLastNdayInMonth' function is from a package?  Then you
should also contact directly the package's maintainer.



-- 
Enrico Schumann
Lucerne, Switzerland
http://enricoschumann.net



More information about the R-SIG-Finance mailing list