From 0f475531b0dfdd5dc300636b66f5aed272dc52d7 Mon Sep 17 00:00:00 2001 From: Xiaoyu Date: Sat, 13 Apr 2024 19:44:49 +0800 Subject: [PATCH] add loan nb --- docs/source/nbsample/index.rst | 3 +- docs/source/nbsample/single_loan.ipynb | 178 +++++++++++++++++++++++++ 2 files changed, 180 insertions(+), 1 deletion(-) create mode 100644 docs/source/nbsample/single_loan.ipynb diff --git a/docs/source/nbsample/index.rst b/docs/source/nbsample/index.rst index fdda1e3..e621c7a 100644 --- a/docs/source/nbsample/index.rst +++ b/docs/source/nbsample/index.rst @@ -4,4 +4,5 @@ Notebook Samples .. toctree:: :maxdepth: 1 - single_invoice \ No newline at end of file + single_invoice + single_loan \ No newline at end of file diff --git a/docs/source/nbsample/single_loan.ipynb b/docs/source/nbsample/single_loan.ipynb new file mode 100644 index 0000000..3d6aa25 --- /dev/null +++ b/docs/source/nbsample/single_loan.ipynb @@ -0,0 +1,178 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Loan" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
Connecting engine server -> https://absbox.org/api/dev\n",
+       "
\n" + ], + "text/plain": [ + "\u001b[1;35mConnecting engine server -> \u001b[0m\u001b[1;4;35mhttps://absbox.org/api/dev\u001b[0m\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/html": [ + "
Connected, local lib:0.26.6, server:0.26.5\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.6\u001b[0m\u001b[1;32m, server:\u001b[0m\u001b[1;32m0.26\u001b[0m\u001b[1;32m.\u001b[0m\u001b[1;32m5\u001b[0m\n" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "from absbox import API\n", + "\n", + "localAPI = API(\"https://absbox.org/api/dev\",lang='english',check=False)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "loan1 = [\"Loan\"\n", + " ,{\"originBalance\": 80000\n", + " ,\"originRate\": [\"floater\",0.045,{\"index\":\"SOFR3M\"\n", + " ,\"spread\":0.01\n", + " ,\"reset\":\"QuarterEnd\"}]\n", + " ,\"originTerm\": 24\n", + " ,\"freq\": \"Monthly\"\n", + " ,\"type\": \"i_p\"\n", + " ,\"originDate\": \"2021-03-01\"}\n", + " ,{\"currentBalance\": 65000\n", + " ,\"currentRate\": 0.06\n", + " ,\"remainTerm\": 12\n", + " ,\"status\": \"Current\"}]" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[('2022-03-01', 65000, 0, 0., 0, 0, 0, 0, 0.06, 0, 0, 0, 0, 0, 0),\n", + " ('2022-04-01', 65000, 0, 331.23, 0, 0, 0, 0, 0.06, 0, 0, 0, 0, 0, 0),\n", + " ('2022-05-01', 65000, 0, 320.54, 0, 0, 0, 0, 0.06, 0, 0, 0, 0, 0, 0),\n", + " ('2022-06-01', 65000, 0, 331.23, 0, 0, 0, 0, 0.06, 0, 0, 0, 0, 0, 0),\n", + " ('2022-07-01', 65000, 0, 267.12, 0, 0, 0, 0, 0.05, 0, 0, 0, 0, 0, 0),\n", + " ('2022-08-01', 65000, 0, 276.02, 0, 0, 0, 0, 0.05, 0, 0, 0, 0, 0, 0),\n", + " ('2022-09-01', 65000, 0, 276.02, 0, 0, 0, 0, 0.05, 0, 0, 0, 0, 0, 0),\n", + " ('2022-10-01', 65000, 0, 267.12, 0, 0, 0, 0, 0.05, 0, 0, 0, 0, 0, 0),\n", + " ('2022-11-01', 65000, 0, 276.02, 0, 0, 0, 0, 0.05, 0, 0, 0, 0, 0, 0),\n", + " ('2022-12-01', 65000, 0, 267.12, 0, 0, 0, 0, 0.05, 0, 0, 0, 0, 0, 0),\n", + " ('2023-01-01', 65000, 0, 276.02, 0, 0, 0, 0, 0.05, 0, 0, 0, 0, 0, 0),\n", + " ('2023-02-01', 65000, 0, 276.02, 0, 0, 0, 0, 0.05, 0, 0, 0, 0, 0, 0),\n", + " ('2023-03-01', 0, 65000, 249.31, 0, 0, 0, 0, 0.05, 65000, 0, 0, 0, 0, 0)]" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "r = localAPI.runAsset(\"2020-01-02\"\n", + " ,[loan1]\n", + " ,poolAssump=(\"Pool\",(\"Loan\",None,None,None,None)\n", + " ,None\n", + " ,None)\n", + " ,rateAssump=[(\"SOFR3M\",0.04)]\n", + " ,read=True)\n", + "\n", + "list(r[0].to_records())" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[('2022-03-01', 65000., 0., 0., 0, 0., 0, 0., 0.06, 0., 0, 0, 0., 0, 0.),\n", + " ('2022-04-01', 64944.55, 0., 330.95, 0, 55.45, 0, 55.45, 0.06, 0., 0, 0, 55.45, 0, 55.45),\n", + " ('2022-05-01', 64890.93, 0., 320.01, 0, 53.62, 0, 53.62, 0.06, 0., 0, 0, 109.07, 0, 109.07),\n", + " ('2022-06-01', 64835.57, 0., 330.39, 0, 55.36, 0, 55.36, 0.06, 0., 0, 0, 164.43, 0, 164.43),\n", + " ('2022-07-01', 64782.04, 0., 266.22, 0, 53.53, 0, 53.53, 0.05, 0., 0, 0, 217.96, 0, 217.96),\n", + " ('2022-08-01', 64726.77, 0., 274.86, 0, 55.27, 0, 55.27, 0.05, 0., 0, 0, 273.23, 0, 273.23),\n", + " ('2022-09-01', 64671.55, 0., 274.63, 0, 55.22, 0, 55.22, 0.05, 0., 0, 0, 328.45, 0, 328.45),\n", + " ('2022-10-01', 64618.15, 0., 265.55, 0, 53.4, 0, 53.4, 0.05, 0., 0, 0, 381.85, 0, 381.85),\n", + " ('2022-11-01', 64563.02, 0., 274.17, 0, 55.13, 0, 55.13, 0.05, 0., 0, 0, 436.98, 0, 436.98),\n", + " ('2022-12-01', 64509.71, 0., 265.1, 0, 53.31, 0, 53.31, 0.05, 0., 0, 0, 490.29, 0, 490.29),\n", + " ('2023-01-01', 64454.67, 0., 273.71, 0, 55.04, 0, 55.04, 0.05, 0., 0, 0, 545.33, 0, 545.33),\n", + " ('2023-02-01', 64399.68, 0., 273.47, 0, 54.99, 0, 54.99, 0.05, 0., 0, 0, 600.32, 0, 600.32),\n", + " ('2023-03-01', 0., 64350.05, 246.82, 0, 49.63, 0, 49.63, 0.05, 64350.05, 0, 0, 649.95, 0, 649.95)]" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "r = localAPI.runAsset(\"2020-01-02\"\n", + " ,[loan1]\n", + " ,poolAssump=(\"Pool\",(\"Loan\",{\"CDR\":0.01},None,None,None)\n", + " ,None\n", + " ,None)\n", + " ,rateAssump=[(\"SOFR3M\",0.04)]\n", + " ,read=True)\n", + "\n", + "list(r[0].to_records())" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.6" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}