Skip to content

Commit

Permalink
0.41.x (#245)
Browse files Browse the repository at this point in the history
* fix : order of pay sequence when remain amt is 0
* add cmt
* Fix on step up & floater bond
* add asset-assumption mismatch error
* refactor on PDL
* expose query LedgerBalanceBy
* fix ledger query by direction always return positive
* remove legacy DealQuery
* Add utils
* patch dates to Errors
* expose changeStatus action
* Ensure result of <limit> is above zero
* update validation on liqSupport
  • Loading branch information
yellowbean authored Dec 12, 2024
1 parent a0eb234 commit a13ce3b
Show file tree
Hide file tree
Showing 37 changed files with 1,876 additions and 1,541 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/docker-image-dev-by-tag.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ jobs:

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
uses: docker/metadata-action@v5
with:
images: yellowbean/hastructure
tags: |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'master') }}
type=match,pattern=(a\d+.\d+.\d+),group=1
flavor: |
latest=false
- name: 'Cleanup build folder'
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ jobs:

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
uses: docker/metadata-action@v5
with:
images: yellowbean/hastructure

Expand Down
17 changes: 14 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,28 @@
<!-- towncrier release notes start -->


## 0.40.9
### 2024-12-11
* ENHANCE: Ensure <limit> always return positive ,otherwise engine will throw error
* NEW: add new action `changeStatus` in waterfall, with optional `Pre` as condition to trigger the status change


## 0.40.6
### 2024-12-06
* NEW: new formula `ledgerBalanceBy`, which return either `Credit` or `Debit` balance of a ledger
* FIX: step-up coupon bond which has a floater index will increase forever
* ENHANCE: refactor on `PDL` book type.


## 0.40.1
### 2024-11-05
* NEW: break changes on API ,now the engine is able to throw out error message instead of just hanging.


## 0.31.0

### 2024-11-05
* NEW: new Call options assumption ,which specifies `dates` to be tested
* NEW:
* ENHANCE: transform financial report to a Tree from a Table
* ENHANCE: transform financial report to a `Tree` from a `Table`

## 0.30.5
### 2024-11-02
Expand Down
6 changes: 3 additions & 3 deletions Hastructure.cabal
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
cabal-version: 1.12

-- This file has been generated from package.yaml by hpack version 0.36.0.
-- This file has been generated from package.yaml by hpack version 0.37.0.
--
-- see: https://github.com/sol/hpack

name: Hastructure
version: 0.26.5
version: 0.40.11
description: Please see the README on GitHub at <https://github.com/yellowbean/Hastructure#readme>
category: StructuredFinance;Securitisation;Cashflow
homepage: https://github.com/yellowbean/Hastructure#readme
Expand All @@ -18,7 +18,7 @@ license-file: LICENSE
build-type: Simple
extra-source-files:
README.md
ChangeLog.md
CHANGELOG.md

source-repository head
type: git
Expand Down
8 changes: 4 additions & 4 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ import qualified DateUtil as DU

import Data.Scientific (fromRationalRepetend,formatScientific, Scientific,FPFormat(Fixed))
import Control.Lens
import Debug.Trace
import qualified Types as W
import Cashflow (patchCumulative)


import Debug.Trace
debug = flip Debug.Trace.trace


Expand All @@ -115,7 +115,7 @@ $(deriveJSON defaultOptions ''Version)
instance ToSchema Version

version1 :: Version
version1 = Version "0.40.1"
version1 = Version "0.40.11"



Expand Down Expand Up @@ -304,7 +304,7 @@ wrapRun (PDeal d) mAssump mNonPerfAssump
(_d,_pflow,_rs,_p) <- D.runDeal d D.DealPoolFlowPricing mAssump mNonPerfAssump
return (PDeal _d,_pflow,_rs,_p)

wrapRun x _ _ = error $ "RunDeal Failed ,due to unsupport deal type "++ show x
wrapRun x _ _ = Left $ "RunDeal Failed ,due to unsupport deal type "++ show x


