from absbox import API,EnginePath
from numpy import nan
localAPI = API(EnginePath.DEV, lang='english', check=False)
Connecting engine server -> https://absbox.org/api/dev
/home/docs/checkouts/readthedocs.org/user_builds/absbox-doc/envs/stable/lib/python3.11/site-packages/urllib3/connectionpool.py:1097: InsecureRequestWarning: Unverified HTTPS request is being made to host 'absbox.org'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings
  warnings.warn(
✅Connected, local lib:0.52.3, server:0.52.3

Assumption By Term

m = ["Mortgage"
        ,{"originBalance": 12000.0
            ,"originRate": ["fix",0.045]
            ,"originTerm": 18
            ,"freq": "Monthly"
            ,"type": "Level"
            ,"originDate": "2021-02-01"}
        ,{"currentBalance": 10000.0
            ,"currentRate": 0.075
            ,"remainTerm": 12
            ,"status": "Current"}]

byTermAssump = [ [0.01]*9+[0.02]*9
                ,[0.02]*6+[0.03]*6
                ,[0.03]*3+[0.04]*3  ]

r = localAPI.runAsset("2020-01-02"
                     ,[m]
                     ,poolAssump=("Pool"
                                    ,("Mortgage", None, {"byTerm":byTermAssump}, None, None)
                                    ,None
                                    ,None)
                     ,read=True)
/home/docs/checkouts/readthedocs.org/user_builds/absbox-doc/envs/stable/lib/python3.11/site-packages/urllib3/connectionpool.py:1097: InsecureRequestWarning: Unverified HTTPS request is being made to host 'absbox.org'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings
  warnings.warn(
r[0].head()
Balance Principal Interest Prepayment Default Recovery Loss WAC BorrowerNum PrepayPenalty CumPrincipal CumPrepay CumDelinq CumDefault CumRecovery CumLoss
Date
2021-08-01 10000.00 0.00 0.00 0.00 0 0 0 0.075 None None 0.00 0.00 0 0 0 0
2021-09-01 9102.98 797.02 61.87 100.00 0 0 0 0.075 None None 797.02 100.00 0 0 0 0
2021-10-01 8217.97 793.99 56.32 91.02 0 0 0 0.075 None None 1591.01 191.02 0 0 0 0
2021-11-01 7344.84 790.96 50.84 82.17 0 0 0 0.075 None None 2381.97 273.19 0 0 0 0
2021-12-01 6417.96 779.99 44.98 146.89 0 0 0 0.075 None None 3161.96 420.08 0 0 0 0
i = ["Installment"
     ,{"originBalance": 1000.0
      ,"feeRate": ["fix",0.01]
      ,"originTerm": 12
      ,"freq": "Monthly"
      ,"type": "f_p"
      ,"originDate": "2022-01-01"}
      ,{"status": "Current"
        ,"currentBalance":1000
        ,"remainTerm":10}]
byTermAssump = [ [0.01]*9+[0.02]*9
                ,[0.02]*6+[0.03]*6
                ,[0.03]*3+[0.04]*3  ]

r = localAPI.runAsset("2020-01-02"
                     ,[i]
                     ,poolAssump=("Pool"
                                    ,("Installment", {"byTerm":byTermAssump}, None, None, None)
                                    ,None
                                    ,None)
                     ,read=True)
/home/docs/checkouts/readthedocs.org/user_builds/absbox-doc/envs/stable/lib/python3.11/site-packages/urllib3/connectionpool.py:1097: InsecureRequestWarning: Unverified HTTPS request is being made to host 'absbox.org'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings
  warnings.warn(
r[0].head(5)
Balance Principal Interest Prepayment Default Recovery Loss WAC CumPrincipal CumPrepay CumDelinq CumDefault CumRecovery CumLoss
Date
2022-03-01 1000.00 0.00 0.00 0 0.00 0 0.00 0.01 0.00 0 0 0.00 0 0.00
2022-04-01 882.01 97.99 11.75 0 20.00 0 20.00 0.01 97.99 0 0 20.00 0 20.00
2022-05-01 768.34 96.03 11.52 0 17.64 0 17.64 0.01 194.02 0 0 37.64 0 37.64
2022-06-01 658.87 94.11 11.29 0 15.36 0 15.36 0.01 288.13 0 0 53.00 0 53.00
2022-07-01 553.47 92.23 11.06 0 13.17 0 13.17 0.01 380.36 0 0 66.17 0 66.17
l = ["Loan"
      ,{"originBalance": 80000
        ,"originRate": ["fix",0.045]
        ,"originTerm": 18
        ,"freq": "SemiAnnually"
        ,"type": "i_p"
        ,"originDate": "2021-03-01"}
      ,{"currentBalance": 65000
        ,"currentRate": 0.06
        ,"remainTerm": 12
        ,"status": "Current"}]

r = localAPI.runAsset("2020-01-02"
                     ,[l]
                     ,poolAssump=("Pool"
                                    ,("Loan", {"byTerm":byTermAssump}, None, None, None)
                                    ,None
                                    ,None)
                     ,read=True)
/home/docs/checkouts/readthedocs.org/user_builds/absbox-doc/envs/stable/lib/python3.11/site-packages/urllib3/connectionpool.py:1097: InsecureRequestWarning: Unverified HTTPS request is being made to host 'absbox.org'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings
  warnings.warn(
r[0].head(5)
Balance Principal Interest Prepayment Default Recovery Loss WAC CumPrincipal CumPrepay CumDelinq CumDefault CumRecovery CumLoss
Date
2024-03-01 65000.00 0.0 0.00 0 0.00 0 0.00 0.06 0.0 0 0 0.00 0 0.00
2024-09-01 64350.00 0.0 1946.36 0 650.00 0 650.00 0.06 0.0 0 0 650.00 0 650.00
2025-03-01 63706.50 0.0 1895.48 0 643.50 0 643.50 0.06 0.0 0 0 1293.50 0 1293.50
2025-09-01 63069.44 0.0 1907.63 0 637.06 0 637.06 0.06 0.0 0 0 1930.56 0 1930.56
2026-03-01 61808.06 0.0 1839.00 0 1261.38 0 1261.38 0.06 0.0 0 0 3191.94 0 3191.94

Combination with Tag

User can make further strats on applying assumpition in smaller granularity

ob1 = {
    "id":"1",
    "tag":["A","B"],
    "fields":{"age":30,"creditLevel":"A"}
} 

ob2 = {
    "id":"2",
    "tag":["C","B"],
    "fields":{"age":50,"creditLevel":"B"}
} 


myAsset1 = ["Mortgage"
            ,{"originBalance": 12000.0
             ,"originRate": ["fix",0.045]
             ,"originTerm": 20
             ,"freq": "monthly"
             ,"type": "level"
             ,"originDate": "2021-02-01"
             ,"obligor":ob1
             }
            ,{"currentBalance": 2000.0
             ,"currentRate": 0.075
             ,"remainTerm": 8
             ,"status": "current"}]
myAsset2 = ["Mortgage"
            ,{"originBalance": 12000.0
             ,"originRate": ["fix",0.045]
             ,"originTerm": 20
             ,"freq": "monthly"
             ,"type": "level"
             ,"originDate": "2021-02-01"
             ,"obligor":ob2
             }
            ,{"currentBalance": 5000.0
             ,"currentRate": 0.075
             ,"remainTerm": 8
             ,"status": "current"}]

myPool = {'assets':[myAsset1,myAsset2],
          'cutoffDate':"2022-03-01"}
byTermAssump = [ [0.01]*10+[0.02]*10
                ,[0.03]*3+[0.04]*3  ]

ppyAssump = (("Mortgage",None ,{"byTerm":byTermAssump}, None, None)
             ,None
             ,None)
defAssump = (("Mortgage",{"CDR":0.2} ,None, None, None)
             ,None
             ,None)

AssetLevelAssumption = ("ByObligor"
                        ,("ByField",[("creditLevel","in",["A"]),("age","cmp","L",35)],ppyAssump)
                        ,("ByDefault",defAssump)
                       )

r = localAPI.runPool(myPool
                   ,poolAssump=AssetLevelAssumption
                   ,read=True)

r['PoolConsol']['flow'].head()
/home/docs/checkouts/readthedocs.org/user_builds/absbox-doc/envs/stable/lib/python3.11/site-packages/urllib3/connectionpool.py:1097: InsecureRequestWarning: Unverified HTTPS request is being made to host 'absbox.org'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings
  warnings.warn(
Balance Principal Interest Prepayment Default Recovery Loss WAC BorrowerNum PrepayPenalty CumPrincipal CumPrepay CumDelinq CumDefault CumRecovery CumLoss
Date
2022-03-01 6034.37 840.77 42.96 40.00 84.86 0 84.86 0.075 None None 840.77 40.00 0 84.86 0 84.86
2022-04-01 5089.14 829.85 36.98 34.40 80.98 0 80.98 0.075 None None 1670.62 74.40 0 165.84 0 165.84
2022-05-01 4174.58 819.43 31.20 28.99 66.14 0 66.14 0.075 None None 2490.05 103.39 0 231.98 0 231.98
2022-06-01 3285.99 808.78 25.58 23.74 56.07 0 56.07 0.075 None None 3298.83 127.13 0 288.05 0 288.05
2022-07-01 2425.96 798.62 20.15 18.67 42.74 0 42.74 0.075 None None 4097.45 145.80 0 330.79 0 330.79