diff options
Diffstat (limited to 'python/notebooks/Allocation Reports.ipynb')
| -rw-r--r-- | python/notebooks/Allocation Reports.ipynb | 71 |
1 files changed, 67 insertions, 4 deletions
diff --git a/python/notebooks/Allocation Reports.ipynb b/python/notebooks/Allocation Reports.ipynb index 00ad7972..2b35e2bb 100644 --- a/python/notebooks/Allocation Reports.ipynb +++ b/python/notebooks/Allocation Reports.ipynb @@ -9,7 +9,8 @@ "import datetime\n", "import pandas.tseries.offsets as off\n", "import globeop_reports as go\n", - "import pandas as pd" + "import pandas as pd\n", + "import matplotlib.pyplot as plt" ] }, { @@ -65,7 +66,7 @@ "outputs": [], "source": [ "#Number of bond positions by strategy by month - and copy to clipboard\n", - "go.num_bond_by_strat()" + "#go.num_bond_by_strat()" ] }, { @@ -75,7 +76,7 @@ "outputs": [], "source": [ "#Number of bond trades by direction by month - and copy to clipboard\n", - "go.num_bond_trades()" + "#go.num_bond_trades()" ] }, { @@ -108,7 +109,7 @@ "metadata": {}, "outputs": [], "source": [ - "df" + "df = go.get_rmbs_pos_df()" ] }, { @@ -116,6 +117,68 @@ "execution_count": null, "metadata": {}, "outputs": [], + "source": [ + "bond_dur, bond_yield = {}, {}\n", + "for d, g in df.groupby(pd.Grouper(freq='M')):\n", + " bond_dur[d] = sum(g.curr_ntl * g[('moddur', 3)])/sum(g.curr_ntl)\n", + " bond_yield[d] = sum(g.endlocalmv * g[('moddur', 3)] * g.b_yield) /sum(g.endlocalmv * g[('moddur', 3)])\n", + "a = pd.Series(bond_dur)\n", + "b = pd.Series(bond_yield)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "fig = plt.figure()\n", + "ax0 = fig.add_subplot(111)\n", + "\n", + "a.name = 'Yield-to-maturity'\n", + "ax1.set_xlabel('date')\n", + "a.plot(kind='line', color = 'r', ax=ax0, label = a.name)\n", + "ax0.set_ylabel('Duration')\n", + "ax0.legend(loc=0)\n", + "\n", + "ax1 = ax0.twinx()\n", + "b.name = 'Duration'\n", + "b.plot(kind='line', secondary_y=True, ax=ax1, label = b.name)\n", + "ax1.set_xlim([a.index.min(), a.index.max()])\n", + "ax1.set_ylabel('Yield-to-Maturity')\n", + "ax1.legend(loc=2)\n", + "#plt.legend(bbox_to_anchor=(0, -.1), loc=0, borderaxespad=0.)\n", + "fig.tight_layout()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#filter out First-Pay bonds. \n", + "df_1 = c[c.strat != 'MTG_FP']\n", + "bond_dur, bond_yield = {}, {}\n", + "for d, g in df_1.groupby(pd.Grouper(freq='M')):\n", + " bond_dur[d] = sum(g.curr_ntl * g[('moddur', 3)])/sum(g.curr_ntl)\n", + " bond_yield[d] = sum(g.endlocalmv * g[('moddur', 3)] * g.b_yield) /sum(g.endlocalmv * g[('moddur', 3)])\n", + "a_1 = pd.Series(bond_dur)\n", + "b_1 = pd.Series(bond_yield)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], "source": [] } ], |
