Skip to content

Commit 19f3917

Browse files
authored
0.30.x Release (#231)
* fix revolv buy when building balanace; avoid duplicate run waterfall in call * bump version to-> < 0.29.6 > * fix multiple entity cf merge * bump version to-> < 0.29.7 > * "expose combo sensitivity endpoint" * expose pricing for bond groups * refactor on ledger booking * expose single clear ledger function * factor out pay liabilities by sequence * add bond prism * expose combo * expose writeoffBySeq * fix stmt consol * expose generic payProRata * minor cleanup * expose which pool to liquidate * add new assumption curve with padding last value to rest * fix cors problem * relax cf proj on mortgage * Fix Pool Agg Logic by create a new poolCf2 * expose extra Stress on ppy/def curve * bump version to-> < 0.29.9 > * Add var for recording current balance * bump version to-> < 0.29.10 > * correct begBalance for asset cashflow statuts * liquidate action refactor * remove future cashflow if liq a pool * update workflow * Fix if new bought cf is longer than original pool * bump version to-> < 0.29.11 > * Lift bought to performWrap * uplift clean up waterfall at end * bump version to-> < 0.29.12 > * fix if bought asset flow is zero * bump version to-> < 0.29.12 > * bump version to-> < 0.29.13 > * add missing txn comment for group bond int /prin * bump version to-> < 0.29.14 > * expose transferMultiple * bump version to-> < 0.29.15 > * avoid use infinity * update wf * bump version to-> < 0.29.16 > * bump version to-> < 0.29.17 > * fix wf * Fix Cumul calc on revolving pool * update UT * bump version to-> < 0.29.18 > * fix balance when merging * BUGFIX: use mergePoolCF2 instead of mergePoolCF1 * add bond stmt merge edge case * bump version to-> < 0.29.20 > * expose date/int range/set predicate * expose credit calculation type for liqProvider * expose PV when liquidate pool * Use PvRate when liq * remove debug * bump version to-> < 0.30.1 > * minor fix on prin pay stmt * bump version to-> < 0.30.1 > * update action * bump version to-> < 0.30.2 > * fix Over drawn * bump version to-> < 0.30.3 > * fix accure day on liqFacility * bump version to-> < 0.30.4 > * Expose bond factor for single bond * include UT for liq * update changelog * FIX: query on borrower number on current asset * enhance: getPoolCurrentBal with pool id * FIX: balanceSheet with multiple pools * include logs in clean up actions * Fix log in trigger effects/action * bump version to-> < 0.30.5 > * new Call Options * expose before on date pattern * add truncate before/after for date pattern * bump version to-> < 0.30.8 > * add direction for payGroupPrin/payGroupInt * bump version to-> < 0.30.9 > * complete the txn direction * bump version to-> < 0.30.10 > * separate each pool balance on financial reports * patch runtime current balance at begin * transform balanacesheet to tree from table * new financial reports * bump version to-> < 0.31.0 > * bump version to-> < 0.31.1 > * normalized txn comment when agg * bump version to-> < 0.31.2 > * fix query on default balance/ defaulted rate * add safeDiv * Expose Error Message * Fix calcFee and financial reports * First test for Error Message version * bump version to-> < 0.40.1 >
1 parent 42208a6 commit 19f3917

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+4308
-2792
lines changed

.github/workflows/docker-image-dev-by-tag.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ jobs:
3030
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
3131
with:
3232
images: yellowbean/hastructure
33+
tags: |
34+
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'master') }}
3335
3436
- name: 'Cleanup build folder'
3537
run: |

ChangeLog.md

Lines changed: 373 additions & 4 deletions
Large diffs are not rendered by default.

Hastructure.cabal

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 1.12
22

3-
-- This file has been generated from package.yaml by hpack version 0.35.2.
3+
-- This file has been generated from package.yaml by hpack version 0.36.0.
44
--
55
-- see: https://github.com/sol/hpack
66

