{ "cells": [ { "cell_type": "code", "execution_count": 15, "id": "18ec58c8-5e5d-4aa7-952e-bfbc0db57f4c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Connecting engine server -> https://absbox.org/api/dev\n",
       "
\n" ], "text/plain": [ "Connecting engine server -> \u001b[4;94mhttps://absbox.org/api/dev\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "/home/xiaoyu/repo/AbsBox/lib/python3.13/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\n", " warnings.warn(\n" ] }, { "data": { "text/html": [ "
✅Connected, local lib:0.46.5, server:0.50.1\n",
       "
\n" ], "text/plain": [ "✅Connected, local li\u001b[1;92mb:0\u001b[0m.\u001b[1;36m46.5\u001b[0m, server:\u001b[1;36m0.50\u001b[0m.\u001b[1;36m1\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from absbox import API,EnginePath,Generic\n", "import pandas as pd\n", "localAPI = API(EnginePath.DEV,lang='english',check=False)" ] }, { "cell_type": "markdown", "id": "f3dbbf9b-966f-456a-84cc-a5c677ad8fde", "metadata": {}, "source": [ "### A Lease Deal Example with root finder\n", "\n", "#### Lease Asset\n", "\n", "* with daily rate of 2\n", "* payable at each 5 of the month\n", "* 24 payments, starting from 2021-3-1" ] }, { "cell_type": "code", "execution_count": 2, "id": "8b508386-78a3-4826-a491-0bbf9151d03e", "metadata": {}, "outputs": [], "source": [ "l1 = [\"Lease\"\n", " ,{\"rental\": (\"byDay\", 2.0, [\"DayOfMonth\",5]),\"originTerm\": 24,\"originDate\": \"2021-03-01\"}\n", " ,{\"currentBalance\":1,\"status\":\"Current\",\"remainTerm\":24}]" ] }, { "cell_type": "markdown", "id": "c76a05cb-cd9c-40a2-8fbb-c490eb81ea9e", "metadata": {}, "source": [ "#### Deal Structure\n", "\n", "* With starting equity tranche 99.5%\n", "* Distribution day: each 20 of the month" ] }, { "cell_type": "code", "execution_count": 3, "id": "01aa8ab8-8498-4a00-afc9-93c65b03aa28", "metadata": {}, "outputs": [], "source": [ "lease01 = Generic(\n", " \"lease01\"\n", " ,{\"cutoff\":\"2021-03-01\",\"closing\":\"2021-06-15\",\"firstPay\":\"2021-07-26\"\n", " ,\"payFreq\":[\"DayOfMonth\",20],\"poolFreq\":\"MonthEnd\",\"stated\":\"2030-01-01\"}\n", " ,{'assets':[l1]}\n", " ,((\"acc01\",{\"balance\":0}),)\n", " ,((\"A1\",{\"balance\":10\n", " ,\"rate\":0.07\n", " ,\"originBalance\":10\n", " ,\"originRate\":0.07\n", " ,\"startDate\":\"2020-01-03\"\n", " ,\"rateType\":{\"Fixed\":0.08}\n", " ,\"bondType\":{\"Sequential\":None}})\n", " ,(\"B\",{\"balance\":1990\n", " ,\"rate\":0.0\n", " ,\"originBalance\":1990\n", " ,\"originRate\":0.00\n", " ,\"startDate\":\"2020-01-03\"\n", " ,\"rateType\":{\"Fixed\":0.00}\n", " ,\"bondType\":{\"Equity\":None}\n", " }))\n", " ,((\"trusteeFee\",{\"type\":{\"fixFee\":30},\"feeStart\":\"2021-06-15\"}),)\n", " ,{\"amortizing\":[\n", " [\"payFee\",\"acc01\",['trusteeFee']]\n", " ,[\"accrueAndPayInt\",\"acc01\",[\"A1\"]]\n", " ,[\"payPrin\",\"acc01\",[\"A1\"]]\n", " ,[\"payPrin\",\"acc01\",[\"B\"]]\n", " ,[\"payIntResidual\",\"acc01\",\"B\"]\n", " ],\n", " \"cleanUp\":[\n", " [\"payIntResidual\",\"acc01\",\"B\"]\n", " ]}\n", " ,[[\"CollectedRental\",\"acc01\"]]\n", " ,None\n", " ,None\n", " ,None\n", " ,None\n", " ,(\"PreClosing\",\"Amortizing\")\n", " )" ] }, { "cell_type": "markdown", "id": "1a8e48df-f633-4d21-8ef2-a11181b43014", "metadata": {}, "source": [ "#### Pool Performance\n", "\n", "* using a decreasing rental vector. For first extenstion, the lease rental will be reduced by 25%\n", "* pricing IRR of the tranche B" ] }, { "cell_type": "code", "execution_count": 4, "id": "389386bd-a01c-4c88-9f7d-783c6f12ffa7", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/xiaoyu/repo/AbsBox/lib/python3.13/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\n", " warnings.warn(\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
IRR
B0.153709
\n", "
" ], "text/plain": [ " IRR\n", "B 0.153709" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "baseRental = ('byRateVec',-0.25,-0.22,-0.1)\n", "\n", "poolPerf = (\"Pool\",(\"Lease\", None, ('days', 25), baseRental, (\"byExtTimes\", 3))\n", " ,None\n", " ,None\n", " )\n", "\n", "pricing = (\"pricing\",{\"IRR\":{\"B\":(\"holding\",[(\"2021-06-15\",-1000)],1000)}})\n", "\n", "r = localAPI.run(lease01\n", " ,runAssump=[pricing]\n", " ,poolAssump = poolPerf\n", " ,read=True)\n", "\n", "r['pricing']['summary']" ] }, { "cell_type": "markdown", "id": "30971d67-2987-4036-a764-535cbb3c7081", "metadata": {}, "source": [ "#### MultiScenario\n", "\n", "Using lens / dict comprehension to build multiple scenario" ] }, { "cell_type": "code", "execution_count": 5, "id": "183ef3cb-e056-4773-baf7-56a241ac0396", "metadata": {}, "outputs": [], "source": [ "from lenses import lens\n", "\n", "scenMap = {\n", " \"low\":('byRateVec',-0.20,-0.20,-0.1),\n", " \"base\":baseRental,\n", " \"high\":('byRateVec',-0.30,-0.25,-0.1),\n", "}\n", "\n", "poolPerfMap = {k: poolPerf & lens[1][3].set(v)\n", " for k,v in scenMap.items()\n", "}" ] }, { "cell_type": "markdown", "id": "4ddb4156-71c0-468f-9aef-b9308e8278f7", "metadata": {}, "source": [ "Use `runByScenarios` to run sensitivity run and view the IRR of tranche B" ] }, { "cell_type": "code", "execution_count": 6, "id": "e66a9d55-8d32-48f4-9558-126937f6d973", "metadata": { "scrolled": true }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/xiaoyu/repo/AbsBox/lib/python3.13/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\n", " warnings.warn(\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
basehighlow
B0.1537090.0957390.20203
\n", "
" ], "text/plain": [ " base high low\n", "B 0.153709 0.095739 0.20203" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r = localAPI.runByScenarios(lease01\n", " ,runAssump=[pricing]\n", " ,poolAssump = poolPerfMap\n", " ,read=True)\n", "\n", "pd.DataFrame.from_dict({k: v['pricing']['summary'].IRR for k,v in r.items() },orient='index').transpose()" ] }, { "cell_type": "markdown", "id": "501dee40-d3a3-4708-9d56-9b5bddd95381", "metadata": {}, "source": [ "#### Structuring deal with target IRR\n", "\n", "* using `runRootFinder` to constantly `splitBalance` between `A1` and `B`, till `Irr` of `B` equals to target.\n", "\n", "There are lots of potential of `runRootFinder` to serve deal structuring purpose.\n", "\n", "Let me know what is missing ! :)" ] }, { "cell_type": "code", "execution_count": 16, "id": "e0116a19-3073-43fc-a35d-b86fe340e621", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/xiaoyu/repo/AbsBox/lib/python3.13/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\n", " warnings.warn(\n", "/home/xiaoyu/repo/AbsBox/lib/python3.13/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\n", " warnings.warn(\n", "/home/xiaoyu/repo/AbsBox/lib/python3.13/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\n", " warnings.warn(\n" ] }, { "data": { "text/plain": [ "[{'A1': 1447.99, 'B': 552.01, 'irr': 0.2},\n", " {'A1': 1602.03, 'B': 397.97, 'irr': 0.225},\n", " {'A1': 1695.53, 'B': 304.47, 'irr': 0.25}]" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "targetIrrs = (0.2,0.225,0.25)\n", "\n", "r0 = [ localAPI.runRootFinder(lease01, poolPerf ,[pricing]\n", " ,((\"splitBalance\", \"A1\" ,\"B\", 0.01, 0.99)\n", " ,(\"bondMetTargetIrr\", \"B\", irr))\n", " )\n", " for irr in targetIrrs \n", " ]\n", "\n", "[ {k:v['bndBalance'] \n", " for k,v in _r[1][0]['RDeal']['bonds'].items()}|{\"irr\":t} \n", " for t,_r in zip(targetIrrs,r0) ]" ] }, { "cell_type": "code", "execution_count": null, "id": "14d15e84-991e-45fc-a504-0dce0788f182", "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 }