{ "cells": [ { "cell_type": "markdown", "id": "94a0c3a5", "metadata": {}, "source": [ "### Liquidate Pools" ] }, { "cell_type": "markdown", "id": "57a91c73", "metadata": {}, "source": [ "We build an waterfall action which will be executed when running date between \"2022-09-01\" and \"2022-11-01\".\n", "The action will sell `all assets` with `1:1 on performing balance` and save proceeds to account `liqAcc`" ] }, { "cell_type": "code", "execution_count": null, "id": "442f80c2", "metadata": {}, "outputs": [], "source": [ "sellBothPool = [\"If\", [\"all\", ['>',\"2022-09-01\"], ['<',\"2022-11-01\"] ]\n", " ,[\"sellAsset\", [\"Current|Defaulted\", 1.0, 0], \"liqAcc\"]\n", " ]" ] }, { "cell_type": "markdown", "id": "15fa9e5e", "metadata": {}, "source": [ "insert this action to deal" ] }, { "cell_type": "code", "execution_count": 45, "id": "2a747c78-0ecf-405c-a4d6-05d2e00d80cb", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Connecting engine server -> http://localhost:8081\n",
       "
\n" ], "text/plain": [ "\u001b[1;35mConnecting engine server -> \u001b[0m\u001b[1;4;35mhttp://localhost:8081\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Connected, local lib:0.28.7, server:0.29.10\n",
       "
\n" ], "text/plain": [ "✅\u001b[1;32mConnected, local li\u001b[0m\u001b[1;32mb:0\u001b[0m\u001b[1;32m.\u001b[0m\u001b[1;32m28.7\u001b[0m\u001b[1;32m, server:\u001b[0m\u001b[1;32m0.29\u001b[0m\u001b[1;32m.\u001b[0m\u001b[1;32m10\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
Warning Message from server:\n",
       "Bond B is not paid off\n",
       "Account acc02 has cash to be distributed\n",
       "Account liqAcc has cash to be distributed\n",
       "
\n" ], "text/plain": [ "Warning Message from server:\n", "\u001b[1;33mBond B is not paid off\u001b[0m\n", "\u001b[1;33mAccount acc02 has cash to be distributed\u001b[0m\n", "\u001b[1;33mAccount liqAcc has cash to be distributed\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from lenses import lens\n", "\n", "from absbox import API,mkDeal,EnginePath\n", "\n", "localAPI = API(EnginePath.DEV,check=False)\n", "\n", "deal_data = {\n", " \"name\":\"Multiple Pools with Mixed Asset\"\n", " ,\"dates\":{\"cutoff\":\"2021-06-01\"\n", " ,\"closing\":\"2021-07-15\"\n", " ,\"firstPay\":\"2021-08-26\"\n", " ,\"payFreq\":[\"DayOfMonth\",20]\n", " ,\"poolFreq\":\"MonthEnd\"\n", " ,\"stated\":\"2030-01-01\"}\n", " ,\"pool\":{\"PoolA\":{'assets':[[\"Mortgage\"\n", " ,{\"originBalance\":2200,\"originRate\":[\"fix\",0.045],\"originTerm\":30\n", " ,\"freq\":\"Monthly\",\"type\":\"Level\",\"originDate\":\"2021-02-01\"}\n", " ,{\"currentBalance\":2200\n", " ,\"currentRate\":0.08\n", " ,\"remainTerm\":30\n", " ,\"status\":\"current\"}]]},\n", " \"PoolB\":{'assets':[[\"Loan\"\n", " ,{\"originBalance\": 80000\n", " ,\"originRate\": [\"floater\",0.045,{\"index\":\"SOFR3M\"\n", " ,\"spread\":0.01\n", " ,\"reset\":\"QuarterEnd\"}]\n", " ,\"originTerm\": 60\n", " ,\"freq\": \"Monthly\"\n", " ,\"type\": \"i_p\"\n", " ,\"originDate\": \"2021-02-01\"}\n", " ,{\"currentBalance\": 65000\n", " ,\"currentRate\": 0.06\n", " ,\"remainTerm\": 60\n", " ,\"status\": \"Current\"}]]}\n", " }\n", " ,\"accounts\":{\"acc01\":{\"balance\":0}\n", " ,\"acc02\":{\"balance\":0}\n", " ,\"liqAcc\":{\"balance\":0}}\n", " ,\"bonds\":{\"A1\":{\"balance\":1000\n", " ,\"rate\":0.07\n", " ,\"originBalance\":1000\n", " ,\"originRate\":0.07\n", " ,\"startDate\":\"2020-01-03\"\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\":\"2020-01-03\"\n", " ,\"rateType\":{\"Fixed\":0.00}\n", " ,\"bondType\":{\"Equity\":None}}}\n", " ,\"fees\":{}\n", " ,\"collect\":[[[\"PoolA\"],\"CollectedCash\",\"acc01\"]\n", " ,[[\"PoolB\"],\"CollectedCash\",\"acc02\"]]\n", " ,\"waterfall\":{\"Amortizing\":[\n", " [\"accrueAndPayInt\",\"acc01\",[\"A1\"]]\n", " ,[\"payPrin\",\"acc01\",[\"A1\"]]\n", " ,[\"payPrin\",\"acc01\",[\"B\"]]\n", " ,sellBothPool\n", " ,[\"payPrinResidual\",\"acc01\",[\"B\"]]\n", " ]}\n", " ,\"status\":(\"PreClosing\",\"Amortizing\")\n", "}\n", "\n", "\n", "deal = mkDeal(deal_data)" ] }, { "cell_type": "code", "execution_count": 105, "id": "6ded7b26", "metadata": {}, "outputs": [], "source": [ "myAssump = {\"poolAssump\" : (\"ByName\"\n", " ,{\"PoolA\":\n", " ((\"Mortgage\",{\"CDR\":0.02} ,None, None, None)\n", " ,None\n", " ,None)\n", " ,\"PoolB\":\n", " ((\"Loan\",{\"CDR\":0.01} ,None, None, None)\n", " ,None\n", " ,None)}\n", " )\n", " ,\"runAssump\" : [(\"interest\",(\"LIBOR6M\",0.04)\n", " ,(\"SOFR3M\",0.04))\n", " ,(\"inspect\",(\"MonthEnd\",(\"poolBalance\",\"PoolB\"))\n", " ,(\"MonthEnd\",(\"poolBalance\",\"PoolA\")))\n", " ]\n", " ,\"read\":True}" ] }, { "cell_type": "code", "execution_count": 106, "id": "e4220c96", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Warning Message from server:\n",
       "Bond B is not paid off\n",
       "Account acc02 has cash to be distributed\n",
       "Account liqAcc has cash to be distributed\n",
       "
\n" ], "text/plain": [ "Warning Message from server:\n", "\u001b[1;33mBond B is not paid off\u001b[0m\n", "\u001b[1;33mAccount acc02 has cash to be distributed\u001b[0m\n", "\u001b[1;33mAccount liqAcc has cash to be distributed\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "r = localAPI.run(deal,**myAssump)" ] }, { "cell_type": "markdown", "id": "0c98c297", "metadata": {}, "source": [ "Now when sell assets in the pool, the balance equals to the liquidation proceeds" ] }, { "cell_type": "code", "execution_count": 107, "id": "2954cec7", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "64935.41" ] }, "execution_count": 107, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r['pool']['flow']['PoolB'].loc[\"2022-08-31\"].Balance + r['pool']['flow']['PoolA'].loc[\"2022-08-31\"].Balance" ] }, { "cell_type": "code", "execution_count": 108, "id": "5e6f7646-6711-4dd3-832b-26d223edf818", "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", "
balancechangememo
date
2022-09-2064935.4164935.41<Liquidation:>
2022-10-2064935.410.00<Liquidation:>
\n", "
" ], "text/plain": [ " balance change memo\n", "date \n", "2022-09-20 64935.41 64935.41 \n", "2022-10-20 64935.41 0.00 " ] }, "execution_count": 108, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r['accounts']['liqAcc']" ] }, { "cell_type": "markdown", "id": "218f96d4", "metadata": {}, "source": [ "#### Sell A Pool Only" ] }, { "cell_type": "markdown", "id": "a64ea0bf", "metadata": {}, "source": [ "Notice there are two pools in the deal, user has the option to sell one of them" ] }, { "cell_type": "code", "execution_count": 53, "id": "4946aee1", "metadata": {}, "outputs": [], "source": [ "sellAPool = [\"If\", [\"all\", ['>',\"2022-09-01\"], ['<',\"2022-10-01\"] ]\n", " ,[\"sellAsset\", [\"Current|Defaulted\", 1.0, 0], \"liqAcc\", ['PoolA']]\n", " ]" ] }, { "cell_type": "markdown", "id": "c35a43b8", "metadata": {}, "source": [ "Let's swap the waterfall action with the one selling `PoolA` only" ] }, { "cell_type": "code", "execution_count": 109, "id": "935d8724", "metadata": {}, "outputs": [], "source": [ "sellPoolADeal = deal & lens.waterfall['Amortizing'][3].set(sellAPool)\n", "## it's fancy lens' way to do it , you can do it a straight forwad way like:\n", "\n", "## deal.waterfall['Amortizing'][3] = sellAPool \n", "## which will change the data in-place" ] }, { "cell_type": "code", "execution_count": 62, "id": "fc6414d7", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Warning Message from server:\n",
       "Bond B is not paid off\n",
       "Account acc02 has cash to be distributed\n",
       "Account liqAcc has cash to be distributed\n",
       "
\n" ], "text/plain": [ "Warning Message from server:\n", "\u001b[1;33mBond B is not paid off\u001b[0m\n", "\u001b[1;33mAccount acc02 has cash to be distributed\u001b[0m\n", "\u001b[1;33mAccount liqAcc has cash to be distributed\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "r = localAPI.run(sellPoolADeal,**myAssump)" ] }, { "cell_type": "markdown", "id": "07bb0162", "metadata": {}, "source": [ "Now , the selling only have proceeds from pool A" ] }, { "cell_type": "code", "execution_count": 66, "id": "cfb2913d", "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", "
balancechangememo
date
2022-09-20905.23905.23<Liquidation:PoolA>
\n", "
" ], "text/plain": [ " balance change memo\n", "date \n", "2022-09-20 905.23 905.23 " ] }, "execution_count": 66, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r['accounts']['liqAcc']" ] }, { "cell_type": "markdown", "id": "b8a2f6dc", "metadata": {}, "source": [ "Now , once the pool has been liquidated, no more cash will be collected after `2022-9-20`" ] }, { "cell_type": "code", "execution_count": 74, "id": "89346318", "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-04-301199.3270.818.4602.1802.180.08NoneNone759.850030.23030.23
2022-05-311126.1871.167.9801.9801.980.08NoneNone831.010032.21032.21
2022-06-301052.7471.517.4901.9301.930.08NoneNone902.520034.14034.14
2022-07-31979.1371.877.0001.7401.740.08NoneNone974.390035.88035.88
2022-08-31905.2372.236.5101.6701.670.08NoneNone1046.620037.55037.55
\n", "
" ], "text/plain": [ " Balance Principal Interest Prepayment Default Recovery Loss \\\n", "Date \n", "2022-04-30 1199.32 70.81 8.46 0 2.18 0 2.18 \n", "2022-05-31 1126.18 71.16 7.98 0 1.98 0 1.98 \n", "2022-06-30 1052.74 71.51 7.49 0 1.93 0 1.93 \n", "2022-07-31 979.13 71.87 7.00 0 1.74 0 1.74 \n", "2022-08-31 905.23 72.23 6.51 0 1.67 0 1.67 \n", "\n", " WAC BorrowerNum PrepayPenalty CumPrincipal CumPrepay \\\n", "Date \n", "2022-04-30 0.08 None None 759.85 0 \n", "2022-05-31 0.08 None None 831.01 0 \n", "2022-06-30 0.08 None None 902.52 0 \n", "2022-07-31 0.08 None None 974.39 0 \n", "2022-08-31 0.08 None None 1046.62 0 \n", "\n", " CumDelinq CumDefault CumRecovery CumLoss \n", "Date \n", "2022-04-30 0 30.23 0 30.23 \n", "2022-05-31 0 32.21 0 32.21 \n", "2022-06-30 0 34.14 0 34.14 \n", "2022-07-31 0 35.88 0 35.88 \n", "2022-08-31 0 37.55 0 37.55 " ] }, "execution_count": 74, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r[\"pool\"]['flow']['PoolA'].tail(5)" ] }, { "cell_type": "code", "execution_count": 73, "id": "8219fcf1", "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-04-3064245.610272.82054.86054.860.05000595.310595.31
2022-05-3164192.570263.80053.04053.040.05000648.350648.35
2022-06-3064137.800272.36054.77054.770.05000703.120703.12
2022-07-3164084.850263.36052.95052.950.05000756.070756.07
2022-08-3164030.180271.90054.67054.670.05000810.740810.74
\n", "
" ], "text/plain": [ " Balance Principal Interest Prepayment Default Recovery \\\n", "Date \n", "2022-04-30 64245.61 0 272.82 0 54.86 0 \n", "2022-05-31 64192.57 0 263.80 0 53.04 0 \n", "2022-06-30 64137.80 0 272.36 0 54.77 0 \n", "2022-07-31 64084.85 0 263.36 0 52.95 0 \n", "2022-08-31 64030.18 0 271.90 0 54.67 0 \n", "\n", " Loss WAC CumPrincipal CumPrepay CumDelinq CumDefault \\\n", "Date \n", "2022-04-30 54.86 0.05 0 0 0 595.31 \n", "2022-05-31 53.04 0.05 0 0 0 648.35 \n", "2022-06-30 54.77 0.05 0 0 0 703.12 \n", "2022-07-31 52.95 0.05 0 0 0 756.07 \n", "2022-08-31 54.67 0.05 0 0 0 810.74 \n", "\n", " CumRecovery CumLoss \n", "Date \n", "2022-04-30 0 595.31 \n", "2022-05-31 0 648.35 \n", "2022-06-30 0 703.12 \n", "2022-07-31 0 756.07 \n", "2022-08-31 0 810.74 " ] }, "execution_count": 73, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r[\"pool\"]['flow']['PoolB'].tail(5)" ] }, { "cell_type": "markdown", "id": "0448e9b9", "metadata": {}, "source": [ "#### Sell Both Pool Explicitly" ] }, { "cell_type": "code", "execution_count": 67, "id": "219f1bb4", "metadata": {}, "outputs": [], "source": [ "sellABPool = [\"If\", [\"all\", ['>',\"2022-09-01\"], ['<',\"2022-10-01\"] ]\n", " ,[\"sellAsset\", [\"Current|Defaulted\", 1.0, 0], \"liqAcc\", ['PoolA','PoolB']]\n", " ]" ] }, { "cell_type": "code", "execution_count": 68, "id": "6627ab5e", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Warning Message from server:\n",
       "Bond B is not paid off\n",
       "Account acc02 has cash to be distributed\n",
       "Account liqAcc has cash to be distributed\n",
       "
\n" ], "text/plain": [ "Warning Message from server:\n", "\u001b[1;33mBond B is not paid off\u001b[0m\n", "\u001b[1;33mAccount acc02 has cash to be distributed\u001b[0m\n", "\u001b[1;33mAccount liqAcc has cash to be distributed\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "sellPoolABDeal = deal & lens.waterfall['Amortizing'][3].set(sellABPool)\n", "r = localAPI.run(sellPoolABDeal,**myAssump)" ] }, { "cell_type": "code", "execution_count": 69, "id": "da59bb45", "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", "
balancechangememo
date
2022-09-2064935.4164935.41<Liquidation:PoolA,PoolB>
\n", "
" ], "text/plain": [ " balance change memo\n", "date \n", "2022-09-20 64935.41 64935.41 " ] }, "execution_count": 69, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r['accounts']['liqAcc']" ] }, { "cell_type": "code", "execution_count": 71, "id": "a352e192", "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-04-3064245.610272.82054.86054.860.05000595.310595.31
2022-05-3164192.570263.80053.04053.040.05000648.350648.35
2022-06-3064137.800272.36054.77054.770.05000703.120703.12
2022-07-3164084.850263.36052.95052.950.05000756.070756.07
2022-08-3164030.180271.90054.67054.670.05000810.740810.74
\n", "
" ], "text/plain": [ " Balance Principal Interest Prepayment Default Recovery \\\n", "Date \n", "2022-04-30 64245.61 0 272.82 0 54.86 0 \n", "2022-05-31 64192.57 0 263.80 0 53.04 0 \n", "2022-06-30 64137.80 0 272.36 0 54.77 0 \n", "2022-07-31 64084.85 0 263.36 0 52.95 0 \n", "2022-08-31 64030.18 0 271.90 0 54.67 0 \n", "\n", " Loss WAC CumPrincipal CumPrepay CumDelinq CumDefault \\\n", "Date \n", "2022-04-30 54.86 0.05 0 0 0 595.31 \n", "2022-05-31 53.04 0.05 0 0 0 648.35 \n", "2022-06-30 54.77 0.05 0 0 0 703.12 \n", "2022-07-31 52.95 0.05 0 0 0 756.07 \n", "2022-08-31 54.67 0.05 0 0 0 810.74 \n", "\n", " CumRecovery CumLoss \n", "Date \n", "2022-04-30 0 595.31 \n", "2022-05-31 0 648.35 \n", "2022-06-30 0 703.12 \n", "2022-07-31 0 756.07 \n", "2022-08-31 0 810.74 " ] }, "execution_count": 71, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r[\"pool\"]['flow']['PoolB'].tail(5)" ] }, { "cell_type": "code", "execution_count": 72, "id": "963865c5", "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-04-301199.3270.818.4602.1802.180.08NoneNone759.850030.23030.23
2022-05-311126.1871.167.9801.9801.980.08NoneNone831.010032.21032.21
2022-06-301052.7471.517.4901.9301.930.08NoneNone902.520034.14034.14
2022-07-31979.1371.877.0001.7401.740.08NoneNone974.390035.88035.88
2022-08-31905.2372.236.5101.6701.670.08NoneNone1046.620037.55037.55
\n", "
" ], "text/plain": [ " Balance Principal Interest Prepayment Default Recovery Loss \\\n", "Date \n", "2022-04-30 1199.32 70.81 8.46 0 2.18 0 2.18 \n", "2022-05-31 1126.18 71.16 7.98 0 1.98 0 1.98 \n", "2022-06-30 1052.74 71.51 7.49 0 1.93 0 1.93 \n", "2022-07-31 979.13 71.87 7.00 0 1.74 0 1.74 \n", "2022-08-31 905.23 72.23 6.51 0 1.67 0 1.67 \n", "\n", " WAC BorrowerNum PrepayPenalty CumPrincipal CumPrepay \\\n", "Date \n", "2022-04-30 0.08 None None 759.85 0 \n", "2022-05-31 0.08 None None 831.01 0 \n", "2022-06-30 0.08 None None 902.52 0 \n", "2022-07-31 0.08 None None 974.39 0 \n", "2022-08-31 0.08 None None 1046.62 0 \n", "\n", " CumDelinq CumDefault CumRecovery CumLoss \n", "Date \n", "2022-04-30 0 30.23 0 30.23 \n", "2022-05-31 0 32.21 0 32.21 \n", "2022-06-30 0 34.14 0 34.14 \n", "2022-07-31 0 35.88 0 35.88 \n", "2022-08-31 0 37.55 0 37.55 " ] }, "execution_count": 72, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r[\"pool\"]['flow']['PoolA'].tail(5)" ] }, { "cell_type": "markdown", "id": "5f01846c", "metadata": {}, "source": [ "#### Sell Pool and Buy again\n", "\n", "Liquidate Pool A and buy asset to Pool A again" ] }, { "cell_type": "code", "execution_count": 84, "id": "a978aff1", "metadata": {}, "outputs": [], "source": [ "revol_asset = [\"Mortgage\"\n", " ,{\"originBalance\":2200,\"originRate\":[\"fix\",0.045],\"originTerm\":30\n", " ,\"freq\":\"Monthly\",\"type\":\"Level\",\"originDate\":\"2021-02-01\"}\n", " ,{\"currentBalance\":2200\n", " ,\"currentRate\":0.08\n", " ,\"remainTerm\":30\n", " ,\"status\":\"current\"}]\n", "\n", "poolToBy = ([\"constant\",revol_asset]\n", " ,(\"Pool\",(\"Mortgage\",{\"CDR\":0.07},None,None,None)\n", " ,None\n", " ,None))\n", "\n", "withBuyAssump = myAssump & lens['runAssump'].modify(lambda xs: xs+[ (\"revolving\",{\"poolOne\":poolToBy})])" ] }, { "cell_type": "code", "execution_count": 100, "id": "c920fcb8", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Warning Message from server:\n",
       "Account acc01 has cash to be distributed\n",
       "Account acc02 has cash to be distributed\n",
       "
\n" ], "text/plain": [ "Warning Message from server:\n", "\u001b[1;33mAccount acc01 has cash to be distributed\u001b[0m\n", "\u001b[1;33mAccount acc02 has cash to be distributed\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "buyAsset = [\"If\", [\"all\", ['>',\"2022-11-01\"], ['<',\"2022-12-01\"] ]\n", " ,[\"buyAsset2\", [\"Current|Defaulted\", 0.5, 0], \"liqAcc\",None, \"poolOne\",'PoolA']]\n", "\n", "sellAndBuyDeal = sellPoolADeal & lens.waterfall['Amortizing'].call_mut(\"insert\",3,buyAsset)\n", "\n", "\n", "r = localAPI.run(sellAndBuyDeal,**withBuyAssump)" ] }, { "cell_type": "code", "execution_count": 104, "id": "2df1a6e8", "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
2025-01-20224.5255.201.8601.7201.720.08NoneNone1424.760.00.0161.180.0161.18
2025-02-20167.9155.241.4801.3701.370.08NoneNone1480.000.00.0162.550.0162.55
2025-03-20111.6955.291.1100.9300.930.08NoneNone1535.290.00.0163.480.0163.48
2025-04-2055.6855.330.7300.6800.680.08NoneNone1590.620.00.0164.160.0164.16
2025-05-200.0055.350.3600.3300.330.08NoneNone1645.970.00.0164.490.0164.49
\n", "
" ], "text/plain": [ " Balance Principal Interest Prepayment Default Recovery Loss \\\n", "Date \n", "2025-01-20 224.52 55.20 1.86 0 1.72 0 1.72 \n", "2025-02-20 167.91 55.24 1.48 0 1.37 0 1.37 \n", "2025-03-20 111.69 55.29 1.11 0 0.93 0 0.93 \n", "2025-04-20 55.68 55.33 0.73 0 0.68 0 0.68 \n", "2025-05-20 0.00 55.35 0.36 0 0.33 0 0.33 \n", "\n", " WAC BorrowerNum PrepayPenalty CumPrincipal CumPrepay \\\n", "Date \n", "2025-01-20 0.08 None None 1424.76 0.0 \n", "2025-02-20 0.08 None None 1480.00 0.0 \n", "2025-03-20 0.08 None None 1535.29 0.0 \n", "2025-04-20 0.08 None None 1590.62 0.0 \n", "2025-05-20 0.08 None None 1645.97 0.0 \n", "\n", " CumDelinq CumDefault CumRecovery CumLoss \n", "Date \n", "2025-01-20 0.0 161.18 0.0 161.18 \n", "2025-02-20 0.0 162.55 0.0 162.55 \n", "2025-03-20 0.0 163.48 0.0 163.48 \n", "2025-04-20 0.0 164.16 0.0 164.16 \n", "2025-05-20 0.0 164.49 0.0 164.49 " ] }, "execution_count": 104, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r['pool']['flow']['PoolA'].tail(5)" ] }, { "cell_type": "code", "execution_count": 102, "id": "511f6453", "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", "
balancechangememo
date
2022-09-20905.23905.23<Liquidation:PoolA>
2022-11-200.00-905.23<PurchaseAsset:poolOne,1810.46>
\n", "
" ], "text/plain": [ " balance change memo\n", "date \n", "2022-09-20 905.23 905.23 \n", "2022-11-20 0.00 -905.23 " ] }, "execution_count": 102, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r['accounts']['liqAcc']" ] }, { "cell_type": "code", "execution_count": 103, "id": "c294bdae", "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", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
balancechangememo
date
2022-11-200.000.00<PayInt:A1>
2022-11-200.000.00<PayPrin:A1>
2022-11-200.000.00<PayPrin:B>
2022-11-200.000.00<PayPrin:B>
2022-11-300.000.00<PoolPoolA:CollectedCash>
2022-12-200.000.00<PayInt:A1>
2022-12-200.000.00<PayPrin:A1>
2022-12-200.000.00<PayPrin:B>
2022-12-200.000.00<PayPrin:B>
2022-12-3166.3866.38<PoolPoolA:CollectedCash>
2023-01-2066.380.00<PayInt:A1>
2023-01-2066.380.00<PayPrin:A1>
2023-01-200.00-66.38<PayPrin:B>
2023-01-200.000.00<PayPrin:B>
2023-01-3165.9765.97<PoolPoolA:CollectedCash>
2023-02-2065.970.00<PayInt:A1>
2023-02-2065.970.00<PayPrin:A1>
2023-02-200.00-65.97<PayPrin:B>
2023-02-200.000.00<PayPrin:B>
2023-02-2865.5765.57<PoolPoolA:CollectedCash>
2023-03-2065.570.00<PayInt:A1>
2023-03-2065.570.00<PayPrin:A1>
2023-03-200.00-65.57<PayPrin:B>
2023-03-200.000.00<PayPrin:B>
\n", "
" ], "text/plain": [ " balance change memo\n", "date \n", "2022-11-20 0.00 0.00 \n", "2022-11-20 0.00 0.00 \n", "2022-11-20 0.00 0.00 \n", "2022-11-20 0.00 0.00 \n", "2022-11-30 0.00 0.00 \n", "2022-12-20 0.00 0.00 \n", "2022-12-20 0.00 0.00 \n", "2022-12-20 0.00 0.00 \n", "2022-12-20 0.00 0.00 \n", "2022-12-31 66.38 66.38 \n", "2023-01-20 66.38 0.00 \n", "2023-01-20 66.38 0.00 \n", "2023-01-20 0.00 -66.38 \n", "2023-01-20 0.00 0.00 \n", "2023-01-31 65.97 65.97 \n", "2023-02-20 65.97 0.00 \n", "2023-02-20 65.97 0.00 \n", "2023-02-20 0.00 -65.97 \n", "2023-02-20 0.00 0.00 \n", "2023-02-28 65.57 65.57 \n", "2023-03-20 65.57 0.00 \n", "2023-03-20 65.57 0.00 \n", "2023-03-20 0.00 -65.57 \n", "2023-03-20 0.00 0.00 " ] }, "execution_count": 103, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r['accounts']['acc01'].loc[\"2022-11-20\":\"2023-03-20\"]" ] }, { "cell_type": "code", "execution_count": null, "id": "123cd714", "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.11.9" } }, "nbformat": 4, "nbformat_minor": 5 }