Skip to content

Commit

Permalink
enable calcInt custom
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowbean committed Dec 8, 2023
1 parent 94532b3 commit 1a4fcfe
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 9 deletions.
3 changes: 3 additions & 0 deletions Hastructure.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ library
, servant-errors
, servant-openapi3
, servant-server
, split
, swagger2
, template-haskell
, text
Expand Down Expand Up @@ -119,6 +120,7 @@ executable Hastructure-exe
, servant-errors
, servant-openapi3
, servant-server
, split
, string-conversions
, swagger2
, template-haskell
Expand Down Expand Up @@ -171,6 +173,7 @@ test-suite Hastructure-test
, servant-errors
, servant-openapi3
, servant-server
, split
, swagger2
, tasty
, tasty-golden
Expand Down
6 changes: 2 additions & 4 deletions src/Asset.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Asset (Pool(..),aggPool
,buildAssumptionPpyDefRecRate,buildAssumptionPpyDelinqDefRecRate
,calcRecoveriesFromDefault
,priceAsset,applyHaircut,buildPrepayRates,buildDefaultRates
,poolFutureCf,issuanceStat,assets,poolFutureTxn,poolIssuanceStat
,poolFutureCf,poolFutureTxn,poolIssuanceStat
) where

import qualified Data.Time as T
Expand Down Expand Up @@ -122,9 +122,7 @@ poolFutureTxn = lens getter setter
poolIssuanceStat :: Asset a => Lens' (Pool a) (Map.Map CutoffFields Balance)
poolIssuanceStat = lens getter setter
where
getter p = case issuanceStat p of
Nothing -> Map.empty
Just m -> m
getter p = fromMaybe Map.empty $ issuanceStat p
setter p m = case issuanceStat p of
Nothing -> p {issuanceStat = Just m}
Just m -> p {issuanceStat = Just m}
Expand Down
1 change: 0 additions & 1 deletion src/Cashflow.hs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,6 @@ firstDate (CashFlowFrame rs) = getDate $ head rs
combine :: CashFlowFrame -> CashFlowFrame -> CashFlowFrame
combine (CashFlowFrame txn1) (CashFlowFrame txn2) = CashFlowFrame $ combineTss [] txn1 txn2

-- ^ TODO need to make sure it will genreate empty row
aggTsByDates :: [TsRow] -> [Date] -> [TsRow]
aggTsByDates trs ds =
map
Expand Down
4 changes: 2 additions & 2 deletions src/Deal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ getInits t@TestDeal{fees=feeMap,pool=thePool,status=status,bonds=bndMap} mAssump
(MultiPool pm, Just (AP.ByName assumpMap))
-> Map.mapWithKey
(\k p -> P.aggPool(P.issuanceStat p) $
runPool p (AP.PoolLevel <$> (Map.lookup k assumpMap)) (AP.interest =<< mNonPerfAssump))
runPool p (AP.PoolLevel <$> Map.lookup k assumpMap) (AP.interest =<< mNonPerfAssump))
pm
(MultiPool pm,_)
-> Map.map (\p -> P.aggPool(P.issuanceStat p) $ runPool p mAssumps (AP.interest =<< mNonPerfAssump)) pm
Expand All @@ -734,7 +734,7 @@ getInits t@TestDeal{fees=feeMap,pool=thePool,status=status,bonds=bndMap} mAssump
poolAggCfM = Map.map (\x -> CF.aggTsByDates x (getDates pActionDates)) poolCfTsM
begRowM = Map.map (\x -> (buildBegTsRow startDate . head) x:[]) poolAggCfM
-- pCollectionCfAfterCutoff = CF.CashFlowFrame $ begRow:poolAggCf
pCollectionCfAfterCutoff = Map.map CF.CashFlowFrame $ Map.unionWith (\a b -> a++b) begRowM poolAggCfM
pCollectionCfAfterCutoff = Map.map CF.CashFlowFrame $ Map.unionWith (++) begRowM poolAggCfM
-- if preclosing deal , issuance balance is using beg balance of projected cashflow
-- if it is ongoing deal, issuance balance is user input ( deal is not aware of issuance balance as point of time)
-- issuanceBalance = case status t of
Expand Down
4 changes: 2 additions & 2 deletions src/Deal/DealAction.hs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ calcDueInt t calc_date mBal mRate b@(L.Bond bn bt bo bi _ bond_bal bond_rate _ i
_ -> DC_ACT_365F
overrideBal = maybe bond_bal (queryDeal t ) mBal
overrideRate = maybe bond_rate (queryDealRate t) mRate
newDueInt = IR.calcInt (overrideBal+intDue) int_due_date calc_date overrideRate dc -- `debug` ("Bond bal"++show bond_bal++">>"++show int_due_date++">>"++ show calc_date++">>"++show bond_rate)
newDueInt = IR.calcInt (overrideBal+intDue) int_due_date calc_date overrideRate dc -- `debug` ("Using Rate"++show overrideRate++">>Bal"++ show overrideBal)


calcDuePrin :: P.Asset a => TestDeal a -> T.Day -> L.Bond -> L.Bond
Expand Down Expand Up @@ -838,7 +838,7 @@ performAction d t@TestDeal{fees=feeMap} (W.CalcFee fns)
performAction d t@TestDeal{bonds=bndMap} (W.CalcBondInt bns mBalDs mRateDs)
= t {bonds = Map.union newBondMap bndMap}
where
newBondMap = Map.map (calcDueInt t d Nothing Nothing) $ getBondByName t (Just bns)
newBondMap = Map.map (calcDueInt t d mBalDs mRateDs) $ getBondByName t (Just bns)

performAction d t@TestDeal{accounts=accs, liqProvider = Just _liqProvider} (W.LiqSupport limit pName CE.LiqToAcc an)
= t { accounts = newAccMap, liqProvider = Just newLiqMap } -- `debug` ("Using LImit"++ show limit)
Expand Down
2 changes: 2 additions & 0 deletions src/Deal/DealQuery.hs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ queryDealRate t s =
FloorWith s floor -> toRational $ max (queryDealRate t s) (queryDealRate t floor)
FloorWithZero s -> toRational $ max (queryDealRate t s) 0
CapWith s cap -> toRational $ min (queryDealRate t s) (queryDealRate t cap)
Factor s r -> toRational $ (queryDealRate t s) * fromRational r


queryDealInt :: P.Asset a => TestDeal a -> DealStats -> Date -> Int
queryDealInt t@TestDeal{ pool = p ,bonds = bndMap } s d =
Expand Down

0 comments on commit 1a4fcfe

Please sign in to comment.