IRR Example
In absbox, user can calculate irr of a tranche or (multiple tranches) for scenarios of:
Holding to maturity
Holding and sell at point of future day with a pricing assumption
Buy a tranche at point of future day with a pricing assumption and hold to maturity
Init
from absbox import examples,API,EnginePath
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
from absbox import Generic
Irr01 = Generic(
"IRR Case"
,{"cutoff":"2021-03-01","closing":"2021-04-01","firstPay":"2021-06-20"
,"payFreq":["DayOfMonth",20],"poolFreq":"MonthFirst","stated":"2030-01-01"}
,{'assets':[["Mortgage"
,{"originBalance":2200,"originRate":["fix",0.045],"originTerm":20
,"freq":"Monthly","type":"Level","originDate":"2021-02-01"}
,{"currentBalance":2200
,"currentRate":0.08
,"remainTerm":20
,"status":"current"}]]}
,(("acc01",{"balance":0}),)
,(("A1",{"balance":1000
,"rate":0.07
,"originBalance":1000
,"originRate":0.07
,"startDate":"2021-04-01"
,"rateType":{"Fixed":0.08}
,"bondType":{"Sequential":None}})
,("B",{"balance":1000
,"rate":0.0
,"originBalance":1000
,"originRate":0.07
,"startDate":"2021-04-01"
,"rateType":{"Fixed":0.00}
,"bondType":{"Equity":None}
}))
,tuple()
,{"amortizing":[
["accrueAndPayInt","acc01",["A1"]]
,["payPrin","acc01",["A1"]]
,["payPrin","acc01",["B"]]
,["payIntResidual","acc01","B"]
]}
,[["CollectedInterest","acc01"]
,["CollectedPrincipal","acc01"]
,["CollectedPrepayment","acc01"]
,["CollectedRecoveries","acc01"]]
,None
,None
,None
,None
,("PreClosing","Amortizing")
)
Holding bond to maturity
r0 = localAPI.run(Irr01
,poolAssump=("Pool",("Mortgage",{"CDRPadding":[0.01,0.02]},{"CPR":0.02},{"Rate":0.1,"Lag":5},None)
,None
,None)
,runAssump = [("pricing"
,{"IRR":
{"B":("holding",[("2021-04-01",-500)],500)
}
}
)
]
,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(
Get IRR
r0['pricing']['summary'].loc["B"].IRR
np.float64(0.264238)
Get breakdown of the bond cashflow of holding
r0['pricing']['breakdown']['B']
| balance | interest | principal | rate | cash | intDue | intOverInt | factor | memo | |
|---|---|---|---|---|---|---|---|---|---|
| date | |||||||||
| 2021-04-01 | 0.00 | 0.00 | 0.00 | 0 | -500.00 | 0 | 0 | NaN | |
| 2021-06-20 | 500.00 | 0.00 | 0.00 | 0 | 0.00 | 0 | 0 | 1.00000 | <PayYield:B> |
| 2021-07-20 | 500.00 | 0.00 | 0.00 | 0 | 0.00 | 0 | 0 | 1.00000 | <PayYield:B> |
| 2021-08-20 | 500.00 | 0.00 | 0.00 | 0 | 0.00 | 0 | 0 | 1.00000 | <PayYield:B> |
| 2021-09-20 | 500.00 | 0.00 | 0.00 | 0 | 0.00 | 0 | 0 | 1.00000 | <PayYield:B> |
| 2021-10-20 | 500.00 | 0.00 | 0.00 | 0 | 0.00 | 0 | 0 | 1.00000 | <PayYield:B> |
| 2021-11-20 | 476.25 | 0.00 | 23.74 | 0 | 23.74 | 0 | 0 | 0.95251 | [<PayPrin:B>, <PayYield:B>] |
| 2021-12-20 | 418.08 | 0.00 | 58.17 | 0 | 58.17 | 0 | 0 | 0.83616 | [<PayPrin:B>, <PayYield:B>] |
| 2022-01-20 | 360.16 | 0.00 | 57.92 | 0 | 57.92 | 0 | 0 | 0.72032 | [<PayPrin:B>, <PayYield:B>] |
| 2022-02-20 | 302.54 | 0.00 | 57.62 | 0 | 57.62 | 0 | 0 | 0.60508 | [<PayPrin:B>, <PayYield:B>] |
| 2022-03-20 | 245.27 | 0.00 | 57.26 | 0 | 57.26 | 0 | 0 | 0.49055 | [<PayPrin:B>, <PayYield:B>] |
| 2022-04-20 | 188.23 | 0.00 | 57.04 | 0 | 57.04 | 0 | 0 | 0.37647 | [<PayPrin:B>, <PayYield:B>] |
| 2022-05-20 | 131.50 | 0.00 | 56.73 | 0 | 56.73 | 0 | 0 | 0.26300 | [<PayPrin:B>, <PayYield:B>] |
| 2022-06-20 | 75.04 | 0.00 | 56.45 | 0 | 56.45 | 0 | 0 | 0.15009 | [<PayPrin:B>, <PayYield:B>] |
| 2022-07-20 | 18.89 | 0.00 | 56.15 | 0 | 56.15 | 0 | 0 | 0.03778 | [<PayPrin:B>, <PayYield:B>] |
| 2022-08-20 | 0.00 | 36.98 | 18.89 | 0 | 55.87 | 0 | 0 | 0.00000 | [<PayPrin:B>, <PayYield:B>] |
| 2022-09-20 | 0.00 | 55.59 | 0.00 | 0 | 55.59 | 0 | 0 | 0.00000 | <PayYield:B> |
| 2022-10-20 | 0.00 | 55.30 | 0.00 | 0 | 55.30 | 0 | 0 | 0.00000 | <PayYield:B> |
| 2022-11-20 | 0.00 | 0.04 | 0.00 | 0 | 0.04 | 0 | 0 | 0.00000 | <PayYield:B> |
| 2022-12-20 | 0.00 | 0.03 | 0.00 | 0 | 0.03 | 0 | 0 | 0.00000 | <PayYield:B> |
| 2023-01-20 | 0.00 | 0.02 | 0.00 | 0 | 0.02 | 0 | 0 | 0.00000 | <PayYield:B> |
| 2023-02-20 | 0.00 | 0.01 | 0.00 | 0 | 0.01 | 0 | 0 | 0.00000 | <PayYield:B> |
| 2023-03-20 | 0.00 | 0.00 | 0.00 | 0 | 0.00 | 0 | 0 | 0.00000 | <PayYield:B> |
Sale the bond during the holding
r1 = localAPI.run(Irr01
,poolAssump=("Pool",("Mortgage",{"CDRPadding":[0.01,0.02]},{"CPR":0.02},{"Rate":0.1,"Lag":5},None)
,None
,None)
,runAssump = [("pricing",{"IRR":
{"A1":("holding",[("2021-04-01",-500)],500,"2021-08-19",("byFactor",1.0))}
}
)]
,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(
r1['pricing']['summary']
| IRR | |
|---|---|
| A1 | 0.07196 |
r1['pricing']['breakdown']['A1']
| balance | interest | principal | rate | cash | intDue | intOverInt | factor | memo | |
|---|---|---|---|---|---|---|---|---|---|
| date | |||||||||
| 2021-04-01 | 0.00 | 0.00 | 0.00 | 0.00 | -500.00 | 0 | 0 | NaN | |
| 2021-06-20 | 266.97 | 7.67 | 233.03 | 0.07 | 240.70 | 0 | 0 | 0.53394 | [<PayInt:A1>, <PayPrin:A1>] |
| 2021-07-20 | 209.04 | 1.53 | 57.92 | 0.07 | 59.46 | 0 | 0 | 0.41809 | [<PayInt:A1>, <PayPrin:A1>] |
| 2021-08-19 | 0.00 | 1.20 | 209.04 | 0.00 | 210.24 | 0 | 0 | NaN |
Buy a bond in future
r3 = localAPI.run(Irr01
,poolAssump=("Pool",("Mortgage",{"CDRPadding":[0.01,0.02]},{"CPR":0.02},{"Rate":0.1,"Lag":5},None)
,None
,None)
,runAssump = [("pricing",{"IRR":
{"A1":("buy","2021-08-01",("byFactor",0.99),("byCash",200))}
}
)]
,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(
r3['pricing']['summary']
| IRR | |
|---|---|
| A1 | 0.139824 |
r3['pricing']['breakdown']['A1']
| balance | interest | principal | rate | cash | intDue | intOverInt | factor | memo | |
|---|---|---|---|---|---|---|---|---|---|
| date | |||||||||
| 2021-08-01 | 0.00 | -0.46 | -200.00 | 0.00 | -200.46 | 0 | 0 | NaN | |
| 2021-08-20 | 145.91 | 1.19 | 56.10 | 0.07 | 57.30 | 0 | 0 | 0.30198 | [<PayInt:A1>, <PayPrin:A1>] |
| 2021-09-20 | 89.66 | 0.86 | 56.25 | 0.07 | 57.11 | 0 | 0 | 0.18557 | [<PayInt:A1>, <PayPrin:A1>] |
| 2021-10-20 | 33.39 | 0.51 | 56.27 | 0.07 | 56.78 | 0 | 0 | 0.06911 | [<PayInt:A1>, <PayPrin:A1>] |
| 2021-11-20 | 0.00 | 0.19 | 33.39 | 0.07 | 33.59 | 0 | 0 | 0.00000 | [<PayInt:A1>, <PayPrin:A1>] |