--- /dev/null
+## File: createCalendar.r
+## Description: Create the calendar transitions to be used on KWF predictor
+## Author: jc @ September 2015
+
+## Function: irishCalendar
+## Description: Create the calendar with day of the week and daytype.
+## (It is the first step, then we need to obtain the transitions)
+irishCalendar <- function(from, to){
+ require(timeDate)
+ y0 <- as.character(substr(from, 1, 4))
+ y1 <- as.character(substr(to, 1, 4))
+ years <- y0:y1
+ IRholidays <- c("NewYearsDay",
+ #saint patrick
+ "EasterMonday",
+ "GBMayDay", # may day
+ #june holiday
+ "GBSummerBankHoliday", # august holiday
+ #october holiday
+ "ChristmasDay"
+ #, st stephen day
+ )
+
+
+ jf <- holiday(year = years, Holiday = IRholidays)
+ jf <- sort(unique(jf))
+ dts <- timeSequence(from = paste(y0, '01', '01', sep = '-'),
+ to = paste(y1, '12', '31', sep = '-'))
+ wday <- dayOfWeek(dts)
+ wdayf <- unname(wday)
+ for(d in 1:length(wdayf)){
+ if(d == 1) fpos <- 1
+ if(dts[d] == jf[fpos]){
+ wdayf[d] <- "Hol"
+ if(fpos < length(jf)) fpos <- fpos + 1
+ }
+ }
+
+ res <- data.frame(dow = wday, daytype = wdayf)
+ i0 <- which(rownames(res) == from)
+ i1 <- which(rownames(res) == to)
+
+ return(res[i0:i1, ])
+}
+
+
+# Call irishCalendar to create the calendar.
+myCal <- irishCalendar(from="2011-01-01", to= "2013-12-31")
+n <- nrow(myCal)
+
+# Obtention of the transitions
+gr <- paste(myCal$daytype[1:(n - 1)], myCal$daytype[2:n], sep = '_')
+gr[gr == "Hol_Hol"] <- "Sun_Hol"
+myCal$gr <- c(gr, "Sat_Sun")
+
+# Write output to a file
+# write.table(file = "calendar_ir.txt", myCal)
+