{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "e43e2879-9574-4753-9221-499d1aae9d6c", "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", "from numpy import nan\n", "localAPI = API(EnginePath.DEV, lang='english', check=False)" ] }, { "cell_type": "markdown", "id": "350c255f", "metadata": {}, "source": [ "### Assumption By Term" ] }, { "cell_type": "code", "execution_count": 2, "id": "ec61bf1a-52d9-4145-9c37-c521a566cae3", "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": [ "m = [\"Mortgage\"\n", " ,{\"originBalance\": 12000.0\n", " ,\"originRate\": [\"fix\",0.045]\n", " ,\"originTerm\": 18\n", " ,\"freq\": \"Monthly\"\n", " ,\"type\": \"Level\"\n", " ,\"originDate\": \"2021-02-01\"}\n", " ,{\"currentBalance\": 10000.0\n", " ,\"currentRate\": 0.075\n", " ,\"remainTerm\": 12\n", " ,\"status\": \"Current\"}]\n", "\n", "byTermAssump = [ [0.01]*9+[0.02]*9\n", " ,[0.02]*6+[0.03]*6\n", " ,[0.03]*3+[0.04]*3 ]\n", "\n", "r = localAPI.runAsset(\"2020-01-02\"\n", " ,[m]\n", " ,poolAssump=(\"Pool\"\n", " ,(\"Mortgage\", None, {\"byTerm\":byTermAssump}, None, None)\n", " ,None\n", " ,None)\n", " ,read=True)" ] }, { "cell_type": "code", "execution_count": 8, "id": "99446e1f-cd43-4ed2-970c-fdca3e1b41c3", "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
2021-08-0110000.000.000.000.000000.075NoneNone0.000.000000
2021-09-019102.98797.0261.87100.000000.075NoneNone797.02100.000000
2021-10-018217.97793.9956.3291.020000.075NoneNone1591.01191.020000
2021-11-017344.84790.9650.8482.170000.075NoneNone2381.97273.190000
2021-12-016417.96779.9944.98146.890000.075NoneNone3161.96420.080000
\n", "
" ], "text/plain": [ " Balance Principal Interest Prepayment Default Recovery \\\n", "Date \n", "2021-08-01 10000.00 0.00 0.00 0.00 0 0 \n", "2021-09-01 9102.98 797.02 61.87 100.00 0 0 \n", "2021-10-01 8217.97 793.99 56.32 91.02 0 0 \n", "2021-11-01 7344.84 790.96 50.84 82.17 0 0 \n", "2021-12-01 6417.96 779.99 44.98 146.89 0 0 \n", "\n", " Loss WAC BorrowerNum PrepayPenalty CumPrincipal CumPrepay \\\n", "Date \n", "2021-08-01 0 0.075 None None 0.00 0.00 \n", "2021-09-01 0 0.075 None None 797.02 100.00 \n", "2021-10-01 0 0.075 None None 1591.01 191.02 \n", "2021-11-01 0 0.075 None None 2381.97 273.19 \n", "2021-12-01 0 0.075 None None 3161.96 420.08 \n", "\n", " CumDelinq CumDefault CumRecovery CumLoss \n", "Date \n", "2021-08-01 0 0 0 0 \n", "2021-09-01 0 0 0 0 \n", "2021-10-01 0 0 0 0 \n", "2021-11-01 0 0 0 0 \n", "2021-12-01 0 0 0 0 " ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r[0].head()" ] }, { "cell_type": "code", "execution_count": 9, "id": "c8569f01-4437-4f6c-8a16-c4ab244dc313", "metadata": {}, "outputs": [], "source": [ "i = [\"Installment\"\n", " ,{\"originBalance\": 1000.0\n", " ,\"feeRate\": [\"fix\",0.01]\n", " ,\"originTerm\": 12\n", " ,\"freq\": \"Monthly\"\n", " ,\"type\": \"f_p\"\n", " ,\"originDate\": \"2022-01-01\"}\n", " ,{\"status\": \"Current\"\n", " ,\"currentBalance\":1000\n", " ,\"remainTerm\":10}]" ] }, { "cell_type": "code", "execution_count": 10, "id": "f3f5740d-8c8d-4b62-a6e8-590768b0db73", "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": [ "byTermAssump = [ [0.01]*9+[0.02]*9\n", " ,[0.02]*6+[0.03]*6\n", " ,[0.03]*3+[0.04]*3 ]\n", "\n", "r = localAPI.runAsset(\"2020-01-02\"\n", " ,[i]\n", " ,poolAssump=(\"Pool\"\n", " ,(\"Installment\", {\"byTerm\":byTermAssump}, None, None, None)\n", " ,None\n", " ,None)\n", " ,read=True)" ] }, { "cell_type": "code", "execution_count": 11, "id": "05048d4d-360a-41dc-817a-afad57e304ee", "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", "
BalancePrincipalInterestPrepaymentDefaultRecoveryLossWACCumPrincipalCumPrepayCumDelinqCumDefaultCumRecoveryCumLoss
Date
2022-03-011000.000.000.0000.0000.000.010.00000.0000.00
2022-04-01882.0197.9911.75020.00020.000.0197.990020.00020.00
2022-05-01768.3496.0311.52017.64017.640.01194.020037.64037.64
2022-06-01658.8794.1111.29015.36015.360.01288.130053.00053.00
2022-07-01553.4792.2311.06013.17013.170.01380.360066.17066.17
\n", "
" ], "text/plain": [ " Balance Principal Interest Prepayment Default Recovery \\\n", "Date \n", "2022-03-01 1000.00 0.00 0.00 0 0.00 0 \n", "2022-04-01 882.01 97.99 11.75 0 20.00 0 \n", "2022-05-01 768.34 96.03 11.52 0 17.64 0 \n", "2022-06-01 658.87 94.11 11.29 0 15.36 0 \n", "2022-07-01 553.47 92.23 11.06 0 13.17 0 \n", "\n", " Loss WAC CumPrincipal CumPrepay CumDelinq CumDefault \\\n", "Date \n", "2022-03-01 0.00 0.01 0.00 0 0 0.00 \n", "2022-04-01 20.00 0.01 97.99 0 0 20.00 \n", "2022-05-01 17.64 0.01 194.02 0 0 37.64 \n", "2022-06-01 15.36 0.01 288.13 0 0 53.00 \n", "2022-07-01 13.17 0.01 380.36 0 0 66.17 \n", "\n", " CumRecovery CumLoss \n", "Date \n", "2022-03-01 0 0.00 \n", "2022-04-01 0 20.00 \n", "2022-05-01 0 37.64 \n", "2022-06-01 0 53.00 \n", "2022-07-01 0 66.17 " ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r[0].head(5)" ] }, { "cell_type": "code", "execution_count": 12, "id": "acc9af57-180c-48b8-81d5-d7c86b0fb506", "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": [ "l = [\"Loan\"\n", " ,{\"originBalance\": 80000\n", " ,\"originRate\": [\"fix\",0.045]\n", " ,\"originTerm\": 18\n", " ,\"freq\": \"SemiAnnually\"\n", " ,\"type\": \"i_p\"\n", " ,\"originDate\": \"2021-03-01\"}\n", " ,{\"currentBalance\": 65000\n", " ,\"currentRate\": 0.06\n", " ,\"remainTerm\": 12\n", " ,\"status\": \"Current\"}]\n", "\n", "r = localAPI.runAsset(\"2020-01-02\"\n", " ,[l]\n", " ,poolAssump=(\"Pool\"\n", " ,(\"Loan\", {\"byTerm\":byTermAssump}, None, None, None)\n", " ,None\n", " ,None)\n", " ,read=True)" ] }, { "cell_type": "code", "execution_count": 13, "id": "923428bb-e552-4fa3-87fb-b380c1b3445a", "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", "
BalancePrincipalInterestPrepaymentDefaultRecoveryLossWACCumPrincipalCumPrepayCumDelinqCumDefaultCumRecoveryCumLoss
Date
2024-03-0165000.000.00.0000.0000.000.060.0000.0000.00
2024-09-0164350.000.01946.360650.000650.000.060.000650.000650.00
2025-03-0163706.500.01895.480643.500643.500.060.0001293.5001293.50
2025-09-0163069.440.01907.630637.060637.060.060.0001930.5601930.56
2026-03-0161808.060.01839.0001261.3801261.380.060.0003191.9403191.94
\n", "
" ], "text/plain": [ " Balance Principal Interest Prepayment Default Recovery \\\n", "Date \n", "2024-03-01 65000.00 0.0 0.00 0 0.00 0 \n", "2024-09-01 64350.00 0.0 1946.36 0 650.00 0 \n", "2025-03-01 63706.50 0.0 1895.48 0 643.50 0 \n", "2025-09-01 63069.44 0.0 1907.63 0 637.06 0 \n", "2026-03-01 61808.06 0.0 1839.00 0 1261.38 0 \n", "\n", " Loss WAC CumPrincipal CumPrepay CumDelinq CumDefault \\\n", "Date \n", "2024-03-01 0.00 0.06 0.0 0 0 0.00 \n", "2024-09-01 650.00 0.06 0.0 0 0 650.00 \n", "2025-03-01 643.50 0.06 0.0 0 0 1293.50 \n", "2025-09-01 637.06 0.06 0.0 0 0 1930.56 \n", "2026-03-01 1261.38 0.06 0.0 0 0 3191.94 \n", "\n", " CumRecovery CumLoss \n", "Date \n", "2024-03-01 0 0.00 \n", "2024-09-01 0 650.00 \n", "2025-03-01 0 1293.50 \n", "2025-09-01 0 1930.56 \n", "2026-03-01 0 3191.94 " ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r[0].head(5)" ] }, { "cell_type": "markdown", "id": "c2185ec4-31c7-4a61-bc2b-76b31ca55c0a", "metadata": {}, "source": [ "#### Combination with Tag\n", "\n", "User can make further strats on applying assumpition in smaller granularity" ] }, { "cell_type": "code", "execution_count": 14, "id": "c861943f-89aa-4a37-be20-08e2eb961253", "metadata": {}, "outputs": [], "source": [ "ob1 = {\n", " \"id\":\"1\",\n", " \"tag\":[\"A\",\"B\"],\n", " \"fields\":{\"age\":30,\"creditLevel\":\"A\"}\n", "} \n", "\n", "ob2 = {\n", " \"id\":\"2\",\n", " \"tag\":[\"C\",\"B\"],\n", " \"fields\":{\"age\":50,\"creditLevel\":\"B\"}\n", "} \n", "\n", "\n", "myAsset1 = [\"Mortgage\"\n", " ,{\"originBalance\": 12000.0\n", " ,\"originRate\": [\"fix\",0.045]\n", " ,\"originTerm\": 20\n", " ,\"freq\": \"monthly\"\n", " ,\"type\": \"level\"\n", " ,\"originDate\": \"2021-02-01\"\n", " ,\"obligor\":ob1\n", " }\n", " ,{\"currentBalance\": 2000.0\n", " ,\"currentRate\": 0.075\n", " ,\"remainTerm\": 8\n", " ,\"status\": \"current\"}]\n", "myAsset2 = [\"Mortgage\"\n", " ,{\"originBalance\": 12000.0\n", " ,\"originRate\": [\"fix\",0.045]\n", " ,\"originTerm\": 20\n", " ,\"freq\": \"monthly\"\n", " ,\"type\": \"level\"\n", " ,\"originDate\": \"2021-02-01\"\n", " ,\"obligor\":ob2\n", " }\n", " ,{\"currentBalance\": 5000.0\n", " ,\"currentRate\": 0.075\n", " ,\"remainTerm\": 8\n", " ,\"status\": \"current\"}]\n", "\n", "myPool = {'assets':[myAsset1,myAsset2],\n", " 'cutoffDate':\"2022-03-01\"}" ] }, { "cell_type": "code", "execution_count": 16, "id": "d9d2a77d-c451-48b4-9ce7-67890c16a93b", "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \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-016034.37840.7742.9640.0084.86084.860.075NoneNone840.7740.00084.86084.86
2022-04-015089.14829.8536.9834.4080.98080.980.075NoneNone1670.6274.400165.840165.84
2022-05-014174.58819.4331.2028.9966.14066.140.075NoneNone2490.05103.390231.980231.98
2022-06-013285.99808.7825.5823.7456.07056.070.075NoneNone3298.83127.130288.050288.05
2022-07-012425.96798.6220.1518.6742.74042.740.075NoneNone4097.45145.800330.790330.79
\n", "
" ], "text/plain": [ " Balance Principal Interest Prepayment Default Recovery \\\n", "Date \n", "2022-03-01 6034.37 840.77 42.96 40.00 84.86 0 \n", "2022-04-01 5089.14 829.85 36.98 34.40 80.98 0 \n", "2022-05-01 4174.58 819.43 31.20 28.99 66.14 0 \n", "2022-06-01 3285.99 808.78 25.58 23.74 56.07 0 \n", "2022-07-01 2425.96 798.62 20.15 18.67 42.74 0 \n", "\n", " Loss WAC BorrowerNum PrepayPenalty CumPrincipal CumPrepay \\\n", "Date \n", "2022-03-01 84.86 0.075 None None 840.77 40.00 \n", "2022-04-01 80.98 0.075 None None 1670.62 74.40 \n", "2022-05-01 66.14 0.075 None None 2490.05 103.39 \n", "2022-06-01 56.07 0.075 None None 3298.83 127.13 \n", "2022-07-01 42.74 0.075 None None 4097.45 145.80 \n", "\n", " CumDelinq CumDefault CumRecovery CumLoss \n", "Date \n", "2022-03-01 0 84.86 0 84.86 \n", "2022-04-01 0 165.84 0 165.84 \n", "2022-05-01 0 231.98 0 231.98 \n", "2022-06-01 0 288.05 0 288.05 \n", "2022-07-01 0 330.79 0 330.79 " ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "byTermAssump = [ [0.01]*10+[0.02]*10\n", " ,[0.03]*3+[0.04]*3 ]\n", "\n", "ppyAssump = ((\"Mortgage\",None ,{\"byTerm\":byTermAssump}, None, None)\n", " ,None\n", " ,None)\n", "defAssump = ((\"Mortgage\",{\"CDR\":0.2} ,None, None, None)\n", " ,None\n", " ,None)\n", "\n", "AssetLevelAssumption = (\"ByObligor\"\n", " ,(\"ByField\",[(\"creditLevel\",\"in\",[\"A\"]),(\"age\",\"cmp\",\"L\",35)],ppyAssump)\n", " ,(\"ByDefault\",defAssump)\n", " )\n", "\n", "r = localAPI.runPool(myPool\n", " ,poolAssump=AssetLevelAssumption\n", " ,read=True)\n", "\n", "r['PoolConsol']['flow'].head()" ] }, { "cell_type": "code", "execution_count": null, "id": "e2a76e7d-3473-4ec6-b482-ee6e24a51539", "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 }