@@ -78,12 +78,15 @@ library
7878
, containers
7979
, generic-lens
8080
, hashable
81+
, ieee754
8182
, lens
83+
, monad-loops
8284
, numeric-limits
8385
, openapi3
8486
, regex-base
8587
, regex-pcre-builtin
8688
, regex-tdfa
89+
, scientific
8790
, servant
8891
, servant-openapi3
8992
, servant-server
@@ -118,8 +121,10 @@ executable Hastructure-exe
118121
, generic-lens
119122
, hashable
120123
, http-types
124+
, ieee754
121125
, lens
122126
, lucid
127+
, monad-loops
123128
, mtl
124129
, numeric-limits
125130
, openapi3
@@ -159,6 +164,7 @@ test-suite Hastructure-test
159164
UT.AssetTest
160165
UT.BondTest
161166
UT.CashflowTest
167+
UT.CeTest
162168
UT.DealTest
163169
UT.DealTest2
164170
UT.ExpTest
@@ -181,12 +187,15 @@ test-suite Hastructure-test
181187
, containers
182188
, generic-lens
183189
, hashable
190+
, ieee754
184191
, lens
192+
, monad-loops
185193
, numeric-limits
186194
, openapi3
187195
, regex-base
188196
, regex-pcre-builtin
189197
, regex-tdfa
198+
, scientific
190199
, servant
191200
, servant-openapi3
192201
, servant-server

app/Main.hs

Lines changed: 87 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import System.Environment
1717

1818
import Control.Monad.Catch (MonadCatch, MonadThrow (..))
1919
import Control.Monad.IO.Class (liftIO)
20+
import Control.Monad (mapM)
2021
import Control.Exception (Exception,throwIO,throw)
2122
import Control.Monad.Except
2223
import Control.Monad.Reader
@@ -86,15 +87,26 @@ import qualified Revolving as RV
8687
import qualified Lib
8788
import qualified Util as U
8889
import qualified DateUtil as DU
89-
9090
-- import Servant.Checked.Exceptions (NoThrow, Throws)
9191
-- import Servant.Checked.Exceptions.Internal.Servant.API (ErrStatus(toErrStatus))
9292

93+
import Data.Scientific (fromRationalRepetend,formatScientific, Scientific,FPFormat(Fixed))
94+
import Control.Lens
9395
import Debug.Trace
9496
import qualified Types as W
9597
import Cashflow (patchCumulative)
98+
99+
96100
debug = flip Debug.Trace.trace
97101

102+
103+
-- instance ToJSON (Ratio Integer) where
104+
-- toJSON r = case fromRationalRepetend Nothing r of
105+
-- Left (sci, _) -> toJSON $ formatScientific Fixed (Just 8) sci
106+
-- -- Right (sci, rep) -> object ["repetend" .= rep, "fraction" .= sci]
107+
-- Right (sci, rep) -> toJSON $ formatScientific Fixed (Just 8) sci
108+
109+
98110
data Version = Version
99111
{ _version :: String
100112
} deriving (Eq, Show, Generic)
@@ -103,7 +115,7 @@ $(deriveJSON defaultOptions ''Version)
103115
instance ToSchema Version
104116

105117
version1 :: Version
106-
version1 = Version "0.29.17"
118+
version1 = Version "0.40.1"
107119

108120

109121

@@ -175,6 +187,7 @@ instance ToSchema W.Action
175187
instance ToSchema W.BookType
176188
instance ToSchema W.CollectionRule
177189
instance ToSchema C.CallOption
190+
instance ToSchema CE.LiqCreditCalc
178191
instance ToSchema CE.LiqFacility
179192
instance ToSchema HE.RateSwap
180193
instance ToSchema HE.RateSwapType
@@ -200,6 +213,8 @@ instance ToSchema AP.IssueBondEvent
200213
instance ToSchema (TsPoint AP.IssueBondEvent)
201214
instance ToSchema (TsPoint AP.RefiEvent)
202215
instance ToSchema AP.RefiEvent
216+
instance ToSchema AP.InspectType
217+
instance ToSchema AP.CallOpt
203218
instance ToSchema AP.NonPerfAssumption
204219
instance ToSchema AP.BondPricingInput
205220
instance ToSchema AP.RevolvingAssumption
@@ -253,41 +268,41 @@ instance ToSchema ResultComponent
253268
instance ToSchema L.PriceResult
254269
instance ToSchema DealType
255270

256-
type RunResp = (DealType , Maybe (Map.Map PoolId CF.CashFlowFrame), Maybe [ResultComponent],Maybe (Map.Map String L.PriceResult))
271+
type RunResp = Either String (DealType , Maybe (Map.Map PoolId CF.CashFlowFrame), Maybe [ResultComponent],Maybe (Map.Map String L.PriceResult))
257272

