Skip to content

Commit

Permalink
expose ratio/avgRatio to date patch
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowbean committed Sep 20, 2024
1 parent bde6076 commit e9fad59
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
19 changes: 6 additions & 13 deletions src/Deal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,10 @@ run t@TestDeal{accounts=accMap,fees=feeMap,triggers=mTrgMap,bonds=bndMap,status=
run (t{liqProvider = Just newLiqMap}) poolFlowMap (Just ads) rates calls rAssump log

DealClosed d ->
let
(PreClosing newSt) = status t -- `debug` ("Switch to >>>"++ show (status t))
let
newSt = case dStatus of
(PreClosing st) -> st
_ -> error $ "DealClosed action is not in PreClosing status but got"++ show dStatus
w = Map.findWithDefault [] W.OnClosingDay (waterfall t) -- `debug` ("DDD0")
rc = RunContext poolFlowMap rAssump rates
(newDeal, newRc, newLog) = foldl (performActionWrap d) (t, rc, log) w -- `debug` ("ClosingDay Action:"++show w)
Expand Down Expand Up @@ -517,16 +519,7 @@ run t@TestDeal{accounts=accMap,fees=feeMap,triggers=mTrgMap,bonds=bndMap,status=
newlog = FinancialReport sd ed bsReport cashReport
in
run t poolFlowMap (Just ads) rates calls rAssump $ log++[newlog]
-- ResetSrtRate d srtName ->
-- let
-- newSrtMap = Map.adjust (updateSrtRate t d (fromMaybe [] rAssump)) srtName (srt t)
-- in
-- run t{srt = newSrtMap} poolFlowMap (Just ads) rates calls rAssump log
-- AccrueSrt d srtName ->
-- let
-- newSrtMap = Map.adjust (accrueSrt t d) srtName (srt t)
-- in
-- run t{srt = newSrtMap} poolFlowMap (Just ads) rates calls rAssump log


FireTrigger d cyc n ->
let
Expand Down Expand Up @@ -555,7 +548,7 @@ run t@TestDeal{accounts=accMap,fees=feeMap,triggers=mTrgMap,bonds=bndMap,status=

MakeWhole d spd walTbl ->
let
schedulePoolFlowMap = Map.map (fromMaybe (CF.CashFlowFrame (0,toDate "19000101",Nothing) [])) $ view dealScheduledCashflow t
schedulePoolFlowMap = Map.map (fromMaybe (CF.CashFlowFrame (0,epocDate,Nothing) [])) $ view dealScheduledCashflow t
factor = divideBB (queryDeal t (FutureCurrentPoolBegBalance Nothing)) (queryDeal t (FutureCurrentSchedulePoolBegBalance Nothing))
reduceCfs = Map.map (over CF.cashflowTxn (\xs -> (CF.scaleTsRow factor) <$> xs)) schedulePoolFlowMap -- need to apply with factor and trucate with date
(runDealWithSchedule,_) = run t reduceCfs (Just ads) rates calls rAssump $ log
Expand Down
6 changes: 5 additions & 1 deletion src/Deal/DealQuery.hs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ patchDateToStats d t
FloorWith ds f -> FloorWith (patchDateToStats d ds) (patchDateToStats d f)
CapWith ds c -> CapWith (patchDateToStats d ds) (patchDateToStats d c)
Round ds rb -> Round (patchDateToStats d ds) rb
DivideRatio ds1 ds2 -> DivideRatio (patchDateToStats d ds1) (patchDateToStats d ds2)
AvgRatio ss -> AvgRatio $ [ patchDateToStats d ds | ds <- ss ]
_ -> t -- `debug` ("Failed to patch date to stats"++show t)

patchDatesToStats :: P.Asset a => TestDeal a -> Date -> Date -> DealStats -> DealStats
Expand All @@ -113,6 +115,8 @@ patchDatesToStats t d1 d2 ds
CapWith ds c -> CapWith (patchDatesToStats t d1 d2 ds) (patchDatesToStats t d1 d2 c)
Round ds rb -> Round (patchDatesToStats t d1 d2 ds) rb
Sum dss -> Sum $ [ patchDatesToStats t d1 d2 ds | ds <- dss ]
DivideRatio ds1 ds2 -> DivideRatio (patchDatesToStats t d1 d2 ds1) (patchDatesToStats t d1 d2 ds2)
AvgRatio ss -> AvgRatio $ [ patchDatesToStats t d1 d2 ds | ds <- ss ]
x -> x


Expand Down Expand Up @@ -234,7 +238,6 @@ queryDealInt t@TestDeal{ pool = p ,bonds = bndMap } s d =
FloorWith s floor -> max (queryDealInt t s d) (queryDealInt t floor d)
FloorWithZero s -> max (queryDealInt t s d) 0
CapWith s cap -> min (queryDealInt t s d) (queryDealInt t cap d)

Max ss -> maximum' $ [ queryDealInt t s d | s <- ss ]
Min ss -> minimum' $ [ queryDealInt t s d | s <- ss ]

Expand Down Expand Up @@ -616,6 +619,7 @@ queryDeal t@TestDeal{accounts=accMap, bonds=bndMap, fees=feeMap, ledgers=ledgerM
CapWith s cap -> min (queryDeal t s) (queryDeal t cap)
Abs s -> abs $ queryDeal t s
Round ds rb -> roundingBy rb (queryDeal t ds)
DivideRatio s1 s2 -> fromRational . toRational $ queryDealRate t (DivideRatio s1 s2)

_ -> error ("Failed to query balance of -> "++ show s)

Expand Down

0 comments on commit e9fad59

Please sign in to comment.