From 42741c1999ec165fc3a76a3e04bf812505a87963 Mon Sep 17 00:00:00 2001 From: Xiaoyu Date: Mon, 20 Nov 2023 23:29:21 +0800 Subject: [PATCH] update format --- src/Deal.hs | 8 ++++---- src/Deal/DealQuery.hs | 4 ++-- src/Liability.hs | 4 ++-- src/Stmt.hs | 4 ++-- src/Types.hs | 8 ++++---- src/Util.hs | 1 + src/Waterfall.hs | 8 +++----- 7 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/Deal.hs b/src/Deal.hs index 917019d7..a162ca99 100644 --- a/src/Deal.hs +++ b/src/Deal.hs @@ -203,20 +203,23 @@ testCalls :: P.Asset a => TestDeal a -> Date -> [C.CallOption] -> Bool testCalls t d [] = False testCalls t d opts = any (testCall t d) opts + queryTrigger :: P.Asset a => TestDeal a -> DealCycle -> [Trigger] queryTrigger t@TestDeal{ triggers = trgs } wt = case trgs of Nothing -> [] Just _trgs -> maybe [] Map.elems $ Map.lookup wt _trgs +-- ^ run trigger sequentially testTriggers :: P.Asset a => TestDeal a -> Date -> [Trigger] -> Bool testTriggers t d [] = False testTriggers t d triggers = any (testTrigger t d) triggers +-- ^ execute effects of trigger: making changes to deal runEffects :: P.Asset a => TestDeal a -> Date -> TriggerEffect -> TestDeal a runEffects t@TestDeal{accounts = accMap, fees = feeMap } d te = case te of - DealStatusTo _ds -> t {status=_ds} -- `debug` ("changing status to "++show _ds++"on date"++ show d) + DealStatusTo _ds -> t {status = _ds} DoAccrueFee fns -> t {fees = foldr (Map.adjust (calcDueFee t d)) feeMap fns} ChangeReserveBalance accName rAmt -> t {accounts = Map.adjust (A.updateReserveBalance rAmt) accName accMap } @@ -233,9 +236,6 @@ runTriggers t@TestDeal{status=oldStatus, triggers = Just trgM} d dcycle = -- get triggeres to run at `dealCycle` trgsMap = Map.findWithDefault Map.empty dcycle trgM - --testTrgsResult = [ (_trg, (not (trgStatus _trg) || trgStatus _trg && trgCurable _trg) && testTrigger t d _trg) - -- | _trg <- _trgs ] - -- triggered trigger triggeredTrgs = Map.filter (\trg -> diff --git a/src/Deal/DealQuery.hs b/src/Deal/DealQuery.hs index 184c2783..07ef0295 100644 --- a/src/Deal/DealQuery.hs +++ b/src/Deal/DealQuery.hs @@ -518,8 +518,8 @@ queryDealBool t@TestDeal{triggers= trgs,bonds = bndMap} ds = IsDealStatus st -> status t == st - TestAny b dss -> any (== b) [ queryDealBool t ds | ds <- dss ] - TestAll b dss -> all (== b) [ queryDealBool t ds | ds <- dss ] + TestAny b dss -> elem b [ queryDealBool t ds | ds <- dss ] + TestAll b dss -> all (== b) [ queryDealBool t ds | ds <- dss ] _ -> error ("Failed to query bool type formula"++ show ds) diff --git a/src/Liability.hs b/src/Liability.hs index c3863205..49675836 100644 --- a/src/Liability.hs +++ b/src/Liability.hs @@ -289,11 +289,11 @@ calcZspread (tradePrice,priceDay) count (level ,(lastSpd,lastSpd2),spd) b@Bond{b thresholds = toRational <$> (level *) <$> [50,20,10,5,2,0.1,0.05,0.01,0.005] shiftPcts = (level *) <$> [0.5,0.2,0.1,0.05,0.02,0.01,0.005,0.001,0.0005] in - case find (\(a,b) -> a < (abs(toRational gap))) (zip thresholds shiftPcts ) of + case find (\(a,b) -> a < abs(toRational gap)) (zip thresholds shiftPcts ) of Just (_,v) -> toRational v -- `debug` ("shifting ->"++ show v) Nothing -> toRational (level * 0.00001) -- `debug` ("shifting-> <> 0.00005") - newLevel = case [abs(newSpd) < 0.0001 + newLevel = case [abs newSpd < 0.0001 ,abs(newSpd-lastSpd)<0.000001 ,abs(newSpd-lastSpd2)<0.000001] of [True,_,_] -> level * 0.5 diff --git a/src/Stmt.hs b/src/Stmt.hs index bb0e73c5..747170fd 100644 --- a/src/Stmt.hs +++ b/src/Stmt.hs @@ -114,8 +114,8 @@ weightAvgBalance sd ed txns = sum $ zipWith mulBR bals dsFactor -- `debug` ("WavgBalace "++show bals++show dsFactor) where _txns = sliceBy IE sd ed txns - bals = (map getTxnBegBalance _txns) ++ [getTxnBalance (last _txns)] - ds = [sd]++(map getDate _txns)++[ed] + bals = map getTxnBegBalance _txns ++ [getTxnBalance (last _txns)] + ds = [sd] ++ map getDate _txns ++ [ed] dsFactor = getIntervalFactors ds -- `debug` ("DS>>>"++show ds) diff --git a/src/Types.hs b/src/Types.hs index a7c7b281..6ccae322 100644 --- a/src/Types.hs +++ b/src/Types.hs @@ -613,10 +613,10 @@ data ResultComponent = CallAt Date -- ^ the d | DealStatusChangeTo Date DealStatus DealStatus -- ^ record when status changed | BondOutstanding String Balance Balance -- ^ when deal ends,calculate oustanding principal balance | BondOutstandingInt String Balance Balance -- ^ when deal ends,calculate oustanding interest due - | InspectBal Date DealStats Balance - | InspectInt Date DealStats Int - | InspectRate Date DealStats Micro - | InspectBool Date DealStats Bool + | InspectBal Date DealStats Balance -- ^ A bal value from inspection + | InspectInt Date DealStats Int -- ^ A int value from inspection + | InspectRate Date DealStats Micro -- ^ A rate value from inspection + | InspectBool Date DealStats Bool -- ^ A bool value from inspection | FinancialReport StartDate EndDate BalanceSheetReport CashflowReport | InspectWaterfall Date (Maybe String) [DealStats] [String] | ErrorMsg String diff --git a/src/Util.hs b/src/Util.hs index 58f3b2c1..e647e206 100644 --- a/src/Util.hs +++ b/src/Util.hs @@ -248,6 +248,7 @@ monthsAfter d n = T.addGregorianDurationClip (T.CalendarDiffDays n 0) d getPriceValue :: PriceResult -> Balance getPriceValue (AssetPrice v _ _ _ _ ) = v +getPriceValue (PriceResult v _ _ _ _ _) = v maximum' :: Ord a => [a] -> a maximum' = foldr1 (\x y ->if x >= y then x else y) diff --git a/src/Waterfall.hs b/src/Waterfall.hs index 04ddbf24..d9c683b8 100644 --- a/src/Waterfall.hs +++ b/src/Waterfall.hs @@ -8,7 +8,6 @@ module Waterfall ,ActionWhen(..),BookType(..),ExtraSupport(..)) where -import GHC.Generics import Language.Haskell.TH import Data.Aeson hiding (json) import qualified Data.Text as T @@ -27,13 +26,12 @@ import Liability import Types import Revolving import Triggers -import Ledger import Stmt (TxnComment(..)) import qualified Lib as L import qualified Call as C import qualified CreditEnhancement as CE import CreditEnhancement (LiquidityProviderName) -import Ledger (Ledger) +import Ledger (Ledger,LedgerName) data ActionWhen = EndOfPoolCollection -- ^ waterfall executed at the end of pool collection @@ -76,8 +74,8 @@ data Action = Transfer (Maybe Limit) AccountName AccountName (Maybe TxnComment) | PayIntResidual (Maybe Limit) AccountName BondName -- ^ pay interest to bond regardless interest due -- | PayTillYield AccountName [BondName] -- Bond - Principal - | PayPrin (Maybe Limit) AccountName [BondName] (Maybe ExtraSupport) -- ^ pay principal to bond - | PayPrinBySeq (Maybe Limit) AccountName [BondName] (Maybe ExtraSupport) -- ^ pay principal to bond via sequence + | PayPrin (Maybe Limit) AccountName [BondName] (Maybe ExtraSupport) -- ^ pay principal to bond via pro-rata + | PayPrinBySeq (Maybe Limit) AccountName [BondName] (Maybe ExtraSupport) -- ^ pay principal to bond via sequence | PayPrinResidual AccountName [BondName] -- ^ pay principal regardless predefined balance schedule -- | PayPrinBy Limit AccountName BondName -- Pool/Asset change