Commit 01c9058f authored by Dr.李's avatar Dr.李

update notebook

parent 2f997476
...@@ -41,7 +41,7 @@ ...@@ -41,7 +41,7 @@
"factor = 'ROEAfterNonRecurring' # 'DROEAfterNonRecurring'\n", "factor = 'ROEAfterNonRecurring' # 'DROEAfterNonRecurring'\n",
"\n", "\n",
"conn = sqlalchemy.create_engine('mysql+mysqldb://root:we083826@localhost:3306/multifactor?charset=utf8')\n", "conn = sqlalchemy.create_engine('mysql+mysqldb://root:we083826@localhost:3306/multifactor?charset=utf8')\n",
"df = pd.read_sql('select factor_data.{0}, trade_data.Return as dailyReturn, {1}.* '\n", "df = pd.read_sql('select factor_data.{0}, trade_data.Return as dailyReturn, {1}.*, 1 as Market '\n",
" 'from factor_data, trade_data, {1} '\n", " 'from factor_data, trade_data, {1} '\n",
" 'where factor_data.Date = {1}.Date and factor_data.Code = {1}.Code '\n", " 'where factor_data.Date = {1}.Date and factor_data.Code = {1}.Code '\n",
" 'and factor_data.Date = trade_data.Date and factor_data.Code = trade_data.Code;'.format(factor, \n", " 'and factor_data.Date = trade_data.Date and factor_data.Code = trade_data.Code;'.format(factor, \n",
...@@ -137,7 +137,9 @@ ...@@ -137,7 +137,9 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {
"collapsed": true
},
"outputs": [], "outputs": [],
"source": [ "source": [
"total_data = df.copy()" "total_data = df.copy()"
...@@ -424,7 +426,7 @@ ...@@ -424,7 +426,7 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"top_sources = aggregated_bars.sum().abs().sort_values(ascending=False).index[:10]\n", "top_sources = aggregated_bars.sum().abs().sort_values(ascending=False).index[:10]\n",
"aggregated_bars.sum().abs().sort_values(ascending=False).plot(kind='bar', figsize=(16, 8))" "aggregated_bars.sum().sort_values(ascending=False).plot(kind='bar', figsize=(16, 8))"
] ]
}, },
{ {
...@@ -455,7 +457,7 @@ ...@@ -455,7 +457,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"exposure_table[top_sources[1:]].plot(figsize=(14,7))\n", "exposure_table[top_sources.difference(['idiosyncratic'])].plot(figsize=(14,7))\n",
"plt.legend(loc='upper center', ncol=len(top_sources[1:]) // 3)" "plt.legend(loc='upper center', ncol=len(top_sources[1:]) // 3)"
] ]
}, },
...@@ -479,62 +481,14 @@ ...@@ -479,62 +481,14 @@
"del total_data" "del total_data"
] ]
}, },
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"total_factors = [factor] + risk_facto_cols.tolist()"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"total_factors" "import gc\n",
] "gc.collect()"
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"aggregated_bars.sum().abs().sort_values(ascending=False)[:10].plot?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"aggregated_bars.sum().abs().sort_values(ascending=False)[:10].plot"
] ]
}, },
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment