Skip to content

Commit 939683f

Browse files
committed
Fix UT
1 parent cd5ba17 commit 939683f

Some content is hidden

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

61 files changed

+45177
-45041
lines changed

absbox/local/component.py

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,27 +1472,28 @@ def id_by_pool_assets(z):
14721472
case _:
14731473
raise RuntimeError(f"Failed to identify deal type {z}")
14741474
y = None
1475-
#if query(x, ["pool","tag"])=='SoloPool':
1476-
if tz.get_in(["pool","tag"], x)=='SoloPool':
1477-
return id_by_pool_assets(x["pool"]['contents'])
1478-
elif "pool" in x and set(x.keys()) == {"pool"}:
1479-
return id_by_pool_assets(x['pool'])
1480-
elif "pool" in x and x["pool"]['tag']=='MultiPool':
1481-
assetTags = lens['pool']['contents'].Values()['assets'][0]['tag'].collect()(x)
1482-
if len(set(assetTags))>1:
1483-
return "UDeal"
1484-
else:
1485-
return id_by_pool_assets(list(x["pool"]['contents'].values())[0])
1486-
elif "ResecDeal" == x['pool']['tag']:
1487-
vs = [ v['deal'] for k,v in x["pool"]['contents'].items() ]
1488-
assetTypes = set(map(identify_deal_type, vs))
1489-
if len(assetTypes)>1:
1490-
return "UDeal"
1491-
else:
1492-
return list(assetTypes)[0]
1493-
else:
1494-
raise RuntimeError(f"Failed to match pool type {x}")
1475+
match x:
1476+
case {"pool":{"tag":"MultiPool","contents":{"PoolConsol":{"assets":[]}}}} if len(x['pool']['contents']['PoolConsol']['futureCf'])>0:
1477+
return id_by_pool_assets(x['pool']['contents']['PoolConsol'])
1478+
case {"pool":{"tag":"MultiPool","contents":{"PoolConsol":{"assets":assetList}}}} if len(assetList) > 1:
1479+
return id_by_pool_assets(x['pool']['contents']['PoolConsol'])
1480+
case {"pool":{"tag":"MultiPool","contents":poolMap}}:
1481+
pools = list(map(id_by_pool_assets, poolMap & lens.Values().collect()))
14951482

1483+
if len(set(pools))>1:
1484+
return "UDeal"
1485+
else:
1486+
return pools[0]
1487+
case {"pool":{"tag":"ResecDeal"}}:
1488+
vs = [ v['deal'] for k,v in x["pool"]['contents'].items() ]
1489+
assetTypes = set(map(identify_deal_type, vs))
1490+
if len(assetTypes)>1:
1491+
return "UDeal"
1492+
else:
1493+
print(assetTypes, "<<<")
1494+
return list(assetTypes)[0]
1495+
case _:
1496+
raise RuntimeError(f"Failed to match pool type {x}")
14961497

14971498

14981499
def mkCallOptionsLegacy(x):
@@ -1763,14 +1764,29 @@ def mkRevolvingPool(x):
17631764

17641765

