module QuantLib.Time.Date
( module QuantLib.Time.Date
) where
import Data.Time
import Data.Time.Calendar.WeekDate
data BusinessDayConvention = Following
| ModifiedFollowing
| Preceding
| ModifiedPreceding
| Unadjusted
deriving (Show, Eq, Enum)
data WeekDay = Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday
deriving (Show, Eq, Enum)
type Date = Day
class Holiday m where
isHoliday :: m->(Integer, Int, Int)->Bool
isBusinessDay :: m->Date->Bool
isBusinessDay m d = not (isHoliday m $ toGregorian d)
hBusinessDayBetween :: m->(Date, Date)->Int
hBusinessDayBetween m (fd, td) = foldl countDays 0 listOfDates
where countDays counter x = counter + fromEnum (isBusinessDay m x)
listOfDates = getDaysBetween (fd, td)
getWeekDay :: Date->WeekDay
getWeekDay d = toEnum (weekDay 1)
where (_, _, weekDay) = toWeekDate d
getDaysBetween :: (Day, Day) -> [Day]
getDaysBetween (fd, td) = reverse $ generator fd []
where generator date x
| date < td = generator nextDate (nextDate : x)
| otherwise = x
where nextDate = addDays 1 date
isWeekEnd :: Date->Bool
isWeekEnd d = (weekday == Saturday) || (weekday == Sunday)
where weekday = getWeekDay d
getNextBusinessDay :: Holiday a => a->Date->Date
getNextBusinessDay m d
| isBusinessDay m nextDay = nextDay
| otherwise = getNextBusinessDay m nextDay
where nextDay = addDays 1 d