{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import datetime\n", "import pandas.tseries.offsets as off\n", "import globeop_reports as go\n", "import pandas as pd\n", "import matplotlib.pyplot as plt" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#PNL Allocation\n", "#report_date = datetime.date(2017,10,31)\n", "report_date = datetime.date.today()\n", "report_date = report_date - off.MonthEnd(1)\n", "report_date" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pnl_alloc = go.alloc('pnl')\n", "alloc = pnl_alloc.xs(report_date)\n", "go.pnl_alloc_plot(alloc)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Capital Allocation\n", "cap_alloc = go.alloc('capital')\n", "alloc1 = cap_alloc.xs(report_date)\n", "go.cap_alloc_plot_pie(alloc1)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Average Portfolio Sales Turnover - as of last monthend from today\n", "go.avg_turnover()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Number of bond positions by strategy by month - and copy to clipboard\n", "#go.num_bond_by_strat()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Number of bond trades by direction by month - and copy to clipboard\n", "#go.num_bond_trades()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df = cap_alloc.endbooknav.groupby('periodenddate').apply(lambda x: x/x.sum())\n", "df = df.unstack().groupby(pd.Grouper(freq='M')).apply(lambda df: df.loc[df.index[-1]])\n", "df = go.shift_cash(datetime.date(2017,11,30), -2096454, df, 'Curve')\n", "temp = df.iloc[-1].sort_values(ascending=False)\n", "df = df.reindex(temp.index, axis=1)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ax = go.cap_alloc_plot_bar(df[:-1])\n", "lgd = ax.legend(loc='lower center', bbox_to_anchor=(0.5, -0.3), ncol=4)\n", "ax.figure.savefig(\"/home/serenitas/edwin/PythonGraphs/cap_alloc_1.png\", bbox_extra_artists=(lgd,), bbox_inches='tight')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "df = go.get_rmbs_pos_df()" ] }, { "cell_type": "code", "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": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.4" } }, "nbformat": 4, "nbformat_minor": 2 }