258273
wrapRun :: DealType -> Maybe AP.ApplyAssumptionType -> AP.NonPerfAssumption -> RunResp
259-
wrapRun (MDeal d) mAssump mNonPerfAssump = let
260-
(_d,_pflow,_rs,_p) = D.runDeal d D.DealPoolFlowPricing mAssump mNonPerfAssump
261-
in
262-
(MDeal _d,_pflow,_rs,_p) -- `debug` ("Run Done with deal->"++ show _d)
263-
wrapRun (RDeal d) mAssump mNonPerfAssump = let
264-
(_d,_pflow,_rs,_p) = D.runDeal d D.DealPoolFlowPricing mAssump mNonPerfAssump
265-
in
266-
(RDeal _d,_pflow,_rs,_p)
267-
wrapRun (IDeal d) mAssump mNonPerfAssump = let
268-
(_d,_pflow,_rs,_p) = D.runDeal d D.DealPoolFlowPricing mAssump mNonPerfAssump
269-
in
270-
(IDeal _d,_pflow,_rs,_p)
271-
wrapRun (LDeal d) mAssump mNonPerfAssump = let
272-
(_d,_pflow,_rs,_p) = D.runDeal d D.DealPoolFlowPricing mAssump mNonPerfAssump
273-
in
274-
(LDeal _d,_pflow,_rs,_p)
275-
wrapRun (FDeal d) mAssump mNonPerfAssump = let
276-
(_d,_pflow,_rs,_p) = D.runDeal d D.DealPoolFlowPricing mAssump mNonPerfAssump
277-
in
278-
(FDeal _d,_pflow,_rs,_p)
279-
wrapRun (UDeal d) mAssump mNonPerfAssump = let
280-
(_d,_pflow,_rs,_p) = D.runDeal d D.DealPoolFlowPricing mAssump mNonPerfAssump
281-
in
282-
(UDeal _d,_pflow,_rs,_p)
283-
wrapRun (VDeal d) mAssump mNonPerfAssump = let
284-
(_d,_pflow,_rs,_p) = D.runDeal d D.DealPoolFlowPricing mAssump mNonPerfAssump
285-
in
286-
(VDeal _d,_pflow,_rs,_p)
287-
wrapRun (PDeal d) mAssump mNonPerfAssump = let
288-
(_d,_pflow,_rs,_p) = D.runDeal d D.DealPoolFlowPricing mAssump mNonPerfAssump
289-
in
290-
(PDeal _d,_pflow,_rs,_p)
274+
wrapRun (MDeal d) mAssump mNonPerfAssump
275+
= do
276+
(_d,_pflow,_rs,_p) <- D.runDeal d D.DealPoolFlowPricing mAssump mNonPerfAssump
277+
return (MDeal _d,_pflow,_rs,_p) -- `debug` ("Run Done with deal->"++ show _d)
278+
wrapRun (RDeal d) mAssump mNonPerfAssump
279+
= do
280+
(_d,_pflow,_rs,_p) <- D.runDeal d D.DealPoolFlowPricing mAssump mNonPerfAssump
281+
return (RDeal _d,_pflow,_rs,_p)
282+
wrapRun (IDeal d) mAssump mNonPerfAssump
283+
= do
284+
(_d,_pflow,_rs,_p) <- D.runDeal d D.DealPoolFlowPricing mAssump mNonPerfAssump
285+
return (IDeal _d,_pflow,_rs,_p)
286+
wrapRun (LDeal d) mAssump mNonPerfAssump
287+
= do
288+
(_d,_pflow,_rs,_p) <- D.runDeal d D.DealPoolFlowPricing mAssump mNonPerfAssump
289+
return (LDeal _d,_pflow,_rs,_p)
290+
wrapRun (FDeal d) mAssump mNonPerfAssump
291+
= do
292+
(_d,_pflow,_rs,_p) <- D.runDeal d D.DealPoolFlowPricing mAssump mNonPerfAssump
293+
return (FDeal _d,_pflow,_rs,_p)
294+
wrapRun (UDeal d) mAssump mNonPerfAssump
295+
= do
296+
(_d,_pflow,_rs,_p) <- D.runDeal d D.DealPoolFlowPricing mAssump mNonPerfAssump
297+
return (UDeal _d,_pflow,_rs,_p)
298+
wrapRun (VDeal d) mAssump mNonPerfAssump
299+
= do
300+
(_d,_pflow,_rs,_p) <- D.runDeal d D.DealPoolFlowPricing mAssump mNonPerfAssump
301+
return (VDeal _d,_pflow,_rs,_p)
302+
wrapRun (PDeal d) mAssump mNonPerfAssump
303+
= do
304+
(_d,_pflow,_rs,_p) <- D.runDeal d D.DealPoolFlowPricing mAssump mNonPerfAssump
305+
return (PDeal _d,_pflow,_rs,_p)
291306

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

@@ -303,13 +318,17 @@ data PoolTypeWrap = LPool (DB.PoolType AB.Loan)
303318
deriving(Show, Generic)
304319

305320

