{ "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", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
<IrrOfBond:B>
Date
2021-03-01-1.000000
2021-03-31-1.000000
2021-04-30-1.000000
2021-05-31-1.000000
2021-06-30-1.000000
2021-07-31-1.000000
2021-08-31-1.000000
2021-09-30-1.000000
2021-10-31-1.000000
2021-11-30-0.991550
2021-12-31-0.924962
2022-01-31-0.819225
2022-02-28-0.691808
2022-03-31-0.556005
2022-04-30-0.418251
2022-05-31-0.284275
2022-06-30-0.156962
2022-07-31-0.038095
2022-08-310.071716
2022-09-300.099997
2022-10-310.099997
2022-11-300.099997
2022-12-310.099997
2023-01-310.099997
2023-02-280.099997
\n", "
" ], "text/plain": [ " \n", "Date \n", "2021-03-01 -1.000000\n", "2021-03-31 -1.000000\n", "2021-04-30 -1.000000\n", "2021-05-31 -1.000000\n", "2021-06-30 -1.000000\n", "2021-07-31 -1.000000\n", "2021-08-31 -1.000000\n", "2021-09-30 -1.000000\n", "2021-10-31 -1.000000\n", "2021-11-30 -0.991550\n", "2021-12-31 -0.924962\n", "2022-01-31 -0.819225\n", "2022-02-28 -0.691808\n", "2022-03-31 -0.556005\n", "2022-04-30 -0.418251\n", "2022-05-31 -0.284275\n", "2022-06-30 -0.156962\n", "2022-07-31 -0.038095\n", "2022-08-31 0.071716\n", "2022-09-30 0.099997\n", "2022-10-31 0.099997\n", "2022-11-30 0.099997\n", "2022-12-31 0.099997\n", "2023-01-31 0.099997\n", "2023-02-28 0.099997" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r0['result']['inspect']['']" ] }, { "cell_type": "code", "execution_count": null, "id": "9b0c3363-8c68-4e68-b26a-2daeea34a5f3", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "5b3a85dc-e81c-4486-930f-f2f5045fdf5e", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.13.3" } }, "nbformat": 4, "nbformat_minor": 5 }