packages feed

hquantlib-time 0.0.5.1 → 0.0.5.2

raw patch · 4 files changed

+94/−83 lines, 4 filesdep ~timePVP ok

version bump matches the API change (PVP)

Dependency ranges changed: time

API changes (from Hackage documentation)

Files

hquantlib-time.cabal view
@@ -1,5 +1,5 @@ name:           hquantlib-time-version:        0.0.5.1+version:        0.0.5.2 license:        LGPL license-file:   LICENSE author:         Pavel Ryzhov@@ -10,7 +10,7 @@ build-type:     Simple stability:      alpha homepage:       http://github.com/paulrzcz/hquantlib-time.git-cabal-version:  >= 1.18+cabal-version:  1.18.0  source-repository head         type:           git@@ -19,7 +19,7 @@ source-repository this         type:           git         location:       https://github.com/paulrzcz/hquantlib-time.git-        tag:            0.0.5.1+        tag:            0.0.5.2  flag optimize         description : Enable optimizations for library and benchmarks@@ -34,7 +34,7 @@          build-depends:                         base                    >3              && <5,-                        time                    >= 1.9.0.0      && < 1.10.0.0+                        time                    >= 1.4.0.0      && < 1.12.0.0          hs-source-dirs: src         ghc-options:    -Wall
src/QuantLib/Time.hs view
@@ -1,8 +1,8 @@ module QuantLib.Time-        ( module QuantLib.Time.Date-        , module QuantLib.Time.DayCounter-        ) where+  ( module QuantLib.Time.Date,+    module QuantLib.Time.DayCounter,+  )+where  import QuantLib.Time.Date import QuantLib.Time.DayCounter-
src/QuantLib/Time/Date.hs view
@@ -1,20 +1,21 @@ module QuantLib.Time.Date-        ( module QuantLib.Time.Date-        , DayOfWeek(..)-        ) where+  ( module QuantLib.Time.Date,+    DayOfWeek (..),+  )+where -import Data.Time-import Data.Time.Calendar.WeekDate+import Data.Time.Calendar (Day (..), DayOfWeek (..), addDays, toGregorian)+import Data.Time.Calendar.WeekDate (toWeekDate) -{- | Business Day conventions- - These conventions specify the algorithm used to adjust a date in case it is not a valid business day.- -}-data BusinessDayConvention = Following -        | ModifiedFollowing -        | Preceding-        | ModifiedPreceding-        | Unadjusted-        deriving (Show, Eq, Enum)+-- | Business Day conventions+-- - These conventions specify the algorithm used to adjust a date in case it is not a valid business day.+data BusinessDayConvention+  = Following+  | ModifiedFollowing+  | Preceding+  | ModifiedPreceding+  | Unadjusted+  deriving (Show, Eq, Enum)  -- -- | Week days -- data WeekDay = Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday@@ -25,37 +26,43 @@  -- | Defines a holidays for given calendar. Corresponds to calendar class in QuantLib class Holiday m where-        isHoliday :: m->(Integer, Int, Int)->Bool-        -        isBusinessDay :: m->Date->Bool-        isBusinessDay m d = not (isHoliday m $ toGregorian d)+  isHoliday :: m -> (Integer, Int, Int) -> Bool -        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)+  isBusinessDay :: m -> Date -> Bool+  isBusinessDay m d = not (isHoliday m $ toGregorian d) --- | Gets a week day -getWeekDay :: Date->DayOfWeek-getWeekDay d   = toEnum (weekDay - 1)-        where   (_, _, weekDay) = toWeekDate 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) +-- | Gets a week day+getWeekDay :: Date -> DayOfWeek+getWeekDay d = toEnum (weekDay - 1)+  where+    (_, _, weekDay) = toWeekDate d+ -- | Generate a list of all dates inbetween-getDaysBetween ::  (Day, Day) -> [Day]+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+  where+    generator date x+      | date < td = generator nextDate (nextDate : x)+      | otherwise = x+      where+        nextDate = addDays 1 date  -- | Checks if the day is a weekend, i.e. Saturday or Sunday-isWeekEnd :: Date->Bool-isWeekEnd d     = (weekday == Saturday) || (weekday == Sunday)-        where   weekday = getWeekDay d+isWeekEnd :: Date -> Bool+isWeekEnd d = (weekday == Saturday) || (weekday == Sunday)+  where+    weekday = getWeekDay d  -- | Gets the next working day-getNextBusinessDay :: Holiday a => a->Date->Date+getNextBusinessDay :: Holiday a => a -> Date -> Date getNextBusinessDay m d-        | isBusinessDay m nextDay       = nextDay-        | otherwise                     = getNextBusinessDay m nextDay-        where   nextDay = addDays 1 d+  | isBusinessDay m nextDay = nextDay+  | otherwise = getNextBusinessDay m nextDay+  where+    nextDay = addDays 1 d
src/QuantLib/Time/DayCounter.hs view
@@ -1,19 +1,22 @@ module QuantLib.Time.DayCounter-        ( module QuantLib.Time.DayCounter-        ) where+  ( module QuantLib.Time.DayCounter,+  )+where -import QuantLib.Time.Date-import Data.Time.Calendar+import Data.Time.Calendar (Day (..), toGregorian)+import QuantLib.Time.Date (Date)  -- | Day counter type class class DayCounter m where-        -- | Name of day counter-        dcName          :: m->String-        -- | Number of business days inbetween-        dcCount         :: m->Date->Date->Int-        -- | Year fraction-        dcYearFraction  :: m->Date->Date->Double+  -- | Name of day counter+  dcName :: m -> String +  -- | Number of business days inbetween+  dcCount :: m -> Date -> Date -> Int++  -- | Year fraction+  dcYearFraction :: m -> Date -> Date -> Double+ {- data SimpleDayCounter = SimpleDayCounter @@ -27,34 +30,35 @@ data Thirty360 = ThirtyUSA | ThirtyEuropean | ThirtyItalian  instance DayCounter Thirty360 where-        dcName ThirtyUSA        = "Thirty USA"-        dcName ThirtyEuropean   = "Thirty Euro"-        dcName ThirtyItalian    = "Thirty Italian"--        dcYearFraction  dc fromDate toDate = fromIntegral (dcCount dc fromDate toDate) / 360.0--        dcCount ThirtyUSA fd td = 360*(yy2-yy1) + 30*(mm2-mm1-1) + max 0 (30-dd1) + min 30 dd2-                where   (yy1, mm1, dd1) = intGregorian fd-                        (yy2, m2, d2)   = intGregorian td-                        (dd2, mm2)      = adjust dd1 d2 m2-                        adjust x1 x2 z2-                                | x2 == 31 && x1 < 30   = (1, z2+1)-                                | otherwise             = (x2, z2)-+  dcName ThirtyUSA = "Thirty USA"+  dcName ThirtyEuropean = "Thirty Euro"+  dcName ThirtyItalian = "Thirty Italian" -        dcCount ThirtyEuropean fd td = 360*(yy2-yy1) + 30*(m2-m1-1) + max 0 (30-d1) + min 30 d2-                where   (yy1, m1, d1)    = intGregorian fd-                        (yy2, m2, d2)    = intGregorian td+  dcYearFraction dc fromDate toDate = fromIntegral (dcCount dc fromDate toDate) / 360.0 -        dcCount ThirtyItalian fd td = 360*(yy2-yy1) + 30*(mm2-mm1-1) + max 0 (30-dd1) + min 30 dd2-                where   (yy1, mm1, d1)   = intGregorian fd-                        (yy2, mm2, d2)   = intGregorian td-                        dd1              = adjust d1 mm1-                        dd2              = adjust d2 mm2-                        adjust x1 z1-                                | z1 == 2 && x1 > 27    = 30-                                | otherwise             = x1+  dcCount ThirtyUSA fd td = 360 * (yy2 - yy1) + 30 * (mm2 - mm1 -1) + max 0 (30 - dd1) + min 30 dd2+    where+      (yy1, mm1, dd1) = intGregorian fd+      (yy2, m2, d2) = intGregorian td+      (dd2, mm2) = adjust dd1 d2 m2+      adjust x1 x2 z2+        | x2 == 31 && x1 < 30 = (1, z2 + 1)+        | otherwise = (x2, z2)+  dcCount ThirtyEuropean fd td = 360 * (yy2 - yy1) + 30 * (m2 - m1 -1) + max 0 (30 - d1) + min 30 d2+    where+      (yy1, m1, d1) = intGregorian fd+      (yy2, m2, d2) = intGregorian td+  dcCount ThirtyItalian fd td = 360 * (yy2 - yy1) + 30 * (mm2 - mm1 -1) + max 0 (30 - dd1) + min 30 dd2+    where+      (yy1, mm1, d1) = intGregorian fd+      (yy2, mm2, d2) = intGregorian td+      dd1 = adjust d1 mm1+      dd2 = adjust d2 mm2+      adjust x1 z1+        | z1 == 2 && x1 > 27 = 30+        | otherwise = x1 -intGregorian ::  Day -> (Int, Int, Int)+intGregorian :: Day -> (Int, Int, Int) intGregorian date = (fromIntegral y, m, d)-        where   (y, m, d) = toGregorian date +  where+    (y, m, d) = toGregorian date