Skip to content

Commit

Permalink
0.23.4 compatible release (#126)
Browse files Browse the repository at this point in the history
* expose bond pay shortcut
* expose bond pay int shortcut
* add conditional support
* add Do Nothing on trigger effects
* expose PayFeeBySeq
* fix irr
* add support draw
* update wkflow

---------

Co-authored-by: yellowbean <always.zhang@gmail>
  • Loading branch information
yellowbean and yellowbean authored Nov 26, 2023
1 parent 42741c1 commit 2a8c074
Show file tree
Hide file tree
Showing 11 changed files with 410 additions and 104 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
name: Docker Image CI

on:
push:
tags:
- 'v*'
pull_request:
types:
- closed

jobs:

build:
if_merged:
if: github.event.pull_request.merged

runs-on: ubuntu-latest

steps:
-
name: Set up QEMU
Expand Down Expand Up @@ -42,4 +41,4 @@ jobs:
push: true
tags: ${{ secrets.DOCKER_HUB_USERNAME }}/hastructure:dev
cache-from: type=registry,ref=${{ secrets.DOCKER_HUB_USERNAME }}/hastructure:buildcache
cache-to: type=registry,ref=${{ secrets.DOCKER_HUB_USERNAME }}/hastructure:buildcache,mode=max
cache-to: type=registry,ref=${{ secrets.DOCKER_HUB_USERNAME }}/hastructure:buildcache,mode=max
2 changes: 1 addition & 1 deletion app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ $(deriveJSON defaultOptions ''Version)
instance ToSchema Version

version1 :: Version
version1 = Version "0.23.3"
version1 = Version "0.23.4"

data PoolType = MPool (P.Pool AB.Mortgage)
| LPool (P.Pool AB.Loan)
Expand Down
1 change: 0 additions & 1 deletion src/CreditEnhancement.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ module CreditEnhancement
import qualified Data.Text as T
import qualified Data.Time as Time
import qualified Data.Map as Map
import qualified InterestRate as IR
import GHC.Generics
import Language.Haskell.TH
import Data.Aeson hiding (json)
Expand Down
1 change: 1 addition & 0 deletions src/Deal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ runEffects t@TestDeal{accounts = accMap, fees = feeMap } d te
DoAccrueFee fns -> t {fees = foldr (Map.adjust (calcDueFee t d)) feeMap fns}
ChangeReserveBalance accName rAmt ->
t {accounts = Map.adjust (A.updateReserveBalance rAmt) accName accMap }
DoNothing -> t
_ -> error $ "Failed to match trigger effects: "++show te

-- ^ test trigger and add a log if deal status changed
Expand Down
227 changes: 141 additions & 86 deletions src/Deal/DealAction.hs

Large diffs are not rendered by default.

11 changes: 6 additions & 5 deletions src/Liability.hs
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ data Bond = Bond {
} deriving (Show, Eq, Generic)

consolStmt :: Bond -> Bond
consolStmt b@Bond{bndName = bn, bndStmt = Nothing} = b
consolStmt b@Bond{bndName = bn, bndStmt = Just (S.Statement (txn:txns))}
= b {bndStmt = Just (S.Statement (reverse (foldl S.consolTxn [txn] txns)))}

consolStmt b@Bond{bndName = bn, bndStmt = Nothing} = b

payInt :: Date -> Amount -> Bond -> Bond
payInt d 0 bnd@(Bond bn bt oi iinfo _ 0 r 0 0 dueIntDate lpayInt lpayPrin stmt) = bnd
Expand Down Expand Up @@ -239,14 +239,15 @@ calcBondYield d cost b@(Bond _ _ _ _ _ _ _ _ _ _ _ _ (Just (S.Statement txns)))
where
cashflows = [ TsPoint (S.getDate txn) (S.getTxnAmt txn) | txn <- txns ]

-- ^ backout interest due for a Yield Maintainace type bond
backoutDueIntByYield :: Date -> Bond -> Balance
backoutDueIntByYield d b@(Bond _ _ (OriginalInfo obal odate _ _) (InterestByYield y) _ currentBalance _ _ _ _ _ _ stmt)
= proj_fv - fvs - currentBalance -- `debug` ("Date"++ show d ++"FV->"++show proj_fv++">>"++show fvs++">>cb"++show currentBalance)
= projFv - fvs - currentBalance -- `debug` ("Date"++ show d ++"FV->"++show projFv++">>"++show fvs++">>cb"++show currentBalance)
where
proj_fv = fv2 y odate d obal
fvs = sum $ [ fv2 y d (fst cf) (snd cf) | cf <- cashflows ]
projFv = fv2 y odate d obal
fvs = sum $ [ fv2 y cfDate d cfAmt | (cfDate,cfAmt) <- cashflows ] -- `debug` (show d ++ ":CFS"++ show cashflows)
cashflows = case stmt of
Just (S.Statement txns) -> [ ((S.getDate txn),(S.getTxnAmt txn)) | txn <- txns ]
Just (S.Statement txns) -> [ ((S.getDate txn),(S.getTxnAmt txn)) | txn <- txns ] -- `debug` (show d ++":TXNS"++ show txns)
Nothing -> []


Expand Down
6 changes: 4 additions & 2 deletions src/Stmt.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE InstanceSigs #-}

module Stmt
(Statement(..),Txn(..)
Expand Down Expand Up @@ -179,6 +180,7 @@ getFlow comment =
SwapInSettle -> Inflow
SwapOutSettle -> Outflow
PurchaseAsset -> Outflow
SupportDraw -> Noneflow
TxnComments cmts ->
let
directionList = getFlow <$> cmts
Expand All @@ -193,12 +195,12 @@ getFlow comment =
_ -> error ("Missing in GetFlow >> "++ show comment)

instance Ord Txn where
compare :: Txn -> Txn -> Ordering
compare (BondTxn d1 _ _ _ _ _ _ ) (BondTxn d2 _ _ _ _ _ _ ) = compare d1 d2
compare (AccTxn d1 _ _ _ ) (AccTxn d2 _ _ _ ) = compare d1 d2

instance Eq Txn where
(BondTxn d1 _ _ _ _ _ _ ) == (BondTxn d2 _ _ _ _ _ _ )
= d1 == d2
(BondTxn d1 _ _ _ _ _ _ ) == (BondTxn d2 _ _ _ _ _ _ ) = d1 == d2

instance TimeSeries Txn where
getDate (BondTxn t _ _ _ _ _ _ ) = t
Expand Down
1 change: 1 addition & 0 deletions src/Triggers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ data TriggerEffect = DealStatusTo DealStatus -- ^ change deal
| IssueBonds [L.Bond] AccountName -- ^ issue new bonds and deposit proceeds to account
| BuyAsset AccountName PricingMethod -- ^ buy asset from the assumption using funds from account
| TriggerEffects [TriggerEffect] -- ^ a combination of effects above
| DoNothing -- ^ do nothing
deriving (Show, Eq, Generic)

data Trigger = Trigger {
Expand Down
2 changes: 2 additions & 0 deletions src/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ data TxnComment = PayInt [BondName]
| LiquidationRepay
| LiquidationSupportInt Balance Balance
| BankInt
| SupportDraw
| Empty
| Tag String
| UsingDS DealStats
Expand Down Expand Up @@ -344,6 +345,7 @@ instance ToJSON TxnComment where
toJSON SwapOutSettle = String $ T.pack $ "<SettleOut:>"
toJSON PurchaseAsset = String $ T.pack $ "<PurchaseAsset:>"
toJSON (TxnDirection dr) = String $ T.pack $ "<TxnDirection:"++show dr++">"
toJSON SupportDraw = String $ T.pack $ "<SupportDraw:>"

instance FromJSON TxnComment where
parseJSON = withText "Empty" parseTxn
Expand Down
7 changes: 6 additions & 1 deletion src/Waterfall.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,25 +59,30 @@ data BookType = PDL DealStats [(LedgerName,DealStats)] -- Reverse PDL Debit refe
data ExtraSupport = SupportAccount AccountName (Maybe BookType) -- ^ if there is deficit, draw another account to pay the shortfall
| SupportLiqFacility LiquidityProviderName -- ^ if there is deficit, draw facility's available credit to pay the shortfall
| MultiSupport [ExtraSupport] -- ^ if there is deficit, draw multiple supports (by sequence in the list) to pay the shortfall
| WithCondition Pre ExtraSupport -- ^ support only available if Pre is true
deriving (Show,Generic)

data Action = Transfer (Maybe Limit) AccountName AccountName (Maybe TxnComment)
-- Fee
| CalcFee [FeeName] -- ^ calculate fee due amount in the fee names
| PayFee (Maybe Limit) AccountName [FeeName] (Maybe ExtraSupport) -- ^ pay fee with cash from account with optional limit or extra support
| PayFeeBySeq (Maybe Limit) AccountName [FeeName] (Maybe ExtraSupport) -- ^ pay fee with cash from account with optional limit or extra support
| CalcAndPayFee (Maybe Limit) AccountName [FeeName] (Maybe ExtraSupport) -- ^ combination of CalcFee and PayFee
| PayFeeResidual (Maybe Limit) AccountName FeeName -- ^ pay fee regardless fee due amount
-- Bond - Interest
| CalcBondInt [BondName] -- ^ calculate interest due amount in the bond names
| PayInt (Maybe Limit) AccountName [BondName] (Maybe ExtraSupport) -- ^ pay interest with cash from the account with optional limit or extra support
| PayIntBySeq (Maybe Limit) AccountName [BondName] (Maybe ExtraSupport) -- ^ with sequence
| AccrueAndPayInt (Maybe Limit) AccountName [BondName] (Maybe ExtraSupport) -- ^ combination of CalcInt and PayInt
| AccrueAndPayIntBySeq (Maybe Limit) AccountName [BondName] (Maybe ExtraSupport) -- ^ with sequence
| 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 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
| PayIntPrinBySeq (Maybe Limit) AccountName [BondName] (Maybe ExtraSupport) -- ^ pay int & prin to bonds sequentially
| AccrueAndPayIntPrinBySeq (Maybe Limit) AccountName [BondName] (Maybe ExtraSupport)
-- Pool/Asset change
| BuyAsset (Maybe Limit) PricingMethod AccountName -- ^ buy asset from revolving assumptions using funds from account
| LiquidatePool PricingMethod AccountName -- ^ sell all assets and deposit proceeds to account
Expand Down
Loading

0 comments on commit 2a8c074

Please sign in to comment.