diff options
Diffstat (limited to 'python/notebooks')
| -rw-r--r-- | python/notebooks/Valuation Backtest.ipynb | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/python/notebooks/Valuation Backtest.ipynb b/python/notebooks/Valuation Backtest.ipynb index 92549418..dfddbf86 100644 --- a/python/notebooks/Valuation Backtest.ipynb +++ b/python/notebooks/Valuation Backtest.ipynb @@ -23,7 +23,11 @@ "metadata": {}, "outputs": [], "source": [ - "date = datetime.date.today() - pd.tseries.offsets.MonthEnd(1)" + "date = datetime.date.today() - pd.tseries.offsets.MonthEnd(1)\n", + "navs = ops.get_net_navs()\n", + "subprime = mark.get_mark_df('Subprime')\n", + "clo = mark.get_mark_df('CLO')\n", + "df = subprime.append(clo)" ] }, { @@ -86,17 +90,9 @@ "metadata": {}, "outputs": [], "source": [ - "#Now Calculate alternate valuation methodologies\n", - "df = mark.get_mark_df()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "mark.count_sources(df)" + "#source counts\n", + "g2 = df.set_index(\"source\", append=True).groupby(level=[\"date\", \"source\"])\n", + "g2[\"mark\"].count().unstack(-1).plot()" ] }, { @@ -106,8 +102,10 @@ "outputs": [], "source": [ "#difference by source\n", - "nav = ops.get_net_navs()['endbooknav']\n", - "difference = mark.diff_by_source_percentage(df)\n", + "difference = mark.diff_by_source(df)\n", + "difference = difference.join(navs['endbooknav'])\n", + "difference = difference.apply(lambda x: (x / x.endbooknav), axis=1)\n", + "del difference[\"endbooknav\"]\n", "#difference.to_clipboard()" ] }, @@ -141,7 +139,7 @@ "metadata": {}, "outputs": [], "source": [ - "results = mark.alt_navs()" + "results = mark.alt_navs(df)" ] }, { @@ -189,7 +187,10 @@ "outputs": [], "source": [ "#Annual Return using different methodology\n", - "round(mark.annual_performance(results[1])*100,2)" + "perf = results[1].groupby(pd.Grouper(freq=\"A\")).last()\n", + "perf_ann = perf / perf.shift(1) - 1\n", + "perf_ann[\"2013\"] = perf[\"2013\"] / 100 - 1\n", + "round(perf_ann*100,2)" ] }, { @@ -209,8 +210,9 @@ "outputs": [], "source": [ "#A positive impact % means the alternative methodology results in a higher NAV than the fund's valuation policy.\n", - "df = mark.alt_nav_impact()\n", - "round(pd.DataFrame(df.iloc[-1]/df.iloc[-1]['endbooknav'])*100,2)" + "alt_nav_impact = mark.calc_mark_diff(df)\n", + "alt_nav_impact = alt_nav_impact.join(navs.endbooknav)\n", + "round(pd.DataFrame(alt_nav_impact.iloc[-1]/alt_nav_impact.iloc[-1]['endbooknav'])*100,2)" ] }, { @@ -220,12 +222,11 @@ "outputs": [], "source": [ "#% impact historical: positive % means the alternative methodology results in a higher NAV\n", - "nav_impact = df.divide(df.endbooknav, axis=0)\n", + "nav_impact = alt_nav_impact.divide(alt_nav_impact.endbooknav, axis=0)\n", "to_plot = ['mark_closest_all', 'mark_filtered_mean']\n", "nav_impact = nav_impact[to_plot].rename(columns={'mark_closest_all': 'mark to closest', \n", " 'mark_filtered_mean': 'mark to mean'})\n", "ax = nav_impact.plot()\n", - "ax.figure.set_figheight(7)\n", "ax.figure.savefig(\"/home/serenitas/edwin/PythonGraphs/Valuation_3.png\", bbox_extra_artists=(lgd,), bbox_inches='tight')" ] }, @@ -298,7 +299,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.4" + "version": "3.8.1" } }, "nbformat": 4, |
