{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "### Run Multiple Scenario on Pool" ] }, { "cell_type": "code", "execution_count": 2, "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\n", "\n", "localAPI = API(EnginePath.DEV, lang='english',check=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Pool\n", "\n", "In `Pool` , it will have a field named `assets` ,which contains a list of `assets`" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "mortgage1 = [\"Mortgage\"\n", " ,{\"originBalance\": 12000.0\n", " ,\"originRate\": [\"fix\",0.045]\n", " ,\"originTerm\": 40\n", " ,\"freq\": \"monthly\"\n", " ,\"type\": \"level\"\n", " ,\"originDate\": \"2021-02-01\"}\n", " ,{\"currentBalance\": 10000.0\n", " ,\"currentRate\": 0.075\n", " ,\"remainTerm\": 30\n", " ,\"status\": \"current\"}]\n", "\n", "mortgage2 = [\"Mortgage\"\n", " ,{\"originBalance\": 800.0\n", " ,\"originRate\": [\"fix\",0.045]\n", " ,\"originTerm\": 25\n", " ,\"freq\": \"monthly\"\n", " ,\"type\": \"level\"\n", " ,\"originDate\": \"2021-02-01\"}\n", " ,{\"currentBalance\": 600.0\n", " ,\"currentRate\": 0.075\n", " ,\"remainTerm\": 15\n", " ,\"status\": \"current\"}]\n", "\n", "myPool = {'assets':[ mortgage1, mortgage2],\n", " 'cutoffDate':\"2022-03-01\"}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Set Multi Assumption\n", "\n", "It is just a map!" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "multiAssump= \\\n", " {\"cdr001\":(\"Pool\",(\"Mortgage\",{\"CDR\":0.01},None,None,None)\n", " ,None\n", " ,None)\n", " ,\"non\":(\"Pool\",(\"Mortgage\",None,None,None,None)\n", " ,None\n", " ,None\n", " )}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Make sure call `runPoolByScenarios`" ] }, { "cell_type": "code", "execution_count": 5, "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" ] } ], "source": [ "r = localAPI.runPoolByScenarios(myPool,poolAssump=multiAssump,read=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Use keys from `multiAssump` to retrive results" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "scrolled": true }, "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", " \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", "
BalancePrincipalInterestPrepaymentDefaultRecoveryLossWACBorrowerNumPrepayPenaltyCumPrincipalCumPrepayCumDelinqCumDefaultCumRecoveryCumLoss
Date
2022-03-019542.79345.8061.8007.6207.620.075NoneNone345.80007.6207.62
2022-04-019186.98347.6859.5808.1308.130.075NoneNone693.480015.75015.75
2022-05-018829.85349.5657.3607.5707.570.075NoneNone1043.040023.32023.32
2022-06-018470.88351.4555.1307.5207.520.075NoneNone1394.490030.84030.84
2022-07-018110.54353.3552.8906.9906.990.075NoneNone1747.840037.83037.83
\n", "
" ], "text/plain": [ " Balance Principal Interest Prepayment Default Recovery Loss \\\n", "Date \n", "2022-03-01 9542.79 345.80 61.80 0 7.62 0 7.62 \n", "2022-04-01 9186.98 347.68 59.58 0 8.13 0 8.13 \n", "2022-05-01 8829.85 349.56 57.36 0 7.57 0 7.57 \n", "2022-06-01 8470.88 351.45 55.13 0 7.52 0 7.52 \n", "2022-07-01 8110.54 353.35 52.89 0 6.99 0 6.99 \n", "\n", " WAC BorrowerNum PrepayPenalty CumPrincipal CumPrepay \\\n", "Date \n", "2022-03-01 0.075 None None 345.80 0 \n", "2022-04-01 0.075 None None 693.48 0 \n", "2022-05-01 0.075 None None 1043.04 0 \n", "2022-06-01 0.075 None None 1394.49 0 \n", "2022-07-01 0.075 None None 1747.84 0 \n", "\n", " CumDelinq CumDefault CumRecovery CumLoss \n", "Date \n", "2022-03-01 0 7.62 0 7.62 \n", "2022-04-01 0 15.75 0 15.75 \n", "2022-05-01 0 23.32 0 23.32 \n", "2022-06-01 0 30.84 0 30.84 \n", "2022-07-01 0 37.83 0 37.83 " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r['cdr001']['PoolConsol']['flow'].head()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Run Multiple Pools with Multiple Assumptions" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "receivable1 = [\"Invoice\"\n", " ,{\"start\":\"2024-04-01\",\"originBalance\":2000\n", " ,\"originAdvance\":1500,\"dueDate\":\"2024-06-01\"}\n", " ,{\"status\":\"Current\"}]\n", "\n", "myMixedPool = {\"invoicePool\": {'assets':[receivable1],}\n", " ,\"mortgagePool\": {'assets':[mortgage1]}\n", " ,'cutoffDate':\"2022-03-01\"}" ] }, { "cell_type": "code", "execution_count": 8, "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" ] } ], "source": [ "mPoolAssump0 = (\"Pool\",\n", " (\"Mortgage\",None,None,None,None)\n", " ,None\n", " ,None)\n", "\n", "mPoolAssump = (\"Pool\",\n", " (\"Mortgage\",{\"CDR\":0.01},None,None,None)\n", " ,None\n", " ,None)\n", "\n", "iPoolAssump0 = (\"Pool\"\n", " ,(\"Receivable\", None, None, None)\n", " ,None\n", " ,None)\n", "\n", "iPoolAssump = (\"Pool\"\n", " ,(\"Receivable\", {\"CDR\":0.01}, None, None)\n", " ,None\n", " ,None)\n", "\n", "\n", "r = localAPI.runPoolByScenarios(myMixedPool\n", " ,poolAssump = {\"NonStress\":(\"ByPoolId\",\n", " {\"invoicePool\":iPoolAssump0\n", " ,\"mortgagePool\":mPoolAssump0})\n", " ,\"Stress\":(\"ByPoolId\",\n", " {\"invoicePool\":iPoolAssump\n", " ,\"mortgagePool\":mPoolAssump})}\n", " ,read=True)" ] }, { "cell_type": "code", "execution_count": 9, "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", "
BalanceAccuredFeePrincipalFeeDefaultRecoveryLossCumPrincipalCumPrepayCumDelinqCumDefaultCumRecoveryCumLoss
Date
2024-04-012000000000000000
2024-06-010020000000000000
\n", "
" ], "text/plain": [ " Balance AccuredFee Principal Fee Default Recovery Loss \\\n", "Date \n", "2024-04-01 2000 0 0 0 0 0 0 \n", "2024-06-01 0 0 2000 0 0 0 0 \n", "\n", " CumPrincipal CumPrepay CumDelinq CumDefault CumRecovery \\\n", "Date \n", "2024-04-01 0 0 0 0 0 \n", "2024-06-01 0 0 0 0 0 \n", "\n", " CumLoss \n", "Date \n", "2024-04-01 0 \n", "2024-06-01 0 " ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r['NonStress']['invoicePool']['flow'].head()" ] }, { "cell_type": "code", "execution_count": 10, "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", " \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", "
BalancePrincipalInterestPrepaymentDefaultRecoveryLossWACBorrowerNumPrepayPenaltyCumPrincipalCumPrepayCumDelinqCumDefaultCumRecoveryCumLoss
Date
2022-03-019059.53307.1458.5407.2207.220.075NoneNone307.14007.2207.22
2022-04-018743.01308.8056.5707.7207.720.075NoneNone615.940014.94014.94
2022-05-018425.32310.4854.5907.2107.210.075NoneNone926.420022.15022.15
2022-06-018105.99312.1552.6107.1807.180.075NoneNone1238.570029.33029.33
2022-07-017785.46313.8450.6206.6906.690.075NoneNone1552.410036.02036.02
\n", "
" ], "text/plain": [ " Balance Principal Interest Prepayment Default Recovery Loss \\\n", "Date \n", "2022-03-01 9059.53 307.14 58.54 0 7.22 0 7.22 \n", "2022-04-01 8743.01 308.80 56.57 0 7.72 0 7.72 \n", "2022-05-01 8425.32 310.48 54.59 0 7.21 0 7.21 \n", "2022-06-01 8105.99 312.15 52.61 0 7.18 0 7.18 \n", "2022-07-01 7785.46 313.84 50.62 0 6.69 0 6.69 \n", "\n", " WAC BorrowerNum PrepayPenalty CumPrincipal CumPrepay \\\n", "Date \n", "2022-03-01 0.075 None None 307.14 0 \n", "2022-04-01 0.075 None None 615.94 0 \n", "2022-05-01 0.075 None None 926.42 0 \n", "2022-06-01 0.075 None None 1238.57 0 \n", "2022-07-01 0.075 None None 1552.41 0 \n", "\n", " CumDelinq CumDefault CumRecovery CumLoss \n", "Date \n", "2022-03-01 0 7.22 0 7.22 \n", "2022-04-01 0 14.94 0 14.94 \n", "2022-05-01 0 22.15 0 22.15 \n", "2022-06-01 0 29.33 0 29.33 \n", "2022-07-01 0 36.02 0 36.02 " ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r['Stress']['mortgagePool']['flow'].head()" ] }, { "cell_type": "code", "execution_count": null, "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": 4 }