{ "cells": [ { "cell_type": "markdown", "id": "e1719fec", "metadata": {}, "source": [ "### Interest Over Interest on Bond" ] }, { "cell_type": "code", "execution_count": 3, "id": "555963fd", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "from absbox.local.generic import Generic\n", "pd.set_option(\"display.max_rows\",None)" ] }, { "cell_type": "markdown", "id": "358ca6bd", "metadata": {}, "source": [ "#### Interest Due" ] }, { "cell_type": "code", "execution_count": 130, "id": "f8319644", "metadata": {}, "outputs": [], "source": [ "interestDueExample = Generic(\n", " \"TEST01\"\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}),(\"acc02\",{\"balance\":0}),)\n", " ,((\"A1\",{\"balance\":1000\n", " ,\"rate\":0.30\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", " }))\n", " ,tuple()\n", " ,{\"amortizing\":[\n", " [\"accrueAndPayInt\",\"acc02\",[\"A1\"]]\n", " ,[\"payPrin\",\"acc01\",[\"A1\"]]\n", " ,[\"payPrin\",\"acc01\",[\"B\"]]\n", " ,[\"payIntResidual\",\"acc01\",\"B\"]\n", " ]}\n", " ,[[\"CollectedInterest\",\"acc02\"]\n", " ,[\"CollectedPrincipal\",\"acc01\"]\n", " ,[\"CollectedPrepayment\",\"acc01\"]\n", " ,[\"CollectedRecoveries\",\"acc01\"]]\n", " ,None\n", " ,None\n", " ,None\n", " ,None\n", " ,(\"PreClosing\",\"Amortizing\")\n", " )" ] }, { "cell_type": "code", "execution_count": 133, "id": "702f8975", "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.26.4, server:0.27.21\n",
       "
\n" ], "text/plain": [ "✅\u001b[1;32mConnected, local li\u001b[0m\u001b[1;32mb:0\u001b[0m\u001b[1;32m.\u001b[0m\u001b[1;32m26.4\u001b[0m\u001b[1;32m, server:\u001b[0m\u001b[1;32m0.27\u001b[0m\u001b[1;32m.\u001b[0m\u001b[1;32m21\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from absbox import API,EnginePath\n", "localAPI = API(EnginePath.DEV,lang='english',check=False)\n", "#localAPI = API(\"https://absbox.org/api/dev\",lang='english',check=False)" ] }, { "cell_type": "code", "execution_count": 134, "id": "2b8b4cbf", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Warning Message from server:\n",
       "Account acc02 has cash to be distributed\n",
       "
\n" ], "text/plain": [ "Warning Message from server:\n", "\u001b[1;33mAccount acc02 has cash to be distributed\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "r = localAPI.run(interestDueExample\n", " ,poolAssump = None\n", " ,runAssump = None\n", " ,read=True)" ] }, { "cell_type": "code", "execution_count": 136, "id": "95408266", "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", "
balanceinterestprincipalratecashintDueintOverIntfactormemo
date
2021-06-20583.0554.49416.950.3471.4411.2600.58305[<PayInt:A1>, <PayPrin:A1>]
2021-07-20477.0811.88105.970.3117.8513.7500.47708[<PayInt:A1>, <PayPrin:A1>]
2021-08-20370.3911.17106.690.3117.8614.7300.37039[<PayInt:A1>, <PayPrin:A1>]
2021-09-20263.0010.46107.390.3117.8513.7000.26300[<PayInt:A1>, <PayPrin:A1>]
2021-10-20154.909.75108.100.3117.8510.4300.15490[<PayInt:A1>, <PayPrin:A1>]
2021-11-2046.079.03108.830.3117.865.3400.04607[<PayInt:A1>, <PayPrin:A1>]
2021-12-200.006.4746.070.352.540.0000.00000[<PayInt:A1>, <PayPrin:A1>]
\n", "
" ], "text/plain": [ " balance interest principal rate cash intDue intOverInt \\\n", "date \n", "2021-06-20 583.05 54.49 416.95 0.3 471.44 11.26 0 \n", "2021-07-20 477.08 11.88 105.97 0.3 117.85 13.75 0 \n", "2021-08-20 370.39 11.17 106.69 0.3 117.86 14.73 0 \n", "2021-09-20 263.00 10.46 107.39 0.3 117.85 13.70 0 \n", "2021-10-20 154.90 9.75 108.10 0.3 117.85 10.43 0 \n", "2021-11-20 46.07 9.03 108.83 0.3 117.86 5.34 0 \n", "2021-12-20 0.00 6.47 46.07 0.3 52.54 0.00 0 \n", "\n", " factor memo \n", "date \n", "2021-06-20 0.58305 [, ] \n", "2021-07-20 0.47708 [, ] \n", "2021-08-20 0.37039 [, ] \n", "2021-09-20 0.26300 [, ] \n", "2021-10-20 0.15490 [, ] \n", "2021-11-20 0.04607 [, ] \n", "2021-12-20 0.00000 [, ] " ] }, "execution_count": 136, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r['bonds']['A1']" ] }, { "cell_type": "markdown", "id": "cee24637", "metadata": {}, "source": [ "##### Backout Date: 2021-07-20" ] }, { "cell_type": "code", "execution_count": 137, "id": "a24dd59f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "14.376575342465753" ] }, "execution_count": 137, "metadata": {}, "output_type": "execute_result" } ], "source": [ "583.05 * 0.3 * 30/365 # new interest accrued" ] }, { "cell_type": "code", "execution_count": 138, "id": "431b3e5f", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "25.636575342465754" ] }, "execution_count": 138, "metadata": {}, "output_type": "execute_result" } ], "source": [ "14.376575342465753 + 11.26 # remain interest due" ] }, { "cell_type": "code", "execution_count": 139, "id": "980c540d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "13.756575342465753" ] }, "execution_count": 139, "metadata": {}, "output_type": "execute_result" } ], "source": [ "25.636575342465754 - 11.88 ## remaining interest due at end of 2021-07-20" ] }, { "cell_type": "markdown", "id": "5e6aaf57", "metadata": {}, "source": [ "##### Backout Date: 2021-12-20" ] }, { "cell_type": "code", "execution_count": 140, "id": "e195eece", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "6.475972602739726" ] }, "execution_count": 140, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# total due int at begin of 2021-12-20\n", "\n", "46.07 * 0.3 * 30/365 + 5.34" ] }, { "cell_type": "code", "execution_count": 141, "id": "b170a07d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.00597260273972644" ] }, "execution_count": 141, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# remain interest due at end of 2021-12-20\n", "6.475972602739726 - 6.47" ] }, { "cell_type": "markdown", "id": "d2eb307c", "metadata": {}, "source": [ "#### Interest Over Interest" ] }, { "cell_type": "code", "execution_count": 142, "id": "548191d7", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(('A1',\n", " {'balance': 1000,\n", " 'rate': 0.3,\n", " 'originBalance': 1000,\n", " 'originRate': 0.07,\n", " 'startDate': '2020-01-03',\n", " 'rateType': {'Fixed': 0.08},\n", " 'bondType': {'Sequential': None}}),\n", " ('B',\n", " {'balance': 1000,\n", " 'rate': 0.0,\n", " 'originBalance': 1000,\n", " 'originRate': 0.07,\n", " 'startDate': '2020-01-03',\n", " 'rateType': {'Fixed': 0.0},\n", " 'bondType': {'Equity': None}}))" ] }, "execution_count": 142, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from lenses import lens\n", "\n", "interestDueExample.bonds" ] }, { "cell_type": "code", "execution_count": 143, "id": "60b964c9", "metadata": {}, "outputs": [], "source": [ "interestOverInterestType = (\"withIntOverInt\", (\"inflate\", 0.2), {\"fix\":0.001} )\n", "\n", "interestOverInterestExample = lens.bonds[0][1]['rateType'].set(interestOverInterestType)(interestDueExample)" ] }, { "cell_type": "code", "execution_count": 144, "id": "dea5cb18", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "('A1',\n", " {'balance': 1000,\n", " 'rate': 0.3,\n", " 'originBalance': 1000,\n", " 'originRate': 0.07,\n", " 'startDate': '2020-01-03',\n", " 'rateType': ('withIntOverInt', ('inflate', 0.2), {'fix': 0.001}),\n", " 'bondType': {'Sequential': None}})" ] }, "execution_count": 144, "metadata": {}, "output_type": "execute_result" } ], "source": [ "interestOverInterestExample.bonds[0]" ] }, { "cell_type": "code", "execution_count": 145, "id": "b2470e2a", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
Warning Message from server:\n",
       "Account acc02 has cash to be distributed\n",
       "
\n" ], "text/plain": [ "Warning Message from server:\n", "\u001b[1;33mAccount acc02 has cash to be distributed\u001b[0m\n" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "r = localAPI.run(interestOverInterestExample\n", " ,poolAssump = None\n", " ,runAssump = None\n", " ,read=True)" ] }, { "cell_type": "code", "execution_count": 146, "id": "99d96413", "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", "
balanceinterestprincipalratecashintDueintOverIntfactormemo
date
2021-07-20477.0811.88105.970.3117.8514.0800.47708[<PayInt:A1>, <PayPrin:A1>]
2021-08-20370.3911.17106.690.3117.8615.4900.37039[<PayInt:A1>, <PayPrin:A1>]
\n", "
" ], "text/plain": [ " balance interest principal rate cash intDue intOverInt \\\n", "date \n", "2021-07-20 477.08 11.88 105.97 0.3 117.85 14.08 0 \n", "2021-08-20 370.39 11.17 106.69 0.3 117.86 15.49 0 \n", "\n", " factor memo \n", "date \n", "2021-07-20 0.47708 [, ] \n", "2021-08-20 0.37039 [, ] " ] }, "execution_count": 146, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r['bonds']['A1'].loc[\"2021-07-20\":\"2021-08-20\"]" ] }, { "cell_type": "markdown", "id": "c9cfb466", "metadata": {}, "source": [ "##### Backout 2021-08-20" ] }, { "cell_type": "code", "execution_count": 147, "id": "616ef2f6", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "12.15573698630137" ] }, "execution_count": 147, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# new due int amount\n", "477.08 * 0.3 * 31/365" ] }, { "cell_type": "code", "execution_count": 148, "id": "0e5a19cc", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "26.23573698630137" ] }, "execution_count": 148, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# total due int at begin of 2021-08-20\n", "12.15573698630137 + 14.08" ] }, { "cell_type": "code", "execution_count": 149, "id": "b40a3bed", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.43050082191780814" ] }, "execution_count": 149, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# int over int\n", "14.08 * (0.3*1.2) * 31/365" ] }, { "cell_type": "code", "execution_count": 150, "id": "c6a2e0c0", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "10.739499178082191" ] }, "execution_count": 150, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# amount to paid of interest due\n", "(11.17 - 0.43050082191780814)" ] }, { "cell_type": "code", "execution_count": 151, "id": "fff4ede7", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "15.496237808219178" ] }, "execution_count": 151, "metadata": {}, "output_type": "execute_result" } ], "source": [ "## due int after interest payment\n", "26.23573698630137 - 10.739499178082191" ] } ], "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 }