Skip to content

holidayNYSE missing some

1 message · Joe W. Byers

#
John Putz wrote:
John,

I wrote this function for the NERC holidays you might have some interest 
in trying.  I also made some suggestions in a previous post in this list 
about this holidayNYSE problem, but did not hear from anyone on the 
feasibility of the suggestions.  This is also a problem with other US 
holidays, not just NYSE.  I would like to correct this for all the 
holiday functions but I do not want to have to overload the fCalendar 
functions every time I load fCalendar.

here is my holidayNERC()

#Method name: holidayNERC
#Written by: Joe W. Byers
#Creation Date:
#Modification Date:           Modifier:
#Inputs:  vector of Years
#Returns: holidays dates
#Example:

#*******************************************************************************
#Required Libraries

#*******************************************************************************
#Input and Temporary variables

#Holidays for the North American Energy Reliability Council (data from 
http://www.nerc.com/~oc/offpeaks.html):
#    * Saturdays
#    * Sundays
#    * New Year's Day, January 1st (possibly moved to Monday if actually 
on Sunday)
#    * Memorial Day, last Monday in May
#    * Independence Day, July 4th (moved to Monday if Sunday)
#    * Labor Day, first Monday in September
#    * Thanksgiving Day, fourth Thursday in November
#    * Christmas, December 25th (moved to Monday if Sunday)

holidayNERC<-function (year = 
currentYear,West=F,FinCenter='America/NewYork')
{
     holidays = NULL
     for (y in year) {
       holidays = c(holidays, as.character(USNewYearsDay(y)))
       holidays = c(holidays, as.character(USIndependenceDay(y)))
       holidays = c(holidays, as.character(USThanksgivingDay(y)))
       holidays = c(holidays, as.character(USChristmasDay(y)))
       holidays = c(holidays, as.character(USLaborDay(y)))
       holidays = c(holidays, as.character(USMemorialDay(y)))
     }
     holidays = sort(holidays)
     ans = timeDate(holidays)
     ans = ans + as.integer(as.POSIXlt(ans at Data)$wday == 0) *
         24 * 3600
     posix = as.POSIXlt(ans at Data)
     y = posix$year + 1900
     m = posix$mon + 1
     lastday = as.POSIXlt((timeCalendar(y = y + (m + 1)%/%13,
         m = m + 1 - (m + 1)%/%13 * 12, d = 1) - 24 * 3600)@Data)$mday
     ExceptOnLastFriday = timeDate(as.character(.last.of.nday(year = y,
         month = m, lastday = lastday, nday = 5)))
     ans = ans - as.integer(ans >= timeDate("1959-07-03") & 
as.POSIXlt(ans at Data)$wday ==
         0 & ans != ExceptOnLastFriday) * 24 * 3600
     if (West==F) {
       ans = ans[!(as.POSIXlt(ans at Data)$wday == 0 | 
as.POSIXlt(ans at Data)$wday ==
         6)]
     } else {
       ans = ans[!as.POSIXlt(ans at Data)$wday == 0]
       ans = ans[!(as.POSIXlt(ans at Data)$wday == 6 & 
!as.POSIXlt(ans at Data)$mon ==
         6)]
     }
     ans at FinCenter = FinCenter
     ans
}