Commit 40967ae5 authored by Dr.李's avatar Dr.李

update example

parent 165e81c0
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
"industry_lower = 1.0\n", "industry_lower = 1.0\n",
"industry_upper = 1.0\n", "industry_upper = 1.0\n",
"method = 'risk_neutral'\n", "method = 'risk_neutral'\n",
"neutralize_risk = ['SIZE'] + industry_styles\n", "neutralize_risk = industry_styles\n",
"industry_name = 'sw_adj'\n", "industry_name = 'sw_adj'\n",
"industry_level = 1\n", "industry_level = 1\n",
"benchmark_total_lower = 0.8\n", "benchmark_total_lower = 0.8\n",
...@@ -62,7 +62,7 @@ ...@@ -62,7 +62,7 @@
"\"\"\"\n", "\"\"\"\n",
"\n", "\n",
"industry_names = industry_list(industry_name, industry_level)\n", "industry_names = industry_list(industry_name, industry_level)\n",
"constraint_risk = ['SIZE', 'SIZENL', 'BETA']\n", "constraint_risk = ['SIZE', 'SIZENL', 'BETA'] + industry_names\n",
"total_risk_names = constraint_risk + ['benchmark', 'total']\n", "total_risk_names = constraint_risk + ['benchmark', 'total']\n",
"\n", "\n",
"b_type = []\n", "b_type = []\n",
...@@ -160,7 +160,7 @@ ...@@ -160,7 +160,7 @@
" factor_values = factor_processing(total_data[alpha_name].values,\n", " factor_values = factor_processing(total_data[alpha_name].values,\n",
" pre_process=[winsorize_normal, standardize],\n", " pre_process=[winsorize_normal, standardize],\n",
" risk_factors=risk_exp,\n", " risk_factors=risk_exp,\n",
" post_process=[winsorize_normal, standardize, rank])\n", " post_process=[winsorize_normal, standardize])\n",
"\n", "\n",
" # const linear model\n", " # const linear model\n",
" er = const_model.predict(pd.DataFrame(data={alpha_name[0]: factor_values.flatten()}))\n", " er = const_model.predict(pd.DataFrame(data={alpha_name[0]: factor_values.flatten()}))\n",
...@@ -224,8 +224,18 @@ ...@@ -224,8 +224,18 @@
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 5,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Wall time: 8.86 s\n"
]
}
],
"source": [ "source": [
"%%time\n",
"\n",
"df = engine.fetch_factor_coverage(start_date='2011-01-01',\n", "df = engine.fetch_factor_coverage(start_date='2011-01-01',\n",
" end_date='2018-02-12',\n", " end_date='2018-02-12',\n",
" universe=universe_name[0])\n", " universe=universe_name[0])\n",
...@@ -236,17 +246,9 @@ ...@@ -236,17 +246,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"Wall time: 1h 25min 5s\n"
]
}
],
"source": [ "source": [
"%%time\n", "%%time\n",
"\n", "\n",
...@@ -274,7 +276,7 @@ ...@@ -274,7 +276,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -287,26 +289,33 @@ ...@@ -287,26 +289,33 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"with pd.ExcelWriter(f'{universe_name[0]}_{benchmark_code}.xlsx', engine='xlsxwriter') as writer:\n", "with pd.ExcelWriter(f'{universe_name[0]}_{benchmark_code}.xlsx', engine='xlsxwriter') as writer:\n",
" factor_df.to_excel(writer, sheet_name='ret')\n", " factor_df.to_excel(writer, sheet_name='ret')\n",
" factor_res.to_excel(writer, sheet_name='ic')\n", " ic_df.to_excel(writer, sheet_name='ic')\n",
" factor_df.to_excel(writer, sheet_name='ret_stat')\n", " factor_res.to_excel(writer, sheet_name='ret_stat')\n",
" ic_res.to_excel(writer, sheet_name='ic_stat')" " ic_res.to_excel(writer, sheet_name='ic_stat')"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"client.close()" "client.close()"
] ]
}, },
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
......
This source diff could not be displayed because it is too large. You can view the blob instead.
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