Skip to content

Commit

Permalink
expose query on history recoveries
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowbean committed Jul 20, 2023
1 parent 6f87429 commit b41badd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Asset.hs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class Show a => Asset a where
-- {-# MINIMAL calcCashflow #-}

data IssuanceFields = IssuanceBalance
| HistoryRecoveries
deriving (Show,Ord,Eq,Read,Generic)

instance ToJSONKey IssuanceFields where
Expand Down
9 changes: 8 additions & 1 deletion src/Cashflow.hs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,13 @@ tsDefaultBal (MortgageFlow2 _ _ _ _ _ _ x _ _ _) = x
tsDefaultBal (MortgageFlow3 _ _ _ _ _ _ _ _ x _ _ _) = x
tsDefaultBal (LoanFlow _ _ _ _ _ x _ _ _) = x

mflowDefault :: TsRow -> Balance
mflowDefault (MortgageFlow _ _ _ _ _ x _ _ _ _) = x
mflowDefault (MortgageFlow2 _ _ _ _ _ _ x _ _ _) = x
mflowDefault (MortgageFlow3 _ _ _ _ _ _ _ _ x _ _ _) = x
mflowDefault (LoanFlow _ _ _ _ _ x _ _ _) = x
mflowDefault _ = error "not supported"

tsSetDate :: TsRow -> Date -> TsRow
tsSetDate (CashFlow _ a) x = CashFlow x a
tsSetDate (BondFlow _ a b c) x = BondFlow x a b c
Expand Down Expand Up @@ -366,7 +373,7 @@ mflowRecovery (MortgageFlow _ _ _ _ _ _ x _ _ _) = x
mflowRecovery (MortgageFlow2 _ _ _ _ _ _ _ x _ _) = x
mflowRecovery (MortgageFlow3 _ _ _ _ _ _ _ _ _ x _ _) = x
mflowRecovery (LoanFlow _ _ _ _ _ _ x _ _) = x
mflowRecovery _ = -1.0
mflowRecovery _ = error "not supported"

mflowBalance :: TsRow -> Balance
mflowBalance (MortgageFlow _ x _ _ _ _ _ _ _ _) = x
Expand Down
11 changes: 11 additions & 0 deletions src/Deal/DealQuery.hs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,17 @@ queryDeal t s =
in
futureDefaults + currentDefaults

CumulativePoolRecoveriesBalance ->
let
futureRecoveries = case P.futureCf (pool t) of
Just (CF.CashFlowFrame _historyTxn) -> sum $ CF.mflowRecovery <$> _historyTxn
Nothing -> 0.0
historyRecoveries = case P.issuanceStat (pool t) of
Just m -> Map.findWithDefault 0.0 P.HistoryRecoveries m
Nothing -> 0.0
in
futureRecoveries + historyRecoveries

CurrentBondBalanceOf bns ->
let
bSubMap = getBondByName t (Just bns) -- Map.filterWithKey (\bn b -> (S.member bn bnSet)) (bonds t)
Expand Down

0 comments on commit b41badd

Please sign in to comment.