17651766
def mkPoolType(assetDate, x, mixedFlag) -> dict:
1766-
if 'assets' in x or "清单" in x or "归集表" in x:
1767-
return mkTag(("SoloPool" ,mkPoolComp(vDate(assetDate), x, False)))
1768-
elif 'deals' in x and isinstance(x['deals'],dict):
1769-
return mkTag(("ResecDeal",{f"{dealObj.json['contents']['name']}:{bn}:{sd}:{str(pct)}": \
1770-
{"deal":dealObj.json['contents'],"future":None,"futureScheduleCf":None,"issuanceStat":None}\
1771-
for ((bn,pct,sd),dealObj) in x['deals'].items()} ))
1772-
else:
1773-
return mkTag(("MultiPool" ,{f"PoolName:{k}":mkPoolComp(vDate(assetDate),v,mixedFlag) for (k,v) in x.items()}))
1767+
# try:
1768+
# if 'assets' in x or "清单" in x or "归集表" in x:
1769+
# return mkTag(("MultiPool" ,{"PoolConsol":mkPoolComp(vDate(assetDate), x, False)}))
1770+
# elif 'deals' in x and isinstance(x['deals'],dict):
1771+
# return mkTag(("ResecDeal",{f"{dealObj.json['contents']['name']}:{bn}:{sd}:{str(pct)}": \
1772+
# {"deal":dealObj.json['contents'],"future":None,"futureScheduleCf":None,"issuanceStat":None}\
1773+
# for ((bn,pct,sd),dealObj) in x['deals'].items()} ))
1774+
# else:
1775+
# return mkTag(("MultiPool" ,{f"PoolName:{k}":mkPoolComp(vDate(assetDate),v,mixedFlag) for (k,v) in x.items()}))
1776+
# except Exception as e:
1777+
# print("Error in mk pool type",e)
1778+
1779+
match x:
1780+
case {"assets": y} | {"清单": y} | {"归集表": y}:
1781+
return mkTag(("MultiPool" ,{"PoolConsol":mkPoolComp(vDate(assetDate), x, False)}))
1782+
case {"deals": y} if isinstance(y, dict):
1783+
return mkTag(("ResecDeal",{f"{dealObj.json['contents']['name']}:{bn}:{sd}:{str(pct)}": \
1784+
{"deal":dealObj.json['contents'],"future":None,"futureScheduleCf":None,"issuanceStat":None}\
1785+
for ((bn,pct,sd),dealObj) in x['deals'].items()} ))
1786+
case x if all([ isinstance(_,dict) for _ in x.values() ]):
1787+
return mkTag(("MultiPool" ,{f"PoolName:{k}":mkPoolComp(vDate(assetDate),v,mixedFlag) for (k,v) in x.items()}))
1788+
case _ :
1789+
raise RuntimeError("Failed to match pool type ",x)
17741790

17751791

17761792
def mkPoolComp(asOfDate, x, mixFlag) -> dict:

