diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/notebooks/Interest Statement.ipynb | 45 | ||||
| -rw-r--r-- | python/notebooks/Single Names Monitoring.ipynb | 67 |
2 files changed, 80 insertions, 32 deletions
diff --git a/python/notebooks/Interest Statement.ipynb b/python/notebooks/Interest Statement.ipynb index 6209ef98..5e016fcb 100644 --- a/python/notebooks/Interest Statement.ipynb +++ b/python/notebooks/Interest Statement.ipynb @@ -27,31 +27,18 @@ "metadata": {}, "outputs": [], "source": [ - "drange = pd.date_range(\"2019-05-01\", \"2019-05-31\")\n", - "df_balances = (df_balances.\n", - " groupby([\"broker\", \"strategy\"], group_keys=False).\n", - " apply(lambda df: df.reindex(drange, method=\"ffill\")).\n", - " dropna())\n", - "df_balances.index.name='date'\n", - "df_balances.join(df_rates)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ "from IPython.display import display\n", + "from pandas.tseries.offsets import BDay\n", "\n", "def f(df_balances, df_rates, broker, start_date, end_date):\n", " df = (df_balances[df_balances.broker == broker].\n", " set_index(\"strategy\", append=True)[\"amount\"].\n", " unstack(\"strategy\"))\n", " df[df.isnull()] = 0.\n", - " drange = pd.date_range(start_date, end_date)\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", " \n", @@ -69,19 +56,19 @@ "import datetime\n", "broker_widget = widgets.Dropdown(\n", " options=df_balances.broker.cat.categories,\n", - " value='GS',\n", + " value='CITI',\n", " description='Broker:',\n", " disabled=False,\n", ")\n", "start_date = widgets.DatePicker(\n", " description='start:',\n", " disabled=False,\n", - " value=datetime.date(2019, 5, 1)\n", + " value=datetime.date(2019, 6, 1)\n", ")\n", "end_date = widgets.DatePicker(\n", " description='end:',\n", " disabled=False,\n", - " value=datetime.date(2019, 5, 31)\n", + " value=datetime.date(2019, 6, 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", @@ -93,6 +80,24 @@ "execution_count": null, "metadata": {}, "outputs": [], + "source": [ + "f(df_balances, df_rates, \"MS\", \"2019-06-01\", \"2019-06-30\").sum(axis=1)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "df_balances[df_balances.broker=='MS'].loc[\"2019-06-10\"]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [] } ], @@ -116,5 +121,5 @@ } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 } diff --git a/python/notebooks/Single Names Monitoring.ipynb b/python/notebooks/Single Names Monitoring.ipynb index 62a1383a..17e0c40d 100644 --- a/python/notebooks/Single Names Monitoring.ipynb +++ b/python/notebooks/Single Names Monitoring.ipynb @@ -3,7 +3,11 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "jupyter": { + "source_hidden": true + } + }, "outputs": [], "source": [ "import pandas as pd\n", @@ -11,7 +15,7 @@ "from analytics.basket_index import MarkitBasketIndex\n", "import matplotlib.pyplot as plt\n", "\n", - "from db import dbengine\n", + "from utils.db import dbengine\n", "from ipywidgets import widgets\n", "engine = dbengine('serenitasdb')" ] @@ -19,7 +23,11 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "jupyter": { + "source_hidden": true + } + }, "outputs": [], "source": [ "w = widgets.Dropdown(\n", @@ -34,17 +42,25 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "jupyter": { + "source_hidden": true + } + }, "outputs": [], "source": [ - "w_1 = widgets.IntSlider(value=31, min=22, max=31, description = 'Series')\n", + "w_1 = widgets.IntSlider(value=32, min=22, max=32, description = 'Series')\n", "w_1" ] }, { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "jupyter": { + "source_hidden": true + } + }, "outputs": [], "source": [ "value_date = (pd.datetime.today() - pd.offsets.BDay(2)).date()\n", @@ -76,7 +92,11 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "jupyter": { + "source_hidden": true + } + }, "outputs": [], "source": [ "#Additions\n", @@ -86,7 +106,11 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "jupyter": { + "source_hidden": true + } + }, "outputs": [], "source": [ "date_range = pd.bdate_range(value_date - 52 * pd.offsets.Week(), value_date, freq='5B')\n", @@ -103,7 +127,11 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "jupyter": { + "source_hidden": true + } + }, "outputs": [], "source": [ "#Top 20 highest cumulative\n", @@ -119,7 +147,22 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "jupyter": { + "source_hidden": true + } + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "jupyter": { + "source_hidden": true + } + }, "outputs": [], "source": [] } @@ -140,9 +183,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.0" + "version": "3.7.3" } }, "nbformat": 4, - "nbformat_minor": 2 + "nbformat_minor": 4 } |
