diff --git a/src/Deal.hs b/src/Deal.hs index 76035cc..ba579e1 100644 --- a/src/Deal.hs +++ b/src/Deal.hs @@ -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) @@ -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 @@ -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 diff --git a/src/Deal/DealQuery.hs b/src/Deal/DealQuery.hs index c9f6ff5..612ae50 100644 --- a/src/Deal/DealQuery.hs +++ b/src/Deal/DealQuery.hs @@ -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 @@ -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 @@ -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 ] @@ -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)