aboutsummaryrefslogtreecommitdiffstats
path: root/python/notebooks/Curve Trades.ipynb
diff options
context:
space:
mode:
Diffstat (limited to 'python/notebooks/Curve Trades.ipynb')
-rw-r--r--python/notebooks/Curve Trades.ipynb42
1 files changed, 27 insertions, 15 deletions
diff --git a/python/notebooks/Curve Trades.ipynb b/python/notebooks/Curve Trades.ipynb
index b2cde72e..05b05f89 100644
--- a/python/notebooks/Curve Trades.ipynb
+++ b/python/notebooks/Curve Trades.ipynb
@@ -9,7 +9,6 @@
"import analytics.curve_trades as ct\n",
"import matplotlib.pyplot as plt\n",
"import pandas as pd\n",
- "import pandas as pd\n",
"import numpy as np\n",
"import graphics as g\n",
"import globeop_reports as go\n",
@@ -42,7 +41,7 @@
"outputs": [],
"source": [
"index = w.value\n",
- "report_date = (pd.datetime.today() - pd.offsets.BDay(2)).date()"
+ "report_date = (pd.datetime.today() - pd.offsets.BDay(5)).date()"
]
},
{
@@ -92,7 +91,7 @@
"metadata": {},
"outputs": [],
"source": [
- "rolling = 10\n",
+ "rolling = 20\n",
"years = 5\n",
"ret = ct.curve_returns(index, rolling, years)\n",
"if index == 'IG':\n",
@@ -187,9 +186,9 @@
"source": [
"#Theta with 3-5-10 Strategy\n",
"df = ct.ratio_within_series(param='duration')\n",
- "s = - df.theta2['3yr'] / df.duration_ratio_to_5yr['3yr'] \\\n",
- " + 2 * df.theta2['5yr'] \\\n",
- " - df.theta2['10yr'] / df.duration_ratio_to_5yr['10yr']\n",
+ "s = - df.theta['3yr'] / df.duration_ratio_to_5yr['3yr'] \\\n",
+ " + 2 * df.theta['5yr'] \\\n",
+ " - df.theta['10yr'] / df.duration_ratio_to_5yr['10yr']\n",
"s.dropna().unstack(-1).plot()"
]
},
@@ -200,7 +199,7 @@
"outputs": [],
"source": [
"#Theta with 5-10 Strategy: buy sell 5y, buy 10y\n",
- "s = df.theta2['5yr'] - df.theta2['10yr'] / df.duration_ratio_to_5yr['10yr']\n",
+ "s = df.theta['5yr'] - df.theta['10yr'] / df.duration_ratio_to_5yr['10yr']\n",
"s.dropna().unstack(-1).plot()"
]
},
@@ -211,8 +210,8 @@
"outputs": [],
"source": [
"#Relative Spread Difference\n",
- "spread_ratio = ct.ratio_within_series(param = 'closespread')\n",
- "spread_ratio.groupby(level = ['date']).last()['closespread_ratio_to_5yr'].plot()"
+ "spread_ratio = ct.ratio_within_series(param = 'close_spread')\n",
+ "spread_ratio.groupby(level = ['date']).last()['close_spread_ratio_to_5yr'].plot()"
]
},
{
@@ -263,9 +262,9 @@
"sql_string = \"SELECT closespread FROM index_quotes where index = %s and series = %s and tenor = %s and date = %s\"\n",
"spread_df = pd.read_sql_query(sql_string, dbengine('serenitasdb'),\n",
" params=[index, ct.on_the_run(index), '5yr', report_date])\n",
- "spread_range = (1+ spread_shock) * spread_df.iloc[0][0]\n",
- "#need to max it at the closest maturity date\n",
- "date_range = pd.bdate_range(report_date, report_date + 180* pd.offsets.DateOffset(), freq='5B')\n",
+ "spread_range = np.round((1+ spread_shock) * spread_df.iloc[0][0], 2)\n",
+ "closest_mat = min([t.end_date for t in portf.trades])\n",
+ "date_range = pd.bdate_range(report_date, min(closest_mat, (report_date + 180* pd.offsets.DateOffset()).date()), freq='5B')\n",
"curve_per = np.arange(.01, .99, .1)\n",
"\n",
"df = run_curve_scenarios(portf, spread_range, date_range, curve_per)"
@@ -277,8 +276,21 @@
"metadata": {},
"outputs": [],
"source": [
- "df_plot = df[df.curve_per == curve_per[5]]\n",
- "g.plot_time_color_map(df_plot, spread_range, attr='pnl')"
+ "#plot steepness scenario at current spread\n",
+ "df_plot = df.set_index(['spread', 'curve_per'], append=True)\n",
+ "df_plot = df_plot.xs(round(spread_df.iloc[0][0], 2), level = 'spread')\n",
+ "df_plot.name = 'pnl'\n",
+ "g.plot_color_map(df_plot, spread_range)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#Plot the shape of the scenario that was run above\n",
+ "ct.plot_curve_shape(report_date)"
]
},
{
@@ -371,7 +383,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.6.5"
+ "version": "3.7.1"
}
},
"nbformat": 4,