[R-SIG-Finance] holidayNYSE missing some
Joe W. Byers
ecjbosu at aol.com
Sat Dec 8 06:26:29 CET 2007
John Putz wrote:
> The correct behavior is to shift the holiday to Friday (from Sat) or to Monday (from Sun). I'm not actually using this for NYSE holidays but for power industry holidays and made a version to handle those changes as well as some other idiosyncracies. Thanks for the suggestion though.
>
> Message: 5
> Date: Thu, 6 Sep 2007 16:51:49 -0400
> From: "Charles Naylor" <Charles.Naylor at nikkoam.com>
> Subject: Re: [R-SIG-Finance] holidayNYSE missing some
> To: <r-sig-finance at stat.math.ethz.ch>
> Message-ID:
> <A4678959B3D65D449266DE8D3825E0821F7F47 at nycmsg501.nikkoam.com>
> Content-Type: text/plain; charset="us-ascii"
>
> This is deliberate behavior. If you check the code, the third-to-last
> line is as follows:
> ans = ans[!(as.POSIXlt(ans at Data)$wday == 0 |
> as.POSIXlt(ans at Data)$wday== 6)]
>
>
> You could make an alternate version of holidayNYSE that omits this line,
> if you like.
>
> -CN
>
> Charles Naylor
> Assistant Vice President
> Global Dynamic Asset Allocation Group
> Nikko Alternative Asset Management, Inc.
> 535 Madison Avenue, Suite 2500
> New York, NY 10022
> T: 212.610.6158
> F: 212.610.6148
> E: charles.naylor at nikkoam.com
>
> -----Original Message-----
> From: r-sig-finance-bounces at stat.math.ethz.ch
> [mailto:r-sig-finance-bounces at stat.math.ethz.ch] On Behalf Of John Putz
> Sent: Thursday, September 06, 2007 4:44 PM
> To: r-sig-finance at stat.math.ethz.ch
> Subject: [R-SIG-Finance] holidayNYSE missing some
>
> Hello,
>
> I'm not sure if this is the correct list to email this too, but it
> appears that at least in R 2.5.0 that the holidayNYSE function in
> fCalendar does not include holidays that occur on Saturday. E.g.
> holidayNYSE(2004) does not list Christmas.
>
> Thanks, John.
> [[alternative HTML version deleted]]
>
>
>
> email: johnputz3655 at yahoo.com
> home: 206-632-6522
> cell: 206-910-5229
> [[alternative HTML version deleted]]
>
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
}
More information about the R-SIG-Finance
mailing list