aboutsummaryrefslogtreecommitdiffstats
path: root/python/notebooks/Valuation Backtest.ipynb
blob: 88211db362e09db5e23ad25d59b7c68fbd8dfb8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
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
}