306-
type RunPoolTypeRtn = Map.Map PoolId (CF.CashFlowFrame, Map.Map CutoffFields Balance)
321+
type RunPoolTypeRtn_ = Map.Map PoolId (CF.CashFlowFrame, Map.Map CutoffFields Balance)
322+
type RunPoolTypeRtn = Either String RunPoolTypeRtn_
307323

308-
patchCumulativeToPoolRun :: RunPoolTypeRtn -> RunPoolTypeRtn
309-
patchCumulativeToPoolRun = Map.map
310-
(\(CF.CashFlowFrame _ txns,stats) -> (CF.CashFlowFrame (0,Lib.toDate "19000101",Nothing) (CF.patchCumulative (0,0,0,0,0,0) [] txns),stats))
324+
patchCumulativeToPoolRun :: RunPoolTypeRtn_ -> RunPoolTypeRtn_
325+
patchCumulativeToPoolRun
326+
= Map.map
327+
(\(CF.CashFlowFrame _ txns,stats) ->
328+
(CF.CashFlowFrame (0,Lib.toDate "19000101",Nothing) (CF.patchCumulative (0,0,0,0,0,0) [] txns),stats)
329+
)
311330

312-
wrapRunPoolType :: PoolTypeWrap -> Maybe AP.ApplyAssumptionType -> Maybe [RateAssumption] -> RunPoolTypeRtn
331+
wrapRunPoolType :: PoolTypeWrap -> Maybe AP.ApplyAssumptionType -> Maybe [RateAssumption] -> RunPoolTypeRtn
313332
wrapRunPoolType (MPool pt) assump mRates = D.runPoolType pt assump $ Just (AP.NonPerfAssumption{AP.interest = mRates})
314333
wrapRunPoolType (LPool pt) assump mRates = D.runPoolType pt assump $ Just (AP.NonPerfAssumption{AP.interest = mRates})
315334
wrapRunPoolType (IPool pt) assump mRates = D.runPoolType pt assump $ Just (AP.NonPerfAssumption{AP.interest = mRates})
@@ -326,21 +345,28 @@ data RunAssetReq = RunAssetReq Date [AB.AssetUnion] (Maybe AP.ApplyAssumptionTyp
326345

327346
instance ToSchema RunAssetReq
328347

329-
wrapRunAsset :: RunAssetReq -> ((CF.CashFlowFrame, Map.Map CutoffFields Balance), Maybe [PriceResult])
348+
type RunAssetResp = Either String ((CF.CashFlowFrame, Map.Map CutoffFields Balance), Maybe [PriceResult])
349+
350+
351+
wrapRunAsset :: RunAssetReq -> RunAssetResp
330352
wrapRunAsset (RunAssetReq d assets Nothing mRates Nothing)
331-
= (P.aggPool Nothing ((\a -> (MA.calcAssetUnion a d mRates, Map.empty)) <$> assets), Nothing)
353+
= do
354+
cfs <- sequenceA $ (\a -> MA.calcAssetUnion a d mRates) <$> assets
355+
return (P.aggPool Nothing [(cf,Map.empty) | cf <- cfs], Nothing)
332356
wrapRunAsset (RunAssetReq d assets (Just (AP.PoolLevel assumps)) mRates Nothing)
333-
= (P.aggPool Nothing ((\a -> MA.projAssetUnion a d assumps mRates) <$> assets), Nothing)
357+
= do
358+
cfs <- sequenceA $ (\a -> MA.projAssetUnion a d assumps mRates) <$> assets
359+
return (P.aggPool Nothing [(cf,Map.empty) | (cf,_) <- cfs] , Nothing)
334360

335361
wrapRunAsset (RunAssetReq d assets (Just (AP.PoolLevel assumps)) mRates (Just pm))
336-
= let
337-
assetCf = P.aggPool Nothing $ (\a -> D.projAssetUnion a d assumps mRates ) <$> assets
338-
pricingResult = (\a -> D.priceAssetUnion a d pm assumps mRates) <$> assets
339-
in
340-
(assetCf , Just pricingResult)
362+
=
363+
do
364+
cfs <- sequenceA $ (\a -> MA.projAssetUnion a d assumps mRates) <$> assets
365+
pricingResult <- sequenceA $ (\a -> D.priceAssetUnion a d pm assumps mRates) <$> assets
366+
let assetCf = P.aggPool Nothing cfs
367+
return (assetCf , Just pricingResult)
341368

342369
--TODO implement on running via ByIndex
343-
344370
type ScenarioName = String
345371

346372
data RunDealReq = SingleRunReq DealType (Maybe AP.ApplyAssumptionType) AP.NonPerfAssumption
@@ -374,10 +400,10 @@ $(concat <$> traverse (deriveJSON defaultOptions) [''RunDealReq, ''RunPoolReq,''
374400
-- Swagger API
375401
type SwaggerAPI = "swagger.json" :> Get '[JSON] OpenApi
376402

377-
type PoolRunResp = Map.Map PoolId (CF.CashFlowFrame, Map.Map CutoffFields Balance)
403+
type PoolRunResp = Either String (Map.Map PoolId (CF.CashFlowFrame, Map.Map CutoffFields Balance))
378404

379405
type EngineAPI = "version" :> Get '[JSON] Version
380-
:<|> "runAsset" :> ReqBody '[JSON] RunAssetReq :> Post '[JSON] ((CF.CashFlowFrame, Map.Map CutoffFields Balance),Maybe [PriceResult])
406+
:<|> "runAsset" :> ReqBody '[JSON] RunAssetReq :> Post '[JSON] RunAssetResp
381407
:<|> "runPool" :> ReqBody '[JSON] RunPoolReq :> Post '[JSON] PoolRunResp
382408
:<|> "runPoolByScenarios" :> ReqBody '[JSON] RunPoolReq :> Post '[JSON] (Map.Map ScenarioName PoolRunResp)
383409
:<|> "runDeal" :> ReqBody '[JSON] RunDealReq :> Post '[JSON] RunResp
@@ -402,20 +428,24 @@ engineSwagger = toOpenApi engineAPI
402428
& info.license ?~ "BSD 3"
403429

404430

405-
406431
-- showVersion :: Handler (Envelope '[] Version)
407432
showVersion :: Handler Version
408433
showVersion = return version1
409434

410-
runAsset :: RunAssetReq -> Handler ((CF.CashFlowFrame, Map.Map CutoffFields Balance),Maybe [PriceResult])
411-
runAsset req = return $ wrapRunAsset req
435+
runAsset :: RunAssetReq -> Handler RunAssetResp
436+
runAsset req = return $
437+
wrapRunAsset req
412438

413439
runPool :: RunPoolReq -> Handler PoolRunResp
414-
runPool (SingleRunPoolReq pt passumption mRates) = return $ patchCumulativeToPoolRun $ wrapRunPoolType pt passumption mRates
440+
runPool (SingleRunPoolReq pt passumption mRates)
441+
= return $
442+
patchCumulativeToPoolRun <$> (wrapRunPoolType pt passumption mRates)
415443

416444
runPoolScenarios :: RunPoolReq -> Handler (Map.Map ScenarioName PoolRunResp)
417-
runPoolScenarios (MultiScenarioRunPoolReq pt mAssumps mRates) = return $ Map.map (\assump -> patchCumulativeToPoolRun (wrapRunPoolType pt (Just assump) mRates))
418-
mAssumps
445+
runPoolScenarios (MultiScenarioRunPoolReq pt mAssumps mRates)
446+
= return $ Map.map (\assump ->
447+
patchCumulativeToPoolRun <$> (wrapRunPoolType pt (Just assump) mRates))
448+
mAssumps
419449

420450
runDeal :: RunDealReq -> Handler RunResp
421451
runDeal (SingleRunReq dt assump nonPerfAssump) = return $ wrapRun dt assump nonPerfAssump
@@ -461,7 +491,6 @@ myServer = return engineSwagger
461491
:<|> runDealByRunScenarios
462492
:<|> runDealByCombo
463493
:<|> runDate
464-
-- :<|> error "not implemented"
465494

466495

467496
writeSwaggerJSON :: IO ()
@@ -477,7 +506,6 @@ app :: Application
477506
app = simpleCors $ serve (Proxy :: Proxy API) myServer
478507

479508

480-
481509
main :: IO ()
482510
main =
483511
do

package.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ dependencies:
3636
- regex-pcre-builtin
3737
- vector
3838
- wai
39+
- monad-loops
40+
- ieee754
3941
- servant
4042
- servant-server
4143
- servant-openapi3
@@ -44,6 +46,7 @@ dependencies:
4446
- split
4547
- tabular
4648
- numeric-limits
49+
- scientific
4750

4851
library:
4952
source-dirs:
@@ -78,6 +81,7 @@ executables:
7881
- mtl
7982
- servant
8083
- lucid
84+
- monad-loops
8185
- string-conversions
8286
- attoparsec
8387
- exceptions
@@ -104,4 +108,4 @@ tests:
104108
- tasty-golden
105109

106110

107-
allow-newer: true
111+
allow-newer: true

0 commit comments

Comments
 (0)