diff options
Diffstat (limited to 'python/notebooks/Curve Trades.ipynb')
| -rw-r--r-- | python/notebooks/Curve Trades.ipynb | 79 |
1 files changed, 77 insertions, 2 deletions
diff --git a/python/notebooks/Curve Trades.ipynb b/python/notebooks/Curve Trades.ipynb index a6ae0b7e..b2cde72e 100644 --- a/python/notebooks/Curve Trades.ipynb +++ b/python/notebooks/Curve Trades.ipynb @@ -16,6 +16,7 @@ "\n", "from ipywidgets import widgets\n", "from analytics.scenarios import run_curve_scenarios\n", + "from scipy.optimize import brentq\n", "from db import dbengine" ] }, @@ -41,7 +42,7 @@ "outputs": [], "source": [ "index = w.value\n", - "report_date = (pd.datetime.today() - pd.offsets.BDay(2)).normalize()" + "report_date = (pd.datetime.today() - pd.offsets.BDay(2)).date()" ] }, { @@ -91,8 +92,82 @@ "metadata": {}, "outputs": [], "source": [ + "rolling = 10\n", + "years = 5\n", + "ret = ct.curve_returns(index, rolling, years)\n", + "if index == 'IG':\n", + " ret1 = ct.curve_returns('HY', rolling, years)\n", + " suf = ' HY'\n", + "else:\n", + " ret1 = ct.curve_returns('IG', rolling, years)\n", + " suf = ' IG'\n", + "ret = ret.join(ret1['5yr long'], rsuffix=suf)\n", + "col_name = '5yr long' + suf" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#Strategy Cumulative Return\n", + "#Margin Requirement: 3% for IG Long only (33.3x), 25bps for curve (400x)\n", + "#Assume Margin Requirement of 10% for IG Long only (10x) and size the curve trade margin to\n", + "lev = 10\n", + "#1) have the same return volatility or \n", + "#curve_lev = ret['5yr long'].std()/ret['3-5-10'].std()\n", + "#2) have the same cumulative return\n", + "ret['5yr long lev'] = lev * ret['5yr long']\n", + "def aux(x, ret, col_a, col_b):\n", + " ret[col_b + ' lev'] = x * ret[col_b]\n", + " cum_ret = (ret+1).cumprod()\n", + " return cum_ret[col_a][-1] - cum_ret[col_b + ' lev'][-1]\n", + "\n", + "curve_lev = brentq(aux, 0.01, 3 * lev, args=(ret, '5yr long lev', '3-5-10'))\n", + "other_lev = brentq(aux, 0.01, 3 * lev, args=(ret, '5yr long lev', col_name))\n", + "\n", + "ret['3-5-10 lev'] = curve_lev * ret['3-5-10']\n", + "ret[col_name + ' lev'] = other_lev * ret[col_name]\n", + "cum_ret = (ret+1).cumprod()\n", + "cum_ret_ax = cum_ret[['5yr long lev', '3-5-10 lev', col_name + ' lev']].plot()\n", + "cum_ret_ax.figure.savefig(\"/home/serenitas/edwin/PythonGraphs/curve_trades_cum_return.png\", bbox_inches='tight')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "curve_lev, other_lev" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ "#Curve Trade returns\n", - "ct.curve_returns()" + "ct.curve_returns_stats(ret)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#2016 scenario: max drawdown from the 2015 peak to 2016 trough\n", + "peak = cum_ret['2015'].max()\n", + "trough = cum_ret['2016'].min()\n", + "scenario_2016 = pd.DataFrame({'peak': peak,\n", + " 'trough': trough,\n", + " 'max_drawdown': (peak - trough)/peak,\n", + " 'peak_dates': cum_ret['2015'].idxmax(),\n", + " 'trough_dates': cum_ret['2016'].idxmin()})\n", + "scenario_2016" ] }, { |