data PoolTypeWrap = LPool (DB.PoolType AB.Loan)
Expand Down Expand Up @@ -337,7 +337,7 @@ wrapRunPoolType (FPool pt) assump mRates = D.runPoolType pt assump $ Just (AP.No
wrapRunPoolType (VPool pt) assump mRates = D.runPoolType pt assump $ Just (AP.NonPerfAssumption{AP.interest = mRates})
wrapRunPoolType (PPool pt) assump mRates = D.runPoolType pt assump $ Just (AP.NonPerfAssumption{AP.interest = mRates})
wrapRunPoolType (UPool pt) assump mRates = D.runPoolType pt assump $ Just (AP.NonPerfAssumption{AP.interest = mRates})
wrapRunPoolType x _ _ = error $ "RunPool Failed ,due to unsupport pool type "++ show x
wrapRunPoolType x _ _ = Left $ "RunPool Failed ,due to unsupport pool type "++ show x


data RunAssetReq = RunAssetReq Date [AB.AssetUnion] (Maybe AP.ApplyAssumptionType) (Maybe [RateAssumption]) (Maybe PricingMethod)
Expand Down
4 changes: 2 additions & 2 deletions package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Hastructure
version: 0.26.5
version: 0.40.11
github: "yellowbean/Hastructure"
license: BSD3
author: "Xiaoyu"
Expand All @@ -8,7 +8,7 @@ copyright: "2024 Xiaoyu, Zhang"

extra-source-files:
- README.md
- ChangeLog.md
- CHANGELOG.md

# Metadata used when publishing your package
# synopsis: Short description of your package
Expand Down
11 changes: 6 additions & 5 deletions src/Accounts.hs
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,10 @@ depositInt ed a@(Account bal _ (Just intType) _ stmt)
newStmt = appendStmt stmt newTxn

-- | move cash from account A to account B
transfer :: Account -> Amount -> Date -> Account -> (Account, Account)
transfer sourceAcc@(Account sBal san _ _ sStmt)
amount
transfer :: (Account,Account) -> Date -> Amount -> (Account, Account)
transfer (sourceAcc@(Account sBal san _ _ sStmt), targetAcc@(Account tBal tan _ _ tStmt))
d
targetAcc@(Account tBal tan _ _ tStmt)
amount
= (sourceAcc {accBalance = newSBal, accStmt = sourceNewStmt}
,targetAcc {accBalance = newTBal, accStmt = targetNewStmt})
where
Expand All @@ -121,7 +120,9 @@ deposit amount d source acc@(Account bal _ _ _ maybeStmt) =

-- | draw cash from account with a comment
draw :: Amount -> Date -> TxnComment -> Account -> Account
draw amount = deposit (- amount)
draw amount d txn acc@Account{ accBalance = bal ,accName = an}
| bal >= amount = deposit (- amount) d txn acc
| otherwise = error $ "Date:"++ show d ++" Failed to draw "++ show amount ++" from account" ++ an

-- | draw cash from account with a comment,return shortfall and acccount
tryDraw :: Amount -> Date -> TxnComment -> Account -> ((Amount,Amount),Account)
Expand Down
2 changes: 1 addition & 1 deletion src/AssetClass/AssetCashflow.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ applyHaircut (Just A.ExtraStress{A.poolHairCut = Just haircuts}) (CF.CashFlowFra
patchPrepayPenaltyFlow :: (Int,Maybe PrepayPenaltyType) -> CF.CashFlowFrame -> CF.CashFlowFrame
patchPrepayPenaltyFlow (ot,mPpyPen) mflow@(CF.CashFlowFrame st trs)
= let
(startDate,endDate) = CF.getDateRangeCashFlowFrame mflow
--(startDate,endDate) = CF.getDateRangeCashFlowFrame mflow
prepaymentFlow = CF.mflowPrepayment <$> trs
flowSize = CF.sizeCashFlowFrame mflow
in
Expand Down
2 changes: 2 additions & 0 deletions src/AssetClass/Installment.hs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ instance Asset Installment where
projCashflow inst@(Installment _ cb rt (Defaulted Nothing)) asOfDay assumps _
= Right $ (CF.CashFlowFrame (cb, asOfDay, Nothing) $ [CF.LoanFlow asOfDay cb 0 0 0 0 0 0 (getOriginRate inst) Nothing],Map.empty)

projCashflow a b c d = Left $ "Failed to match when proj mortgage with assumption >>" ++ show a ++ show b ++ show c ++ show d

splitWith (Installment (LoanOriginalInfo ob or ot p sd _type _obligor) cb rt st) rs
= [ Installment (LoanOriginalInfo (mulBR ob ratio) or ot p sd _type _obligor) (mulBR cb ratio) rt st | ratio <- rs ]

Expand Down
2 changes: 2 additions & 0 deletions src/AssetClass/Lease.hs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ instance Asset Lease where
begBal = CF.buildBegBal allTxns


projCashflow a b c d = Left $ "Failed to match when proj lease with assumption >>" ++ show a ++ show b ++ show c ++ show d

getCurrentBal l = case l of
StepUpLease _ _ bal _ _ -> bal
RegularLease _ bal _ _-> bal
Expand Down
2 changes: 1 addition & 1 deletion src/AssetClass/Loan.hs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ instance Asset Loan where
projCashflow m@(PersonalLoan (LoanOriginalInfo ob or ot p sd prinPayType _) cb cr rt (Defaulted Nothing)) asOfDay assumps _
= Right $ (CF.CashFlowFrame (cb,asOfDay,Nothing) [CF.LoanFlow asOfDay 0 0 0 0 0 0 0 cr Nothing],Map.empty)

projCashflow a b c d = Left $ "failed to match projCashflow"++show a++show b++show c++show d
projCashflow a b c d = Left $ "failed to match projCashflow for Loan "++show a++show b++show c++show d

splitWith l@(PersonalLoan (LoanOriginalInfo ob or ot p sd prinPayType obr) cb cr rt st) rs
= [ PersonalLoan (LoanOriginalInfo (mulBR ob ratio) or ot p sd prinPayType obr) (mulBR cb ratio) cr rt st | ratio <- rs ]
2 changes: 2 additions & 0 deletions src/AssetClass/ProjectedCashFlow.hs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ instance Ast.Asset ProjectedCashflow where
Right $ (foldl CF.combine fixedCashFlow floatedCashFlow, Map.empty)
--(fixedCashFlow, Map.empty)

projCashflow a b c d = Left $ "Failed to match when proj projected flow with assumption >>" ++ show a ++ show b ++ show c ++ show d

getBorrowerNum f = 0

splitWith f rs = [f]
Expand Down
2 changes: 2 additions & 0 deletions src/AssetClass/Receivable.hs
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,5 @@ instance Asset Receivable where

txns = [initTxn, CF.ReceivableFlow payDate 0 0 principal feePaid defaultAmt 0 realizedLoss Nothing]
(futureTxns,historyM) = CF.cutoffTrs asOfDay $ txns++(buildRecoveryCfs payDate defaultAmt amr) -- `debug` ("recovery flow"++ show (buildRecoveryCfs payDate defaultAmt amr))

projCashflow a b c d = Left $ "Failed to match when proj receivable with assumption >>" ++ show a ++ show b ++ show c ++ show d
19 changes: 11 additions & 8 deletions src/Cashflow.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@

module Cashflow (CashFlowFrame(..),Principals,Interests,Amount
,combine,mergePoolCf,sumTsCF,tsSetDate,tsSetLoss,tsSetRecovery
,sizeCashFlowFrame,aggTsByDates, getTsCashFlowFrame
,sizeCashFlowFrame,aggTsByDates
,mflowInterest,mflowPrincipal,mflowRecovery,mflowPrepayment
,mflowRental,mflowRate,sumPoolFlow,splitTrs,aggregateTsByDate
,mflowDefault,mflowLoss,mflowDate
,getSingleTsCashFlowFrame,getDatesCashFlowFrame,getDateRangeCashFlowFrame
,getSingleTsCashFlowFrame,getDatesCashFlowFrame
,lookupSource,lookupSourceM,combineTss
,mflowBalance,mflowBegBalance,tsDefaultBal
,mflowBorrowerNum,mflowPrepaymentPenalty
,emptyTsRow,mflowAmortAmount
,tsTotalCash, setPrepaymentPenalty, setPrepaymentPenaltyFlow
,getDate,getTxnLatestAsOf
,getDate,getTxnLatestAsOf,totalPrincipal
,mflowWeightAverageBalance
,addFlowBalance,totalLoss,totalDefault,totalRecovery,firstDate
,shiftCfToStartDate,cfInsertHead,buildBegTsRow,insertBegTsRow
Expand Down Expand Up @@ -221,14 +221,12 @@ instance Show CashFlowFrame where
sizeCashFlowFrame :: CashFlowFrame -> Int
sizeCashFlowFrame (CashFlowFrame _ ts) = length ts

getTsCashFlowFrame :: CashFlowFrame -> [TsRow]
getTsCashFlowFrame (CashFlowFrame _ ts) = ts

getDatesCashFlowFrame :: CashFlowFrame -> [Date]
getDatesCashFlowFrame (CashFlowFrame _ ts) = getDates ts

getDateRangeCashFlowFrame :: CashFlowFrame -> (Date,Date)
getDateRangeCashFlowFrame (CashFlowFrame _ trs) = (getDate (head trs), getDate (last trs))
-- getDateRangeCashFlowFrame :: CashFlowFrame -> (Date,Date) --TODO what if it is empty ?
-- getDateRangeCashFlowFrame (CashFlowFrame _ [tr]) = (getDate tr, getDate tr)
-- getDateRangeCashFlowFrame (CashFlowFrame _ trs) = (getDate (head trs), getDate (last trs))

getBegBalCashFlowFrame :: CashFlowFrame -> Balance
getBegBalCashFlowFrame (CashFlowFrame _ []) = 0
Expand Down Expand Up @@ -825,6 +823,9 @@ totalDefault (CashFlowFrame _ rs) = sum $ mflowDefault <$> rs
totalRecovery :: CashFlowFrame -> Balance
totalRecovery (CashFlowFrame _ rs) = sum $ mflowRecovery <$> rs

totalPrincipal :: CashFlowFrame -> Balance
totalPrincipal (CashFlowFrame _ rs) = sum $ mflowPrincipal <$> rs

-- ^ merge two cashflow frame but no patching beg balance
mergePoolCf :: CashFlowFrame -> CashFlowFrame -> CashFlowFrame
mergePoolCf cf (CashFlowFrame _ []) = cf
Expand Down Expand Up @@ -1187,5 +1188,7 @@ txnCumulativeStats = lens getter setter
setter x _ = x




$(deriveJSON defaultOptions ''TsRow)
$(deriveJSON defaultOptions ''CashFlowFrame)
Loading

0 comments on commit a13ce3b

Please sign in to comment.