diff --git a/Hastructure.cabal b/Hastructure.cabal index 5daf482d..86795b67 100644 --- a/Hastructure.cabal +++ b/Hastructure.cabal @@ -81,6 +81,7 @@ library , servant-errors , servant-openapi3 , servant-server + , split , swagger2 , template-haskell , text @@ -119,6 +120,7 @@ executable Hastructure-exe , servant-errors , servant-openapi3 , servant-server + , split , string-conversions , swagger2 , template-haskell @@ -171,6 +173,7 @@ test-suite Hastructure-test , servant-errors , servant-openapi3 , servant-server + , split , swagger2 , tasty , tasty-golden diff --git a/src/Asset.hs b/src/Asset.hs index f674b099..a1426fa7 100644 --- a/src/Asset.hs +++ b/src/Asset.hs @@ -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 @@ -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} diff --git a/src/Cashflow.hs b/src/Cashflow.hs index 36e45a70..e71e6801 100644 --- a/src/Cashflow.hs +++ b/src/Cashflow.hs @@ -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 diff --git a/src/Deal.hs b/src/Deal.hs index dba9afe2..62cdced3 100644 --- a/src/Deal.hs +++ b/src/Deal.hs @@ -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 @@ -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 diff --git a/src/Deal/DealAction.hs b/src/Deal/DealAction.hs index 54eb5c89..b158478c 100644 --- a/src/Deal/DealAction.hs +++ b/src/Deal/DealAction.hs @@ -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 @@ -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) diff --git a/src/Deal/DealQuery.hs b/src/Deal/DealQuery.hs index 22b22157..7db5503a 100644 --- a/src/Deal/DealQuery.hs +++ b/src/Deal/DealQuery.hs @@ -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 =