Skip to content

Commit

Permalink
fix read pool /single asset cf
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowbean committed May 27, 2024
1 parent 51e2589 commit 1ce32cf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
13 changes: 7 additions & 6 deletions absbox/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from absbox.local.util import mkTag,mapValsBy \
, _read_cf, _read_asset_pricing, mergeStrWithDict \
, earlyReturnNone, searchByFst, filter_by_tags \
, enumVals, lmap, inferPoolTypeFromAst
, enumVals, lmap, inferPoolTypeFromAst, getValWithKs
from absbox.local.component import mkPool, mkAssumpType, mkNonPerfAssumps, mkLiqMethod \
, mkAssetUnion, mkRateAssumption, mkDatePattern, mkPoolType

Expand Down Expand Up @@ -249,11 +249,12 @@ def build_pool_req(self, pool, poolAssump, rateAssumps, isMultiScenario=False) -
"""
r = None
_rateAssump = map(mkRateAssumption, rateAssumps) if rateAssumps else None
assetDate = pool['cutoffDate']
assetDate = getValWithKs(pool, ['cutoffDate', '封包日'])
#assetDate = pool['cutoffDate']

def buildPoolType(p) -> dict:
""" build type for `PoolTypeWrap` """
assetTag = inferPoolTypeFromAst(p) if 'assets' in p else "UPool"
assetTag = inferPoolTypeFromAst(p) if (('assets' in p) or ('清单' in p)) else "UPool"
_p = tz.dissoc(p, 'cutoffDate')
if assetTag == "UPool":
return mkTag((assetTag, mkPoolType(assetDate, _p, True)))
Expand Down Expand Up @@ -381,7 +382,7 @@ def read_single(self, pool_resp) -> tuple:
:rtype: tuple
"""
(pool_flow, pool_bals) = pool_resp
result = _read_cf(pool_flow['contents'], self.lang)
result = _read_cf(pool_flow['contents'][1], self.lang)
return (result, pool_bals)


Expand Down Expand Up @@ -509,7 +510,7 @@ def runAsset(self, date, _assets, poolAssump=None, rateAssump=None
def readResult(x):
try:
((cfs, cfBalance), pr) = x
cfs = _read_cf(cfs['contents'], self.lang)
cfs = _read_cf(cfs['contents'][1], self.lang)
pricingResult = _read_asset_pricing(pr, self.lang) if pr else None
return (cfs, cfBalance, pricingResult)
except Exception as e:
Expand Down Expand Up @@ -539,7 +540,7 @@ def runDates(self, d, dp):
:type d: date
:param dp: a date pattern
:type dp: date pattern
:return: a lsit of dates
:return: a list of dates
:rtype: list[date]
"""
url = f"{self.url}/{Endpoints.RunDate.value}"
Expand Down
11 changes: 5 additions & 6 deletions absbox/local/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,18 +280,17 @@ def guess_pool_flow_header(x, l):

def inferPoolTypeFromAst(x:dict) -> str:
match x:
case {"assets":[["Mortgage",*fields],*ast]} | {"assets":[["AdjustRateMortgage",*fields],*ast]}:
case {"assets":[["Mortgage",*fields],*ast]} | {"assets":[["AdjustRateMortgage",*fields],*ast]} | {'清单': [['按揭贷款', *fields], *ast]}:
return "MPool"
case {"assets":[["Loan",*fields],*ast]}:
case {"assets":[["Loan",*fields],*ast]} | {'清单': [['贷款', *fields], *ast]}:
return "LPool"
case {"assets":[["Installment",*fields],*ast]}:
case {"assets":[["Installment",*fields],*ast]} | {'清单': [['分期', *fields], *ast]}:
return "IPool"
case {"assets":[["Lease",*fields],*ast]}:
case {"assets":[["Lease",*fields],*ast]} | {'清单': [['租赁', *fields], *ast]}:
return "RPool"
case {"assets":[["FixedAsset",*fields],*ast]}:
return "FPool"

case {"assets":[["Invoice",*fields],*ast]}:
case {"assets":[["Invoice",*fields],*ast]} | {'清单': [['应收账款', *fields], *ast]}:
return "VPool"
case _:
raise RuntimeError(f"Failed to find pool type from assets:{x}")
Expand Down

0 comments on commit 1ce32cf

Please sign in to comment.