aboutsummaryrefslogtreecommitdiffstats
path: root/python/notebooks
diff options
context:
space:
mode:
Diffstat (limited to 'python/notebooks')
-rw-r--r--python/notebooks/Curve Trades.ipynb163
-rw-r--r--python/notebooks/Interest Statement.ipynb158
-rw-r--r--python/notebooks/swaption_risk.ipynb466
3 files changed, 749 insertions, 38 deletions
diff --git a/python/notebooks/Curve Trades.ipynb b/python/notebooks/Curve Trades.ipynb
index 744eaa89..d8d1b7ce 100644
--- a/python/notebooks/Curve Trades.ipynb
+++ b/python/notebooks/Curve Trades.ipynb
@@ -2,11 +2,10 @@
"cells": [
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
- "import analytics.curve_trades as ct\n",
"import matplotlib.pyplot as plt\n",
"import pandas as pd\n",
"import numpy as np\n",
@@ -15,17 +14,31 @@
"\n",
"from ipywidgets import widgets\n",
"from analytics.scenarios import run_curve_scenarios\n",
+ "from analytics.curve_trades import curve_spread_diff, spreads_diff_table, theta_matrix_by_series\n",
"from scipy.optimize import brentq\n",
- "from utils.db import dbengine\n",
- "\n",
- "%matplotlib inline"
+ "from utils.db import dbengine"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 3,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "application/vnd.jupyter.widget-view+json": {
+ "model_id": "48e324f064aa450f9ca82dd064a3082f",
+ "version_major": 2,
+ "version_minor": 0
+ },
+ "text/plain": [
+ "Dropdown(description='Index:', options=('IG', 'EU'), value='IG')"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ }
+ ],
"source": [
"w = widgets.Dropdown(\n",
" options=['IG', 'EU'],\n",
@@ -38,7 +51,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
@@ -48,23 +61,143 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 8,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "application/vnd.jupyter.widget-view+json": {
+ "model_id": "260c86a418564dbe92079d66f6da64d5",
+ "version_major": 2,
+ "version_minor": 0
+ },
+ "text/plain": [
+ "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/plain": [
+ "<matplotlib.axes._subplots.AxesSubplot at 0x7f6018e50e50>"
+ ]
+ },
+ "execution_count": 8,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"#On the run spread differences\n",
- "spreads_diff = ct.curve_spread_diff(index, 6)\n",
+ "spreads_diff = curve_spread_diff(index, 6)\n",
"spreads_diff.plot()"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 14,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "application/vnd.jupyter.widget-view+json": {
+ "model_id": "1f6848430d7c4cdca60133d2b6edf190",
+ "version_major": 2,
+ "version_minor": 0
+ },
+ "text/plain": [
+ "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …"
+ ]
+ },
+ "metadata": {},
+ "output_type": "display_data"
+ },
+ {
+ "data": {
+ "text/html": [
+ "<div>\n",
+ "<style scoped>\n",
+ " .dataframe tbody tr th:only-of-type {\n",
+ " vertical-align: middle;\n",
+ " }\n",
+ "\n",
+ " .dataframe tbody tr th {\n",
+ " vertical-align: top;\n",
+ " }\n",
+ "\n",
+ " .dataframe thead th {\n",
+ " text-align: right;\n",
+ " }\n",
+ "</style>\n",
+ "<table border=\"1\" class=\"dataframe\">\n",
+ " <thead>\n",
+ " <tr style=\"text-align: right;\">\n",
+ " <th></th>\n",
+ " <th>3-5</th>\n",
+ " <th>5-7</th>\n",
+ " <th>7-10</th>\n",
+ " <th>5-10</th>\n",
+ " </tr>\n",
+ " </thead>\n",
+ " <tbody>\n",
+ " <tr>\n",
+ " <th>min</th>\n",
+ " <td>21.219659</td>\n",
+ " <td>20.056528</td>\n",
+ " <td>16.047530</td>\n",
+ " <td>40.126583</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>max</th>\n",
+ " <td>34.068608</td>\n",
+ " <td>27.193659</td>\n",
+ " <td>24.195653</td>\n",
+ " <td>48.782836</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>mean</th>\n",
+ " <td>29.106575</td>\n",
+ " <td>24.588519</td>\n",
+ " <td>20.883679</td>\n",
+ " <td>45.472198</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>current</th>\n",
+ " <td>21.603603</td>\n",
+ " <td>21.392519</td>\n",
+ " <td>23.498862</td>\n",
+ " <td>44.891380</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>zscore</th>\n",
+ " <td>-2.698133</td>\n",
+ " <td>-2.206748</td>\n",
+ " <td>1.378322</td>\n",
+ " <td>-0.287849</td>\n",
+ " </tr>\n",
+ " </tbody>\n",
+ "</table>\n",
+ "</div>"
+ ],
+ "text/plain": [
+ " 3-5 5-7 7-10 5-10\n",
+ "min 21.219659 20.056528 16.047530 40.126583\n",
+ "max 34.068608 27.193659 24.195653 48.782836\n",
+ "mean 29.106575 24.588519 20.883679 45.472198\n",
+ "current 21.603603 21.392519 23.498862 44.891380\n",
+ "zscore -2.698133 -2.206748 1.378322 -0.287849"
+ ]
+ },
+ "execution_count": 14,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"#Table of Spread Differences, and Z-score of current spread differences\n",
- "ct.spreads_diff_table(spreads_diff)"
+ "spreads_diff_table(spreads_diff)"
]
},
{
@@ -512,7 +645,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.8.0"
+ "version": "3.8.1"
}
},
"nbformat": 4,
diff --git a/python/notebooks/Interest Statement.ipynb b/python/notebooks/Interest Statement.ipynb
index cf0c64bd..69518dff 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": 21,
"metadata": {},
"outputs": [],
"source": [
@@ -23,7 +23,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
@@ -60,9 +60,24 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 24,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "application/vnd.jupyter.widget-view+json": {
+ "model_id": "a0d5bf2d610b480f918704e73e02309a",
+ "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",
@@ -75,12 +90,12 @@
"start_date = widgets.DatePicker(\n",
" description='start:',\n",
" disabled=False,\n",
- " value=datetime.date(2019, 9, 1)\n",
+ " value=datetime.date(2019, 12, 1)\n",
")\n",
"end_date = widgets.DatePicker(\n",
" description='end:',\n",
" disabled=False,\n",
- " value=datetime.date(2019, 9, 30)\n",
+ " value=datetime.date(2019, 12, 31)\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,18 +108,139 @@
"metadata": {},
"outputs": [],
"source": [
- "df_balances[df_balances.broker=='BAML_ISDA'].loc[\"2019-06-10\"]"
+ "df_balances[df_balances.broker=='GS'].loc[\"2019-06-10\"]"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 23,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "date\n",
+ "2019-12-02 -8,800,000.00\n",
+ "2019-12-03 -8,800,000.00\n",
+ "2019-12-04 -8,800,000.00\n",
+ "2019-12-05 -8,800,000.00\n",
+ "2019-12-06 -8,800,000.00\n",
+ "2019-12-09 -8,800,000.00\n",
+ "2019-12-10 -8,800,000.00\n",
+ "2019-12-11 -9,070,000.00\n",
+ "2019-12-12 -9,070,000.00\n",
+ "2019-12-13 -9,070,000.00\n",
+ "2019-12-16 -9,070,000.00\n",
+ "2019-12-17 -9,070,000.00\n",
+ "2019-12-18 -9,070,000.00\n",
+ "2019-12-19 -9,070,000.00\n",
+ "2019-12-20 -9,070,000.00\n",
+ "2019-12-23 -9,070,000.00\n",
+ "2019-12-26 -9,070,000.00\n",
+ "2019-12-27 -9,070,000.00\n",
+ "2019-12-30 -9,070,000.00\n",
+ "2020-01-01 -9,070,000.00\n",
+ "2020-01-02 -9,070,000.00\n",
+ "2020-01-03 -9,070,000.00\n",
+ "Name: amount, dtype: float64"
+ ]
+ },
+ "execution_count": 23,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "df_gs=df_balances[df_balances.broker == \"MS\"]\n",
+ "df_gs.groupby(df_gs.index)['amount'].sum()[\"2019-12-01\":]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
- "df_baml=df_balances[df_balances.broker == \"BAML_ISDA\"]\n",
- "df_baml.groupby(df_baml.index)['amount'].sum()[\"2019-08-30\":]"
+ "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(pd.Timestamp(start_date) - BDay(), end_date)\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\n",
+ " return result"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 12,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "2019-12-01 -1,217.99\n",
+ "2019-12-02 -1,217.99\n",
+ "2019-12-03 -1,210.18\n",
+ "2019-12-04 -1,210.18\n",
+ "2019-12-05 -1,210.18\n",
+ "2019-12-06 -1,440.10\n",
+ "2019-12-07 -1,440.10\n",
+ "2019-12-08 -1,440.10\n",
+ "2019-12-09 -1,440.10\n",
+ "2019-12-10 -1,440.10\n",
+ "2019-12-11 -1,440.10\n",
+ "2019-12-12 -1,474.54\n",
+ "2019-12-13 -1,474.54\n",
+ "2019-12-14 -1,474.54\n",
+ "2019-12-15 -1,474.54\n",
+ "2019-12-16 -1,484.06\n",
+ "2019-12-17 -1,484.06\n",
+ "2019-12-18 -1,474.54\n",
+ "2019-12-19 -1,474.54\n",
+ "2019-12-20 -1,474.54\n",
+ "2019-12-21 -1,474.54\n",
+ "2019-12-22 -1,474.54\n",
+ "2019-12-23 -1,474.54\n",
+ "2019-12-24 -1,474.54\n",
+ "2019-12-25 -1,474.54\n",
+ "2019-12-26 -1,474.54\n",
+ "2019-12-27 -1,474.54\n",
+ "2019-12-28 -1,474.54\n",
+ "2019-12-29 -1,474.54\n",
+ "2019-12-30 -1,474.54\n",
+ "2019-12-31 -1,474.54\n",
+ "Freq: D, dtype: float64"
+ ]
+ },
+ "execution_count": 12,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "f(df_balances, df_rates, \"GS\", \"2019-12-01\", \"2019-12-31\").sum(axis=1)"
]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
}
],
"metadata": {
@@ -123,7 +259,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.7.4"
+ "version": "3.8.1"
}
},
"nbformat": 4,
diff --git a/python/notebooks/swaption_risk.ipynb b/python/notebooks/swaption_risk.ipynb
index 00b5db55..ce860db3 100644
--- a/python/notebooks/swaption_risk.ipynb
+++ b/python/notebooks/swaption_risk.ipynb
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
@@ -13,7 +13,7 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
@@ -21,24 +21,389 @@
"import datetime\n",
"from utils.db import dbconn\n",
"from analytics import init_ontr\n",
+ "import analytics\n",
"conn = dbconn('dawndb')\n",
"conn.autocommit = True\n",
- "init_ontr()"
+ "value_date = datetime.date.today()\n",
+ "init_ontr(value_date)"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 3,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "Portfolio 2020-01-22\n",
+ "\n",
+ "<table border=\"1\" class=\"dataframe\">\n",
+ " <thead>\n",
+ " <tr style=\"text-align: right;\">\n",
+ " <th></th>\n",
+ " <th>Product</th>\n",
+ " <th>Index</th>\n",
+ " <th>Notional</th>\n",
+ " <th>Ref</th>\n",
+ " <th>Strike</th>\n",
+ " <th>Direction</th>\n",
+ " <th>Type</th>\n",
+ " <th>Expiry</th>\n",
+ " <th>Vol</th>\n",
+ " <th>PV</th>\n",
+ " <th>Delta</th>\n",
+ " <th>Gamma</th>\n",
+ " <th>Theta</th>\n",
+ " <th>Vega</th>\n",
+ " <th>HY Equiv</th>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>ids</th>\n",
+ " <th></th>\n",
+ " <th></th>\n",
+ " <th></th>\n",
+ " <th></th>\n",
+ " <th></th>\n",
+ " <th></th>\n",
+ " <th></th>\n",
+ " <th></th>\n",
+ " <th></th>\n",
+ " <th></th>\n",
+ " <th></th>\n",
+ " <th></th>\n",
+ " <th></th>\n",
+ " <th></th>\n",
+ " <th></th>\n",
+ " </tr>\n",
+ " </thead>\n",
+ " <tbody>\n",
+ " <tr>\n",
+ " <th>SWPTN91</th>\n",
+ " <td>Swaption</td>\n",
+ " <td>IG33 5yr</td>\n",
+ " <td>200,000,000.00</td>\n",
+ " <td>45.13</td>\n",
+ " <td>45.0</td>\n",
+ " <td>Long</td>\n",
+ " <td>receiver</td>\n",
+ " <td>2020-02-19</td>\n",
+ " <td>40.74%</td>\n",
+ " <td>150,061.67</td>\n",
+ " <td>-37.06%</td>\n",
+ " <td>66.00%</td>\n",
+ " <td>-3,327.79</td>\n",
+ " <td>4,576.20</td>\n",
+ " <td>-21,825,100.50</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>SWPTN92</th>\n",
+ " <td>Swaption</td>\n",
+ " <td>IG33 5yr</td>\n",
+ " <td>200,000,000.00</td>\n",
+ " <td>45.13</td>\n",
+ " <td>65.0</td>\n",
+ " <td>Short</td>\n",
+ " <td>payer</td>\n",
+ " <td>2020-02-19</td>\n",
+ " <td>75.62%</td>\n",
+ " <td>-20,633.56</td>\n",
+ " <td>-6.40%</td>\n",
+ " <td>-13.42%</td>\n",
+ " <td>1,809.79</td>\n",
+ " <td>-1,399.72</td>\n",
+ " <td>-3,765,995.13</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>SWPTN97</th>\n",
+ " <td>Swaption</td>\n",
+ " <td>IG33 5yr</td>\n",
+ " <td>200,000,000.00</td>\n",
+ " <td>45.13</td>\n",
+ " <td>42.5</td>\n",
+ " <td>Long</td>\n",
+ " <td>receiver</td>\n",
+ " <td>2020-03-18</td>\n",
+ " <td>38.45%</td>\n",
+ " <td>96,216.26</td>\n",
+ " <td>-21.68%</td>\n",
+ " <td>43.36%</td>\n",
+ " <td>-1,761.48</td>\n",
+ " <td>5,166.44</td>\n",
+ " <td>-12,768,492.88</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>SWPTN107</th>\n",
+ " <td>Swaption</td>\n",
+ " <td>IG33 5yr</td>\n",
+ " <td>200,000,000.00</td>\n",
+ " <td>45.13</td>\n",
+ " <td>42.5</td>\n",
+ " <td>Long</td>\n",
+ " <td>receiver</td>\n",
+ " <td>2020-03-18</td>\n",
+ " <td>38.45%</td>\n",
+ " <td>96,216.26</td>\n",
+ " <td>-21.68%</td>\n",
+ " <td>43.36%</td>\n",
+ " <td>-1,761.48</td>\n",
+ " <td>5,166.44</td>\n",
+ " <td>-12,768,492.88</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>SWPTN108</th>\n",
+ " <td>Swaption</td>\n",
+ " <td>IG33 5yr</td>\n",
+ " <td>200,000,000.00</td>\n",
+ " <td>45.13</td>\n",
+ " <td>55.0</td>\n",
+ " <td>Short</td>\n",
+ " <td>payer</td>\n",
+ " <td>2020-03-18</td>\n",
+ " <td>54.75%</td>\n",
+ " <td>-123,985.48</td>\n",
+ " <td>-26.66%</td>\n",
+ " <td>-32.67%</td>\n",
+ " <td>2,590.27</td>\n",
+ " <td>-5,340.77</td>\n",
+ " <td>-15,699,000.27</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>SWPTN98</th>\n",
+ " <td>Swaption</td>\n",
+ " <td>IG33 5yr</td>\n",
+ " <td>200,000,000.00</td>\n",
+ " <td>45.13</td>\n",
+ " <td>57.5</td>\n",
+ " <td>Short</td>\n",
+ " <td>payer</td>\n",
+ " <td>2020-03-18</td>\n",
+ " <td>57.96%</td>\n",
+ " <td>-101,557.29</td>\n",
+ " <td>-21.92%</td>\n",
+ " <td>-27.94%</td>\n",
+ " <td>2,453.43</td>\n",
+ " <td>-4,793.54</td>\n",
+ " <td>-12,910,454.18</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>SWPTN93</th>\n",
+ " <td>Swaption</td>\n",
+ " <td>IG33 5yr</td>\n",
+ " <td>300,000,000.00</td>\n",
+ " <td>45.13</td>\n",
+ " <td>62.5</td>\n",
+ " <td>Short</td>\n",
+ " <td>payer</td>\n",
+ " <td>2020-03-18</td>\n",
+ " <td>63.80%</td>\n",
+ " <td>-107,301.85</td>\n",
+ " <td>-15.41%</td>\n",
+ " <td>-20.60%</td>\n",
+ " <td>3,231.38</td>\n",
+ " <td>-5,769.27</td>\n",
+ " <td>-13,613,875.38</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>SWPTN103</th>\n",
+ " <td>Swaption</td>\n",
+ " <td>IG33 5yr</td>\n",
+ " <td>200,000,000.00</td>\n",
+ " <td>45.13</td>\n",
+ " <td>42.5</td>\n",
+ " <td>Long</td>\n",
+ " <td>receiver</td>\n",
+ " <td>2020-04-15</td>\n",
+ " <td>39.95%</td>\n",
+ " <td>130,102.18</td>\n",
+ " <td>-22.89%</td>\n",
+ " <td>35.40%</td>\n",
+ " <td>-1,518.80</td>\n",
+ " <td>6,419.89</td>\n",
+ " <td>-13,477,124.52</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>SWPTN101</th>\n",
+ " <td>Swaption</td>\n",
+ " <td>IG33 5yr</td>\n",
+ " <td>100,000,000.00</td>\n",
+ " <td>45.13</td>\n",
+ " <td>42.5</td>\n",
+ " <td>Long</td>\n",
+ " <td>receiver</td>\n",
+ " <td>2020-04-15</td>\n",
+ " <td>39.95%</td>\n",
+ " <td>65,051.09</td>\n",
+ " <td>-22.89%</td>\n",
+ " <td>35.40%</td>\n",
+ " <td>-759.40</td>\n",
+ " <td>3,209.94</td>\n",
+ " <td>-6,738,562.26</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>SWPTN99</th>\n",
+ " <td>Swaption</td>\n",
+ " <td>IG33 5yr</td>\n",
+ " <td>200,000,000.00</td>\n",
+ " <td>45.12</td>\n",
+ " <td>42.5</td>\n",
+ " <td>Long</td>\n",
+ " <td>receiver</td>\n",
+ " <td>2020-04-15</td>\n",
+ " <td>39.96%</td>\n",
+ " <td>130,399.30</td>\n",
+ " <td>-22.93%</td>\n",
+ " <td>35.43%</td>\n",
+ " <td>-1,520.20</td>\n",
+ " <td>6,424.14</td>\n",
+ " <td>-13,500,437.56</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>SWPTN102</th>\n",
+ " <td>Swaption</td>\n",
+ " <td>IG33 5yr</td>\n",
+ " <td>100,000,000.00</td>\n",
+ " <td>45.12</td>\n",
+ " <td>57.5</td>\n",
+ " <td>Short</td>\n",
+ " <td>payer</td>\n",
+ " <td>2020-04-15</td>\n",
+ " <td>55.99%</td>\n",
+ " <td>-86,043.53</td>\n",
+ " <td>-28.92%</td>\n",
+ " <td>-27.46%</td>\n",
+ " <td>1,137.31</td>\n",
+ " <td>-3,432.55</td>\n",
+ " <td>-8,516,333.11</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>SWPTN104</th>\n",
+ " <td>Swaption</td>\n",
+ " <td>IG33 5yr</td>\n",
+ " <td>200,000,000.00</td>\n",
+ " <td>45.12</td>\n",
+ " <td>57.5</td>\n",
+ " <td>Short</td>\n",
+ " <td>payer</td>\n",
+ " <td>2020-04-15</td>\n",
+ " <td>55.99%</td>\n",
+ " <td>-172,087.07</td>\n",
+ " <td>-28.92%</td>\n",
+ " <td>-27.46%</td>\n",
+ " <td>2,274.63</td>\n",
+ " <td>-6,865.09</td>\n",
+ " <td>-17,032,666.22</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>SWPTN100</th>\n",
+ " <td>Swaption</td>\n",
+ " <td>IG33 5yr</td>\n",
+ " <td>200,000,000.00</td>\n",
+ " <td>45.12</td>\n",
+ " <td>60.0</td>\n",
+ " <td>Short</td>\n",
+ " <td>payer</td>\n",
+ " <td>2020-04-15</td>\n",
+ " <td>58.42%</td>\n",
+ " <td>-147,765.75</td>\n",
+ " <td>-24.99%</td>\n",
+ " <td>-24.50%</td>\n",
+ " <td>2,198.93</td>\n",
+ " <td>-6,373.46</td>\n",
+ " <td>-14,714,847.97</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>SWPTN105</th>\n",
+ " <td>Swaption</td>\n",
+ " <td>IG33 5yr</td>\n",
+ " <td>200,000,000.00</td>\n",
+ " <td>45.12</td>\n",
+ " <td>42.5</td>\n",
+ " <td>Long</td>\n",
+ " <td>receiver</td>\n",
+ " <td>2020-05-20</td>\n",
+ " <td>41.20%</td>\n",
+ " <td>161,429.07</td>\n",
+ " <td>-23.06%</td>\n",
+ " <td>29.16%</td>\n",
+ " <td>-1,309.02</td>\n",
+ " <td>7,595.96</td>\n",
+ " <td>-13,577,001.50</td>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>SWPTN106</th>\n",
+ " <td>Swaption</td>\n",
+ " <td>IG33 5yr</td>\n",
+ " <td>200,000,000.00</td>\n",
+ " <td>45.12</td>\n",
+ " <td>60.0</td>\n",
+ " <td>Short</td>\n",
+ " <td>payer</td>\n",
+ " <td>2020-05-20</td>\n",
+ " <td>56.55%</td>\n",
+ " <td>-229,470.13</td>\n",
+ " <td>-31.54%</td>\n",
+ " <td>-23.91%</td>\n",
+ " <td>2,020.49</td>\n",
+ " <td>-8,542.41</td>\n",
+ " <td>-18,570,543.35</td>\n",
+ " </tr>\n",
+ " </tbody>\n",
+ "</table>"
+ ],
+ "text/plain": [
+ "Portfolio 2020-01-22\n",
+ "\n",
+ " Product Index Notional Ref Strike Direction Type Expiry Vol \\\n",
+ "ids \n",
+ "SWPTN91 Swaption IG33 5yr 200,000,000.00 45.13 45.0 Long receiver 2020-02-19 40.74% \n",
+ "SWPTN92 Swaption IG33 5yr 200,000,000.00 45.13 65.0 Short payer 2020-02-19 75.62% \n",
+ "SWPTN97 Swaption IG33 5yr 200,000,000.00 45.13 42.5 Long receiver 2020-03-18 38.45% \n",
+ "SWPTN107 Swaption IG33 5yr 200,000,000.00 45.13 42.5 Long receiver 2020-03-18 38.45% \n",
+ "SWPTN108 Swaption IG33 5yr 200,000,000.00 45.13 55.0 Short payer 2020-03-18 54.75% \n",
+ "SWPTN98 Swaption IG33 5yr 200,000,000.00 45.13 57.5 Short payer 2020-03-18 57.96% \n",
+ "SWPTN93 Swaption IG33 5yr 300,000,000.00 45.13 62.5 Short payer 2020-03-18 63.80% \n",
+ "SWPTN103 Swaption IG33 5yr 200,000,000.00 45.13 42.5 Long receiver 2020-04-15 39.95% \n",
+ "SWPTN101 Swaption IG33 5yr 100,000,000.00 45.13 42.5 Long receiver 2020-04-15 39.95% \n",
+ "SWPTN99 Swaption IG33 5yr 200,000,000.00 45.12 42.5 Long receiver 2020-04-15 39.96% \n",
+ "SWPTN102 Swaption IG33 5yr 100,000,000.00 45.12 57.5 Short payer 2020-04-15 55.99% \n",
+ "SWPTN104 Swaption IG33 5yr 200,000,000.00 45.12 57.5 Short payer 2020-04-15 55.99% \n",
+ "SWPTN100 Swaption IG33 5yr 200,000,000.00 45.12 60.0 Short payer 2020-04-15 58.42% \n",
+ "SWPTN105 Swaption IG33 5yr 200,000,000.00 45.12 42.5 Long receiver 2020-05-20 41.20% \n",
+ "SWPTN106 Swaption IG33 5yr 200,000,000.00 45.12 60.0 Short payer 2020-05-20 56.55% \n",
+ "\n",
+ " PV Delta Gamma Theta Vega HY Equiv \n",
+ "ids \n",
+ "SWPTN91 150,061.67 -37.06% 66.00% -3,327.79 4,576.20 -21,825,100.50 \n",
+ "SWPTN92 -20,633.56 -6.40% -13.42% 1,809.79 -1,399.72 -3,765,995.13 \n",
+ "SWPTN97 96,216.26 -21.68% 43.36% -1,761.48 5,166.44 -12,768,492.88 \n",
+ "SWPTN107 96,216.26 -21.68% 43.36% -1,761.48 5,166.44 -12,768,492.88 \n",
+ "SWPTN108 -123,985.48 -26.66% -32.67% 2,590.27 -5,340.77 -15,699,000.27 \n",
+ "SWPTN98 -101,557.29 -21.92% -27.94% 2,453.43 -4,793.54 -12,910,454.18 \n",
+ "SWPTN93 -107,301.85 -15.41% -20.60% 3,231.38 -5,769.27 -13,613,875.38 \n",
+ "SWPTN103 130,102.18 -22.89% 35.40% -1,518.80 6,419.89 -13,477,124.52 \n",
+ "SWPTN101 65,051.09 -22.89% 35.40% -759.40 3,209.94 -6,738,562.26 \n",
+ "SWPTN99 130,399.30 -22.93% 35.43% -1,520.20 6,424.14 -13,500,437.56 \n",
+ "SWPTN102 -86,043.53 -28.92% -27.46% 1,137.31 -3,432.55 -8,516,333.11 \n",
+ "SWPTN104 -172,087.07 -28.92% -27.46% 2,274.63 -6,865.09 -17,032,666.22 \n",
+ "SWPTN100 -147,765.75 -24.99% -24.50% 2,198.93 -6,373.46 -14,714,847.97 \n",
+ "SWPTN105 161,429.07 -23.06% 29.16% -1,309.02 7,595.96 -13,577,001.50 \n",
+ "SWPTN106 -229,470.13 -31.54% -23.91% 2,020.49 -8,542.41 -18,570,543.35 "
+ ]
+ },
+ "execution_count": 3,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
- "portf = get_swaption_portfolio(datetime.date.today(), conn, source_list=['GS'])\n",
+ "portf = get_swaption_portfolio(value_date, conn, source_list=[\"GS\"])\n",
"portf"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
@@ -51,20 +416,77 @@
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"hedges = pd.read_sql_query(\"SELECT security_desc, notional FROM list_cds_positions_by_strat(%s) \"\n",
" \"WHERE folder in ('IGOPTDEL', 'HYOPTDEL')\",\n",
- " conn, params=(datetime.date.today(),))"
+ " conn, params=(value_date,))"
]
},
{
"cell_type": "code",
- "execution_count": null,
+ "execution_count": 6,
"metadata": {},
- "outputs": [],
+ "outputs": [
+ {
+ "data": {
+ "text/html": [
+ "<div>\n",
+ "<style scoped>\n",
+ " .dataframe tbody tr th:only-of-type {\n",
+ " vertical-align: middle;\n",
+ " }\n",
+ "\n",
+ " .dataframe tbody tr th {\n",
+ " vertical-align: top;\n",
+ " }\n",
+ "\n",
+ " .dataframe thead th {\n",
+ " text-align: right;\n",
+ " }\n",
+ "</style>\n",
+ "<table border=\"1\" class=\"dataframe\">\n",
+ " <thead>\n",
+ " <tr style=\"text-align: right;\">\n",
+ " <th></th>\n",
+ " <th>current hedge</th>\n",
+ " <th>current_delta</th>\n",
+ " <th>gamma</th>\n",
+ " <th>net_delta</th>\n",
+ " </tr>\n",
+ " <tr>\n",
+ " <th>Index</th>\n",
+ " <th></th>\n",
+ " <th></th>\n",
+ " <th></th>\n",
+ " <th></th>\n",
+ " </tr>\n",
+ " </thead>\n",
+ " <tbody>\n",
+ " <tr>\n",
+ " <th>IG33 5yr</th>\n",
+ " <td>681,400,000.00</td>\n",
+ " <td>-677,507,134.07</td>\n",
+ " <td>151,731,367.46</td>\n",
+ " <td>3,892,865.93</td>\n",
+ " </tr>\n",
+ " </tbody>\n",
+ "</table>\n",
+ "</div>"
+ ],
+ "text/plain": [
+ " current hedge current_delta gamma net_delta\n",
+ "Index \n",
+ "IG33 5yr 681,400,000.00 -677,507,134.07 151,731,367.46 3,892,865.93"
+ ]
+ },
+ "execution_count": 6,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
"source": [
"def f(s):\n",
" l = s.split(\" \")\n",
@@ -81,6 +503,26 @@
},
{
"cell_type": "code",
+ "execution_count": 7,
+ "metadata": {},
+ "outputs": [
+ {
+ "data": {
+ "text/plain": [
+ "5758.050875686662"
+ ]
+ },
+ "execution_count": 7,
+ "metadata": {},
+ "output_type": "execute_result"
+ }
+ ],
+ "source": [
+ "portf.theta"
+ ]
+ },
+ {
+ "cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
@@ -103,7 +545,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.7.3"
+ "version": "3.8.1"
}
},
"nbformat": 4,