aboutsummaryrefslogtreecommitdiffstats
path: root/python/notebooks/Valuation Backtest.ipynb
diff options
context:
space:
mode:
Diffstat (limited to 'python/notebooks/Valuation Backtest.ipynb')
-rw-r--r--python/notebooks/Valuation Backtest.ipynb198
1 files changed, 198 insertions, 0 deletions
diff --git a/python/notebooks/Valuation Backtest.ipynb b/python/notebooks/Valuation Backtest.ipynb
new file mode 100644
index 00000000..88211db3
--- /dev/null
+++ b/python/notebooks/Valuation Backtest.ipynb
@@ -0,0 +1,198 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import matplotlib.pyplot as plt\n",
+ "from matplotlib.ticker import FuncFormatter \n",
+ "from datetime import datetime\n",
+ "import pandas as pd\n",
+ "\n",
+ "import mark_backtest_underpar as mark\n",
+ "import globeop_reports as ops"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#exclude sell price that are over 200\n",
+ "df_long = mark.back_test('2013-01-01', '2018-01-01', sell_price_threshold = 200)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#%matplotlib nbagg\n",
+ "%matplotlib inline\n",
+ "mark.pretty_plot(df_long)\n",
+ "#file saved in serenitas shared drive/edwin/"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#exclude trades that are over 5x mark for purpose of regression\n",
+ "diff_threshold = 5\n",
+ "results = mark.stats(df_long, diff_threshold)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#Regression Intercept\n",
+ "results[0]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#Sale Difference\n",
+ "results[1]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#Now Calculate alternate valuation methodologies\n",
+ "df = mark.get_mark_df()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "%matplotlib inline\n",
+ "mark.count_sources(df)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#difference by source\n",
+ "nav = ops.get_net_navs()['endbooknav']\n",
+ "difference = mark.diff_by_source_percentage(df)\n",
+ "#difference.to_clipboard()\n",
+ "\n",
+ "#plot\n",
+ "ax = difference.plot(kind = 'bar', legend = True)\n",
+ "\n",
+ "visible = ax.xaxis.get_ticklabels()[::6]\n",
+ "for label in ax.xaxis.get_ticklabels():\n",
+ " if label not in visible:\n",
+ " label.set_visible(False)\n",
+ " \n",
+ "ax.xaxis.set_major_formatter(plt.FixedFormatter(difference.index.to_series().dt.strftime(\"%b %Y\")))\n",
+ "ax.set_ylabel('NAV Impact vs. Fund Policy (%)')\n",
+ "vals = ax.get_yticks()\n",
+ "ax.set_yticklabels(['{:3.0f}%'.format(x*100) for x in vals])"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "results = mark.alt_navs()"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#%matplotlib nbagg\n",
+ "to_plot = ['mark_closest_all', 'mark_mean_all']\n",
+ "to_plot1 = ['mark_manager']\n",
+ "plot_df0 = results[1][to_plot]\n",
+ "plot_df1 = results[1][to_plot1]\n",
+ "\n",
+ "plot_df0 = plot_df0.rename(columns = {'mark_closest_all': 'Third-pary mark closest to LMCG valuation', \\\n",
+ " 'mark_mean_all': 'Average of all third-party marks'})\n",
+ "plot_df1 = plot_df1.rename(columns = {'mark_manager': 'Marks per fund valuation policy'})\n",
+ "\n",
+ "ax = plot_df0.plot(figsize = [10, 3.5])\n",
+ "ax = plot_df1.plot(marker = 'o', ax = ax)\n",
+ "plt.rcParams[\"font.family\"] = \"sans-serif\"\n",
+ "ax.set_xlabel('')\n",
+ "ax.set_ylabel('NAV', weight = 'bold')\n",
+ "ax.set_title('Fund Return Using Different Valuation Methods', weight = 'bold')\n",
+ "lgd = ax.legend(loc='upper center', bbox_to_anchor=(0.5, -.1), shadow=True, ncol=3)\n",
+ "ax.figure.savefig(\"/home/serenitas/edwin/PythonGraphs/Valuation_1.png\", bbox_extra_artists=(lgd,), bbox_inches='tight')"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "mark.annual_performance(results[1])"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "pd.DataFrame(mark.alt_nav_impact())"
+ ]
+ },
+ {
+ "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.1"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}