packages feed

hquantlib-time 0.1.0 → 0.1.1

raw patch · 6 files changed

+105/−100 lines, 6 filesdep ~timePVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: time

API changes (from Hackage documentation)

- QuantLib.Time.Date: ModifiedJulianDay :: Integer -> Day
- QuantLib.Time.Date: [toModifiedJulianDay] :: Day -> Integer
- QuantLib.Time.Date: newtype () => Day
+ QuantLib.Time.Date: Friday :: DayOfWeek
+ QuantLib.Time.Date: Monday :: DayOfWeek
+ QuantLib.Time.Date: Saturday :: DayOfWeek
+ QuantLib.Time.Date: Sunday :: DayOfWeek
+ QuantLib.Time.Date: Thursday :: DayOfWeek
+ QuantLib.Time.Date: Tuesday :: DayOfWeek
+ QuantLib.Time.Date: Wednesday :: DayOfWeek
+ QuantLib.Time.Date: data () => DayOfWeek
+ QuantLib.Time.Date: getWeekDay :: Date -> DayOfWeek
+ QuantLib.Time.Date: type Date = Day
- QuantLib.Time.Date: getNextBusinessDay :: Holiday a => a -> Day -> Day
+ QuantLib.Time.Date: getNextBusinessDay :: Holiday a => a -> Date -> Date
- QuantLib.Time.Date: hBusinessDayBetween :: Holiday m => m -> (Day, Day) -> Int
+ QuantLib.Time.Date: hBusinessDayBetween :: Holiday m => m -> (Date, Date) -> Int
- QuantLib.Time.Date: isBusinessDay :: Holiday m => m -> Day -> Bool
+ QuantLib.Time.Date: isBusinessDay :: Holiday m => m -> Date -> Bool
- QuantLib.Time.Date: isWeekEnd :: Day -> Bool
+ QuantLib.Time.Date: isWeekEnd :: Date -> Bool
- QuantLib.Time.DayCounter: dcCount :: DayCounter m => m -> Day -> Day -> Int
+ QuantLib.Time.DayCounter: dcCount :: DayCounter m => m -> Date -> Date -> Int
- QuantLib.Time.DayCounter: dcYearFraction :: DayCounter m => m -> Day -> Day -> Double
+ QuantLib.Time.DayCounter: dcYearFraction :: DayCounter m => m -> Date -> Date -> Double

Files

− CHANGELOG.md
@@ -1,8 +0,0 @@-### 0.1.0-* Migrated to GHC 9.4.8.-* Upgraded the dependencies to more recent versions.-* Removed obsolete definitions as they are now in [time library](https://hackage.haskell.org/package/time).-* Upgraded to Cabal 3.0.--### 0.0.4.1-* I don't remember what was changed here
− README.md
@@ -1,2 +0,0 @@-# hquantlib-time-Separated Time module from HQuantlib
hquantlib-time.cabal view
@@ -1,7 +1,6 @@-cabal-version:  3.0 name:           hquantlib-time-version:        0.1.0-license:        LGPL-3.0-or-later+version:        0.1.1+license:        LGPL license-file:   LICENSE author:         Pavel Ryzhov maintainer:     Pavel Ryzhov <pavel.ryzhov@gmail.com>@@ -9,12 +8,9 @@ synopsis:       HQuantLib Time is a business calendar functions extracted from HQuantLib description:    HQuantLib is intended to be a functional style port of QuantLib (http://quantlib.org) build-type:     Simple-stability:      provisional+stability:      alpha homepage:       http://github.com/paulrzcz/hquantlib-time.git-extra-doc-files:-        README.md-        CHANGELOG.md-tested-with:    GHC == 9.4.8+cabal-version:  1.18.0  source-repository head         type:           git@@ -23,7 +19,7 @@ source-repository this         type:           git         location:       https://github.com/paulrzcz/hquantlib-time.git-        tag:            0.1.0+        tag:            0.1.1  flag optimize         description : Enable optimizations for library and benchmarks@@ -38,9 +34,9 @@          build-depends:                         base                    >3              && <5,-                        time                    >= 1.12.2       && < 1.13        +                        time                    >= 1.4.0.0      && < 1.15.0.0          hs-source-dirs: src         ghc-options:    -Wall         if flag(optimize)-                ghc-options: -funbox-strict-fields -fspec-constr -fdicts-cheap+                ghc-options: -funbox-strict-fields -O2 -fspec-constr -fdicts-cheap
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,53 +1,68 @@ module QuantLib.Time.Date-        ( BusinessDayConvention(..)-        , Day(..)-        , Holiday(..)-        , getDaysBetween-        , isWeekEnd-        , getNextBusinessDay-        ) where+  ( module QuantLib.Time.Date,+    DayOfWeek (..),+  )+where -import Data.Time.Calendar (Day(..), addDays, toGregorian)-import Data.Time.Calendar.WeekDate (dayOfWeek, DayOfWeek(..))+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+--         deriving (Show, Eq, Enum)++-- | Date+type Date = Day+ -- | Defines a holidays for given calendar. Corresponds to calendar class in QuantLib class Holiday m where-        isHoliday :: m->(Integer, Int, Int)->Bool-        -        isBusinessDay :: m->Day->Bool-        isBusinessDay m d = not (isHoliday m $ toGregorian d)+  isHoliday :: m -> (Integer, Int, Int) -> Bool -        hBusinessDayBetween :: m->(Day, Day)->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) +  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 :: Day->Bool-isWeekEnd d     = (weekday == Saturday) || (weekday == Sunday)-        where   weekday = dayOfWeek d+isWeekEnd :: Date -> Bool+isWeekEnd d = (weekday == Saturday) || (weekday == Sunday)+  where+    weekday = getWeekDay d  -- | Gets the next working day-getNextBusinessDay :: Holiday a => a->Day->Day+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->Day->Day->Int-        -- | Year fraction-        dcYearFraction  :: m->Day->Day->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