diff options
Diffstat (limited to 'python/notebooks')
| -rw-r--r-- | python/notebooks/Interest Statement.ipynb | 106 |
1 files changed, 83 insertions, 23 deletions
diff --git a/python/notebooks/Interest Statement.ipynb b/python/notebooks/Interest Statement.ipynb index 5e016fcb..bd053ff3 100644 --- a/python/notebooks/Interest Statement.ipynb +++ b/python/notebooks/Interest Statement.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 49, "metadata": {}, "outputs": [], "source": [ @@ -23,12 +23,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 104, "metadata": {}, "outputs": [], "source": [ "from IPython.display import display\n", "from pandas.tseries.offsets import BDay\n", + "import numpy as np\n", "\n", "def f(df_balances, df_rates, broker, start_date, end_date):\n", " df = (df_balances[df_balances.broker == broker].\n", @@ -36,11 +37,22 @@ " unstack(\"strategy\"))\n", " df[df.isnull()] = 0.\n", " drange = pd.date_range(pd.Timestamp(start_date) - BDay(), end_date)\n", - " rates = df_rates.reindex(drange, method=\"ffill\").values /100 /360\n", - " df = df.reindex(drange, method=\"ffill\") * rates\n", - " df = df.loc[start_date:]\n", - " display(df.sum().to_frame(name='amount'))\n", - " print(df.sum().sum())\n", + " rates = df_rates.reindex(drange, method=\"ffill\") /100 /360\n", + " df = df.reindex(drange, method=\"ffill\")\n", + " if broker in [\"BAML_ISDA\", \"CITI\"]:\n", + " d = {}\n", + " for strat in df:\n", + " s = df.loc[start_date:, strat]\n", + " ir_bal = 0.\n", + " for bal, r in zip(s.values, rates.loc[start_date:, 'rate'].values):\n", + " bal += ir_bal\n", + " ir_bal += bal * r\n", + " d[strat] = ir_bal\n", + " result = pd.Series(d, name='amount')\n", + " else:\n", + " result = (df.loc[start_date:] * rates.loc[start_date:].values).sum().to_frame(name='amount')\n", + " display(result)\n", + " print(result.sum())\n", " \n", "from functools import partial\n", "f_print = partial(f, df_balances, df_rates)" @@ -48,9 +60,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 105, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "6f7a35fe5dcd486480d9819426ef7f6d", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "VBox(children=(HBox(children=(Dropdown(description='Broker:', index=3, options=('BAML_FCM', 'BAML_ISDA', 'BNP'…" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], "source": [ "from ipywidgets import widgets, Layout\n", "import datetime\n", @@ -63,12 +90,12 @@ "start_date = widgets.DatePicker(\n", " description='start:',\n", " disabled=False,\n", - " value=datetime.date(2019, 6, 1)\n", + " value=datetime.date(2019, 9, 1)\n", ")\n", "end_date = widgets.DatePicker(\n", " description='end:',\n", " disabled=False,\n", - " value=datetime.date(2019, 6, 30)\n", + " value=datetime.date(2019, 9, 30)\n", ")\n", "output = widgets.interactive_output(f_print, {'broker': broker_widget, 'start_date': start_date, 'end_date': end_date})\n", "output.layout= Layout(margin='auto auto auto 90px')\n", @@ -81,24 +108,57 @@ "metadata": {}, "outputs": [], "source": [ - "f(df_balances, df_rates, \"MS\", \"2019-06-01\", \"2019-06-30\").sum(axis=1)" + "df_balances[df_balances.broker=='BAML_ISDA'].loc[\"2019-06-10\"]" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 106, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "date\n", + "2019-08-30 -910,332.93\n", + "2019-09-02 -910,332.93\n", + "2019-09-03 -910,332.93\n", + "2019-09-04 -911,899.69\n", + "2019-09-05 -911,899.69\n", + "2019-09-06 -911,899.69\n", + "2019-09-09 -911,899.69\n", + "2019-09-10 -911,899.69\n", + "2019-09-11 -911,899.69\n", + "2019-09-12 -911,899.69\n", + "2019-09-13 -911,899.69\n", + "2019-09-16 -911,899.69\n", + "2019-09-17 -911,899.69\n", + "2019-09-18 -911,899.69\n", + "2019-09-19 -911,899.69\n", + "2019-09-20 -911,899.69\n", + "2019-09-23 -911,899.69\n", + "2019-09-24 -911,899.69\n", + "2019-09-25 -911,899.69\n", + "2019-09-26 -911,899.69\n", + "2019-09-27 -911,899.69\n", + "2019-09-30 -911,899.69\n", + "2019-10-01 -911,899.69\n", + "2019-10-02 -913,453.48\n", + "2019-10-03 -913,453.48\n", + "2019-10-04 -913,453.48\n", + "2019-10-07 -913,453.48\n", + "Name: amount, dtype: float64" + ] + }, + "execution_count": 106, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "df_balances[df_balances.broker=='MS'].loc[\"2019-06-10\"]" + "df_baml=df_balances[df_balances.broker == \"BAML_ISDA\"]\n", + "df_baml.groupby(df_baml.index)['amount'].sum()[\"2019-08-30\":]" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { @@ -117,7 +177,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.3" + "version": "3.7.4" } }, "nbformat": 4, |