absbox/tests/benchmark/china/out/test01.json

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -31,46 +31,48 @@
3131
}
3232
},
3333
"pool": {
34-
"tag": "SoloPool",
34+
"tag": "MultiPool",
3535
"contents": {
36-
"assets": [
37-
{
38-
"tag": "Mortgage",
39-
"contents": [
40-
{
41-
"originBalance": 120,
42-
"originRate": {
43-
"tag": "Fix",
44-
"contents": [
45-
"DC_ACT_365F",
46-
0.045
47-
]
48-
},
49-
"originTerm": 30,
50-
"period": "Monthly",
51-
"startDate": "2021-02-01",
52-
"prinType": {
53-
"tag": "Even"
36+
"PoolConsol": {
37+
"assets": [
38+
{
39+
"tag": "Mortgage",
40+
"contents": [
41+
{
42+
"originBalance": 120,
43+
"originRate": {
44+
"tag": "Fix",
45+
"contents": [
46+
"DC_ACT_365F",
47+
0.045
48+
]
49+
},
50+
"originTerm": 30,
51+
"period": "Monthly",
52+
"startDate": "2021-02-01",
53+
"prinType": {
54+
"tag": "Even"
55+
},
56+
"prepaymentPenalty": null,
57+
"obligor": null,
58+
"tag": "MortgageOriginalInfo"
5459
},
55-
"prepaymentPenalty": null,
56-
"obligor": null,
57-
"tag": "MortgageOriginalInfo"
58-
},
59-
120,
60-
0.08,
61-
20,
62-
null,
63-
{
64-
"tag": "Current"
65-
}
66-
]
60+
120,
61+
0.08,
62+
20,
63+
null,
64+
{
65+
"tag": "Current"
66+
}
67+
]
68+
}
69+
],
70+
"asOfDate": "2021-03-31",
71+
"issuanceStat": null,
72+
"futureCf": null,
73+
"extendPeriods": {
74+
"tag": "MonthEnd"
6775
}
68-
],
69-
"asOfDate": "2021-03-31",
70-
"issuanceStat": null,
71-
"futureCf": null,
72-
"extendPeriods": {
73-
"tag": "MonthEnd"
7476
}
7577
}
7678
},

absbox/tests/benchmark/china/out/test02.json

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -31,46 +31,48 @@
3131
}
3232
},
3333
"pool": {
34-
"tag": "SoloPool",
34+
"tag": "MultiPool",
3535
"contents": {
36-
"assets": [
37-
{
38-
"tag": "Mortgage",
39-
"contents": [
40-
{
41-
"originBalance": 120,
42-
"originRate": {
43-
"tag": "Fix",
44-
"contents": [
45-
"DC_ACT_365F",
46-
0.0485
47-
]
36+
"PoolConsol": {
37+
"assets": [
38+
{
39+
"tag": "Mortgage",
40+
"contents": [
41+
{
42+
"originBalance": 120,
43+
"originRate": {
44+
"tag": "Fix",
45+
"contents": [
46+
"DC_ACT_365F",
47+
0.0485
48+
]
49+
},
50+
"originTerm": 30,
51+
"period": "Monthly",
52+
"startDate": "2020-06-01",
53+
"prinType": {
54+
"tag": "Even"
55+
},
56+
"prepaymentPenalty": null,
57+
"obligor": null,
58+
"tag": "MortgageOriginalInfo"
4859
},
49-
"originTerm": 30,
50-
"period": "Monthly",
51-
"startDate": "2020-06-01",
52-
"prinType": {
53-
"tag": "Even"
54-
},
55-
"prepaymentPenalty": null,
56-
"obligor": null,
57-
"tag": "MortgageOriginalInfo"
58-
},
59-
120,
60-
0.08,
61-
10,
62-
null,
63-
{
64-
"tag": "Current"
65-
}
66-
]
60+
120,
61+
0.08,
62+
10,
63+
null,
64+
{
65+
"tag": "Current"
66+
}
67+
]
68+
}
69+
],
70+
"asOfDate": "2021-03-01",
71+
"issuanceStat": null,
72+
"futureCf": null,
73+
"extendPeriods": {
74+
"tag": "MonthEnd"
6775
}
68-
],
69-
"asOfDate": "2021-03-01",
70-
"issuanceStat": null,
71-
"futureCf": null,
72-
"extendPeriods": {
73-
"tag": "MonthEnd"
7476
}
7577
}
7678
},

absbox/tests/benchmark/china/out/test03.json

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -31,54 +31,56 @@
3131
}
3232
},
3333
"pool": {
34-
"tag": "SoloPool",
34+
"tag": "MultiPool",
3535
"contents": {
36-
"assets": [
37-
{
38-
"tag": "Mortgage",
39-
"contents": [
40-
{
41-
"originBalance": 120,
42-
"originRate": {
43-
"tag": "Floater",
44-
"contents": [
45-
"DC_ACT_365F",
46-
"LPR5Y",
47-
0.01,
48-
0.085,
49-
{
50-
"tag": "MonthEnd"
51-
},
52-
null,
53-
null,
54-
null
55-
]
56-
},
57-
"originTerm": 30,
58-
"period": "Monthly",
59-
"startDate": "2020-06-01",
60-
"prinType": {
61-
"tag": "Even"
36+
"PoolConsol": {
37+
"assets": [
38+
{
39+
"tag": "Mortgage",
40+
"contents": [
41+
{
42+
"originBalance": 120,
43+
"originRate": {
44+
"tag": "Floater",
45+
"contents": [
46+
"DC_ACT_365F",
47+
"LPR5Y",
48+
0.01,
49+
0.085,
50+
{
51+
"tag": "MonthEnd"
52+
},
53+
null,
54+
null,
55+
null
56+
]
57+
},
58+
"originTerm": 30,
59+
"period": "Monthly",
60+
"startDate": "2020-06-01",
61+
"prinType": {
62+
"tag": "Even"
63+
},
64+
"prepaymentPenalty": null,
65+
"obligor": null,
66+
"tag": "MortgageOriginalInfo"
6267
},
63-
"prepaymentPenalty": null,
64-
"obligor": null,
65-
"tag": "MortgageOriginalInfo"
66-
},
67-
180,
68-
0.08,
69-
10,
70-
null,
71-
{
72-
"tag": "Current"
73-
}
74-
]
68+
180,
69+
0.08,
70+
10,
71+
null,
72+
{
73+
"tag": "Current"
74+
}
75+
]
76+
}
77+
],
78+
"asOfDate": "2021-03-01",
79+
"issuanceStat": null,
80+
"futureCf": null,
81+
"extendPeriods": {
82+
"tag": "MonthEnd"
7583
}
76-
],
77-
"asOfDate": "2021-03-01",
78-
"issuanceStat": null,
79-
"futureCf": null,
80-
"extendPeriods": {
81-
"tag": "MonthEnd"
8284
}
8385
}
8486
},

0 commit comments

Comments
 (0)