Skip to content

Commit

Permalink
update format
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowbean committed Nov 20, 2023
1 parent 4654e30 commit 42741c1
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 19 deletions.
8 changes: 4 additions & 4 deletions src/Deal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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 ->
Expand Down
4 changes: 2 additions & 2 deletions src/Deal/DealQuery.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions src/Liability.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Stmt.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
8 changes: 4 additions & 4 deletions src/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 3 additions & 5 deletions src/Waterfall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 42741c1

Please sign in to comment.