hquantlib-time 0.0.5.3 → 0.1.0
raw patch · 6 files changed
+100/−105 lines, 6 filesdep ~timePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: time
API changes (from Hackage documentation)
- 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: ModifiedJulianDay :: Integer -> Day
+ QuantLib.Time.Date: [toModifiedJulianDay] :: Day -> Integer
+ QuantLib.Time.Date: newtype () => Day
- QuantLib.Time.Date: getNextBusinessDay :: Holiday a => a -> Date -> Date
+ QuantLib.Time.Date: getNextBusinessDay :: Holiday a => a -> Day -> Day
- QuantLib.Time.Date: hBusinessDayBetween :: Holiday m => m -> (Date, Date) -> Int
+ QuantLib.Time.Date: hBusinessDayBetween :: Holiday m => m -> (Day, Day) -> Int
- QuantLib.Time.Date: isBusinessDay :: Holiday m => m -> Date -> Bool
+ QuantLib.Time.Date: isBusinessDay :: Holiday m => m -> Day -> Bool
- QuantLib.Time.Date: isWeekEnd :: Date -> Bool
+ QuantLib.Time.Date: isWeekEnd :: Day -> Bool
- QuantLib.Time.DayCounter: dcCount :: DayCounter m => m -> Date -> Date -> Int
+ QuantLib.Time.DayCounter: dcCount :: DayCounter m => m -> Day -> Day -> Int
- QuantLib.Time.DayCounter: dcYearFraction :: DayCounter m => m -> Date -> Date -> Double
+ QuantLib.Time.DayCounter: dcYearFraction :: DayCounter m => m -> Day -> Day -> Double
Files
- CHANGELOG.md +8/−0
- README.md +2/−0
- hquantlib-time.cabal +11/−7
- src/QuantLib/Time.hs +4/−4
- src/QuantLib/Time/Date.hs +38/−53
- src/QuantLib/Time/DayCounter.hs +37/−41
+ CHANGELOG.md view
@@ -0,0 +1,8 @@+### 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 view
@@ -0,0 +1,2 @@+# hquantlib-time+Separated Time module from HQuantlib
hquantlib-time.cabal view
@@ -1,6 +1,7 @@+cabal-version: 3.0 name: hquantlib-time-version: 0.0.5.3-license: LGPL+version: 0.1.0+license: LGPL-3.0-or-later license-file: LICENSE author: Pavel Ryzhov maintainer: Pavel Ryzhov <pavel.ryzhov@gmail.com>@@ -8,9 +9,12 @@ 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: alpha+stability: provisional homepage: http://github.com/paulrzcz/hquantlib-time.git-cabal-version: 1.18.0+extra-doc-files:+ README.md+ CHANGELOG.md+tested-with: GHC == 9.4.8 source-repository head type: git@@ -19,7 +23,7 @@ source-repository this type: git location: https://github.com/paulrzcz/hquantlib-time.git- tag: 0.0.5.3+ tag: 0.1.0 flag optimize description : Enable optimizations for library and benchmarks@@ -34,9 +38,9 @@ build-depends: base >3 && <5,- time >= 1.4.0.0 && < 1.15.0.0+ time >= 1.12.2 && < 1.13 hs-source-dirs: src ghc-options: -Wall if flag(optimize)- ghc-options: -funbox-strict-fields -O2 -fspec-constr -fdicts-cheap+ ghc-options: -funbox-strict-fields -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,68 +1,53 @@ module QuantLib.Time.Date- ( module QuantLib.Time.Date,- DayOfWeek (..),- )-where--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)+ ( BusinessDayConvention(..)+ , Day(..)+ , Holiday(..)+ , getDaysBetween+ , isWeekEnd+ , getNextBusinessDay+ ) where --- -- | Week days--- data WeekDay = Monday | Tuesday | Wednesday | Thursday | Friday | Saturday | Sunday--- deriving (Show, Eq, Enum)+import Data.Time.Calendar (Day(..), addDays, toGregorian)+import Data.Time.Calendar.WeekDate (dayOfWeek, DayOfWeek(..)) --- | Date-type Date = Day+{- | 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) -- | 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)-- 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)+ isHoliday :: m->(Integer, Int, Int)->Bool+ + isBusinessDay :: m->Day->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->(Day, Day)->Int+ hBusinessDayBetween m (fd, td) = foldl countDays 0 listOfDates+ where countDays counter x = counter + fromEnum (isBusinessDay m x)+ listOfDates = getDaysBetween (fd, td) -- | 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 :: Day->Bool+isWeekEnd d = (weekday == Saturday) || (weekday == Sunday)+ where weekday = dayOfWeek d -- | Gets the next working day-getNextBusinessDay :: Holiday a => a -> Date -> Date+getNextBusinessDay :: Holiday a => a->Day->Day 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,21 +1,18 @@ module QuantLib.Time.DayCounter- ( module QuantLib.Time.DayCounter,- )-where+ ( module QuantLib.Time.DayCounter+ ) where -import Data.Time.Calendar (Day (..), toGregorian)-import QuantLib.Time.Date (Date)+import QuantLib.Time.Date+import Data.Time.Calendar -- | 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->Day->Day->Int+ -- | Year fraction+ dcYearFraction :: m->Day->Day->Double {- data SimpleDayCounter = SimpleDayCounter@@ -30,35 +27,34 @@ data Thirty360 = ThirtyUSA | ThirtyEuropean | ThirtyItalian instance DayCounter Thirty360 where- dcName ThirtyUSA = "Thirty USA"- dcName ThirtyEuropean = "Thirty Euro"- dcName ThirtyItalian = "Thirty Italian"+ dcName ThirtyUSA = "Thirty USA"+ dcName ThirtyEuropean = "Thirty Euro"+ dcName ThirtyItalian = "Thirty Italian" - dcYearFraction dc fromDate toDate = fromIntegral (dcCount dc fromDate toDate) / 360.0+ 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)- 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+ 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) -intGregorian :: Day -> (Int, Int, Int)++ 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 date = (fromIntegral y, m, d)- where- (y, m, d) = toGregorian date+ where (y, m, d) = toGregorian date