{ "cells": [ { "cell_type": "markdown", "id": "723dea80-1f1f-4da3-b600-aa9588446e7d", "metadata": {}, "source": [ "### IRR Example (continue)\n", "\n", "In `absbox`, user can calculate irr of a tranche or (multiple tranches) for scenarios of:\n", "\n", "* During the waterfall distribution, user want to pay up to x% IRR to a bond (which makes IRR of the bond close to that threshold.\n", "* Using IRR from the formula, like inspect the current IRR of the bond, or use the IRR in a `condition`\n", "\n", "#### Related formula\n", "\n", "Since engine version : `0.52.3`\n", "\n", "* `IrrOfBond`" ] }, { "cell_type": "markdown", "id": "6a5c410a", "metadata": {}, "source": [ "#### Init" ] }, { "cell_type": "code", "execution_count": 1, "id": "a791a17b", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Connecting engine server -> http://localhost:8081\n",
"\n"
],
"text/plain": [
"Connecting engine server -> \u001b[4;94mhttp://localhost:8081\u001b[0m\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"✅Connected, local lib:0.51.5, server:0.52.3\n", "\n" ], "text/plain": [ "✅Connected, local li\u001b[1;92mb:0\u001b[0m.\u001b[1;36m51.5\u001b[0m, server:\u001b[1;36m0.52\u001b[0m.\u001b[1;36m3\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from absbox import examples,API,EnginePath\n", "localAPI = API(EnginePath.DEV, check=False)" ] }, { "cell_type": "code", "execution_count": 2, "id": "b24530a1-8456-4eb2-8a96-5a7b04dc849d", "metadata": {}, "outputs": [], "source": [ "from absbox import Generic\n", "\n", "Irr02 = Generic(\n", " \"IRR Case 02\"\n", " ,{\"cutoff\":\"2021-03-01\",\"closing\":\"2021-04-01\",\"firstPay\":\"2021-06-20\"\n", " ,\"payFreq\":[\"DayOfMonth\",20],\"poolFreq\":\"MonthFirst\",\"stated\":\"2030-01-01\"}\n", " ,{'assets':[[\"Mortgage\"\n", " ,{\"originBalance\":2200,\"originRate\":[\"fix\",0.045],\"originTerm\":20\n", " ,\"freq\":\"Monthly\",\"type\":\"Level\",\"originDate\":\"2021-02-01\"}\n", " ,{\"currentBalance\":2200\n", " ,\"currentRate\":0.08\n", " ,\"remainTerm\":20\n", " ,\"status\":\"current\"}]]}\n", " ,((\"acc01\",{\"balance\":0}),)\n", " ,((\"A1\",{\"balance\":1000\n", " ,\"rate\":0.07\n", " ,\"originBalance\":1000\n", " ,\"originRate\":0.07\n", " ,\"startDate\":\"2021-04-01\"\n", " ,\"rateType\":{\"Fixed\":0.08}\n", " ,\"bondType\":{\"Sequential\":None}})\n", " ,(\"B\",{\"balance\":1000\n", " ,\"rate\":0.0\n", " ,\"originBalance\":1000\n", " ,\"originRate\":0.07\n", " ,\"startDate\":\"2021-04-01\"\n", " ,\"rateType\":{\"Fixed\":0.00}\n", " ,\"bondType\":{\"Equity\":None}\n", " ,\"stmt\":[[\"2021-04-01\",0,0,0,0,-1000,0,0,None,\"\"],]\n", " }))\n", " ,((\"incentiveFee\",{\"type\":{\"fixFee\":100},\"feeStart\":\"2021-04-01\"}),)\n", " ,{\"amortizing\":[\n", " [\"accrueAndPayInt\",\"acc01\",[\"A1\"]]\n", " ,[\"payPrin\",\"acc01\",[\"A1\"]]\n", " ,[\"payPrin\",\"acc01\",[\"B\"]]\n", " #,[\"payIntResidual\",\"acc01\",\"B\",{\"limit\":(\"ds\",(\"floorWithZero\",(\"amountForTargetIrr\",0.11,\"B\")))}]\n", " ,[\"payIntResidual\",\"acc01\",\"B\",{\"limit\":(\"ds\",(\"floorWithZero\",(\"amountForTargetIrr\",0.10,\"B\")))}]\n", " ,[\"payFee\",\"acc01\",['incentiveFee',]]\n", " ,[\"payFeeResidual\",\"acc01\",\"incentiveFee\"]\n", " ]}\n", " ,[[\"CollectedInterest\",\"acc01\"]\n", " ,[\"CollectedPrincipal\",\"acc01\"]\n", " ,[\"CollectedPrepayment\",\"acc01\"]\n", " ,[\"CollectedRecoveries\",\"acc01\"]]\n", " ,None\n", " ,None\n", " ,None\n", " ,None\n", " ,(\"PreClosing\",\"Amortizing\")\n", " )\n" ] }, { "cell_type": "markdown", "id": "af9dedfe", "metadata": {}, "source": [ "It says , pay out cash from account `acc01` as a residual yield ( which won't be constrainted to interest due ) to the bond `B`, by amount limited to a cap , which is the amount will make irr of bond B equal to `10%`\n", "\n", " [\"payIntResidual\",\"acc01\",\"B\",{\"limit\":(\"ds\",(\"floorWithZero\",(\"amountForTargetIrr\",0.10,\"B\")))}]\n", "\n", "* adding a `floorWithZero` , because the `amountForTargetIrr` may return negative\n", "\n", "\n", "#### Inspect the IRR changes of bond" ] }, { "cell_type": "code", "execution_count": 16, "id": "e03297f6", "metadata": {}, "outputs": [], "source": [ "r0 = localAPI.run(Irr02\n", " ,poolAssump=(\"Pool\",(\"Mortgage\",{\"CDRPadding\":[0.01,0.02]},{\"CPR\":0.02},{\"Rate\":0.1,\"Lag\":5},None)\n", " ,None\n", " ,None)\n", " ,runAssump = [\n", " (\"inspect\",[\"MonthEnd\",(\"irrOfBond\",\"B\")]\n", " )\n", " ]\n", " ,read=True\n", " )" ] }, { "cell_type": "code", "execution_count": 18, "id": "6867526b-e341-401d-abba-e53a9b55b292", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
| \n", " | <IrrOfBond:B> | \n", "
|---|---|
| Date | \n", "\n", " |
| 2021-03-01 | \n", "-1.000000 | \n", "
| 2021-03-31 | \n", "-1.000000 | \n", "
| 2021-04-30 | \n", "-1.000000 | \n", "
| 2021-05-31 | \n", "-1.000000 | \n", "
| 2021-06-30 | \n", "-1.000000 | \n", "
| 2021-07-31 | \n", "-1.000000 | \n", "
| 2021-08-31 | \n", "-1.000000 | \n", "
| 2021-09-30 | \n", "-1.000000 | \n", "
| 2021-10-31 | \n", "-1.000000 | \n", "
| 2021-11-30 | \n", "-0.991550 | \n", "
| 2021-12-31 | \n", "-0.924962 | \n", "
| 2022-01-31 | \n", "-0.819225 | \n", "
| 2022-02-28 | \n", "-0.691808 | \n", "
| 2022-03-31 | \n", "-0.556005 | \n", "
| 2022-04-30 | \n", "-0.418251 | \n", "
| 2022-05-31 | \n", "-0.284275 | \n", "
| 2022-06-30 | \n", "-0.156962 | \n", "
| 2022-07-31 | \n", "-0.038095 | \n", "
| 2022-08-31 | \n", "0.071716 | \n", "
| 2022-09-30 | \n", "0.099997 | \n", "
| 2022-10-31 | \n", "0.099997 | \n", "
| 2022-11-30 | \n", "0.099997 | \n", "
| 2022-12-31 | \n", "0.099997 | \n", "
| 2023-01-31 | \n", "0.099997 | \n", "
| 2023-02-28 | \n", "0.099997 | \n", "