Skip to content

Commit

Permalink
add new date vector generation method NO_IE
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowbean committed Aug 11, 2023
1 parent 776b067 commit 6fd9e3a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ data Ts = FloatCurve [TsPoint Rational]
| PricingCurve [TsPoint Rational]
deriving (Show,Eq,Ord,Read,Generic)

data RangeType = II | IE | EI | EE
data RangeType = II | IE | EI | EE | NO_IE
data CutoffType = Inc | Exc

data BookItem = Item String Balance
Expand Down
4 changes: 3 additions & 1 deletion src/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import Text.Printf
import Control.Exception

import Debug.Trace
import Data.Time (addDays)
debug = flip trace

mulBR :: Balance -> Rate -> Centi
Expand Down Expand Up @@ -242,7 +243,7 @@ genSerialDatesTill sd ptn ed
YearFirst-> div cdM 12
MonthDayOfYear _m _d -> div cdM 12 -- T.MonthOfYear T.DayOfMonth
DayOfMonth _d -> cdM -- T.DayOfMonth
CustomDate ds -> 2 + (toInteger $ length ds)
CustomDate ds -> 2 + toInteger (length ds)
EveryNMonth _d _n -> div cdM (toInteger _n)
-- DayOfWeek Int -> -- T.DayOfWeek

Expand All @@ -257,6 +258,7 @@ genSerialDatesTill2 rt sd dp ed
(IE,False) -> sd:_r
(EE,True) -> tail _r
(EE,False) -> _r
(NO_IE,_) -> genSerialDatesTill2 rt sd dp (addDays 1 ed)
where
_r = case dp of
AllDatePattern dps -> concat [ genSerialDatesTill sd _dp ed | _dp <- dps ]
Expand Down
2 changes: 1 addition & 1 deletion test/UT/AccountTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ reserveAccTest =
acc1 = Account 200 "A1" Nothing (Just (PctReserve CurrentPoolBalance 0.01)) Nothing
acc2 = Account 150 "A2" Nothing (Just (FixReserve 210)) Nothing
accMap = Map.fromList [("A1",acc1),("A2",acc2)]
testCFs = CF.CashFlowFrame $
testCFs = CF.CashFlowFrame
[CF.MortgageFlow (toDate "20220601") 150 20 10 0 0 0 0 0 Nothing
,CF.MortgageFlow (toDate "20220701") 130 20 10 0 0 0 0 0 Nothing
,CF.MortgageFlow (toDate "20220801") 110 20 10 0 0 0 0 0 Nothing
Expand Down
16 changes: 16 additions & 0 deletions test/UT/UtilTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,22 @@ dateVectorPatternTest =
(OffsetBy
(CustomDate [toDate "20230202", toDate "20230909"]) 2)
(toDate "20230910"))
, testCase "No Inclusive or Exclusive" $
assertEqual "1"
(toDates ["20230831","20230930","20231031"])
(genSerialDatesTill2 NO_IE (toDate "20230810") MonthEnd (toDate "20231031") )
, testCase "No Inclusive or Exclusive" $
assertEqual "2"
(toDates ["20230831","20230930"])
(genSerialDatesTill2 NO_IE (toDate "20230810") MonthEnd (toDate "20231030") )
, testCase "No Inclusive or Exclusive" $
assertEqual "3"
(toDates ["20230831","20230930","20231031"])
(genSerialDatesTill2 NO_IE (toDate "20230831") MonthEnd (toDate "20231031") )
, testCase "No Inclusive or Exclusive" $
assertEqual "4"
(toDates ["20230831","20230930"])
(genSerialDatesTill2 NO_IE (toDate "20230831") MonthEnd (toDate "20231030") )
]

paddingTest =
Expand Down

0 comments on commit 6fd9e3a

Please sign in to comment.