Commit d8390b86 authored by Dr.李's avatar Dr.李

update examples

parent 65c347f3
...@@ -50,8 +50,8 @@ ...@@ -50,8 +50,8 @@
"horizon = map_freq(frequency)\n", "horizon = map_freq(frequency)\n",
"weight_gap = 0.01\n", "weight_gap = 0.01\n",
"benchmark_code = 905\n", "benchmark_code = 905\n",
"universe_name = ['zz800']\n", "universe_name = 'zz800'\n",
"universe = Universe('custom', universe_name)\n", "universe = Universe(universe_name)\n",
"ref_dates = makeSchedule(start_date, end_date, frequency, 'china.sse')\n", "ref_dates = makeSchedule(start_date, end_date, frequency, 'china.sse')\n",
"\n", "\n",
"executor = NaiveExecutor()\n", "executor = NaiveExecutor()\n",
...@@ -279,13 +279,20 @@ ...@@ -279,13 +279,20 @@
"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}_{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",
" ic_df.to_excel(writer, sheet_name='ic')\n", " ic_df.to_excel(writer, sheet_name='ic')\n",
" factor_res.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",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
...@@ -310,7 +317,7 @@ ...@@ -310,7 +317,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.6.3" "version": "3.6.5"
}, },
"varInspector": { "varInspector": {
"cols": { "cols": {
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
"batch = 1\n", "batch = 1\n",
"horizon = map_freq(freq)\n", "horizon = map_freq(freq)\n",
"weights_bandwidth = 0.01\n", "weights_bandwidth = 0.01\n",
"universe = Universe(\"custom\", ['zz800'])\n", "universe = Universe('zz800')\n",
"data_source = os.environ['DB_URI']\n", "data_source = os.environ['DB_URI']\n",
"benchmark_code = 905\n", "benchmark_code = 905\n",
"method = 'risk_neutral'" "method = 'risk_neutral'"
...@@ -83,7 +83,7 @@ ...@@ -83,7 +83,7 @@
"# Constraintes settings\n", "# Constraintes settings\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'] + industry_names\n", "constraint_risk = ['SIZE', 'SIZENL', 'BETA']\n",
"total_risk_names = constraint_risk + ['benchmark', 'total']\n", "total_risk_names = constraint_risk + ['benchmark', 'total']\n",
"all_styles = risk_styles + industry_styles + macro_styles\n", "all_styles = risk_styles + industry_styles + macro_styles\n",
"\n", "\n",
...@@ -171,7 +171,7 @@ ...@@ -171,7 +171,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.6.3" "version": "3.6.5"
}, },
"varInspector": { "varInspector": {
"cols": { "cols": {
......
...@@ -40,10 +40,10 @@ ...@@ -40,10 +40,10 @@
"\"\"\"\n", "\"\"\"\n",
"\n", "\n",
"benchmark_code = 905\n", "benchmark_code = 905\n",
"universe = Universe(\"zz800_cyb\", ['zz800', 'cyb'])\n", "universe = Universe('zz800') + Universe('cyb')\n",
"\n", "\n",
"def create_scenario(weights_bandwidth=0.02, target_vol=0.01, method='risk_neutral'):\n", "def create_scenario(weights_bandwidth=0.02, target_vol=0.01, method='risk_neutral'):\n",
" start_date = '2010-01-01'\n", " start_date = '2017-01-01'\n",
" end_date = '2018-04-27'\n", " end_date = '2018-04-27'\n",
" freq = '10b'\n", " freq = '10b'\n",
" neutralized_risk = None\n", " neutralized_risk = None\n",
...@@ -69,7 +69,7 @@ ...@@ -69,7 +69,7 @@
" data_source=os.environ['DB_URI'])\n", " data_source=os.environ['DB_URI'])\n",
"\n", "\n",
" industry_names = industry_list('sw', 1)\n", " industry_names = industry_list('sw', 1)\n",
" constraint_risk = ['SIZE', 'SIZENL', 'BETA'] + industry_names\n", " constraint_risk = ['SIZE', 'SIZENL', 'BETA']\n",
" total_risk_names = constraint_risk + ['benchmark', 'total']\n", " total_risk_names = constraint_risk + ['benchmark', 'total']\n",
" all_styles = risk_styles + industry_styles + macro_styles\n", " all_styles = risk_styles + industry_styles + macro_styles\n",
"\n", "\n",
...@@ -152,7 +152,7 @@ ...@@ -152,7 +152,7 @@
"source": [ "source": [
"weight_gaps = [0.005, 0.010, 0.015, 0.020]\n", "weight_gaps = [0.005, 0.010, 0.015, 0.020]\n",
"\n", "\n",
"with pd.ExcelWriter(f'{universe.name}_{benchmark_code}_gap.xlsx', engine='xlsxwriter') as writer:\n", "with pd.ExcelWriter(f'zz800_cyb_{benchmark_code}_gap.xlsx', engine='xlsxwriter') as writer:\n",
" for i, weight_gap in enumerate(weight_gaps):\n", " for i, weight_gap in enumerate(weight_gaps):\n",
" ret_df = create_scenario(weight_gap, target_vol=0.01, method='risk_neutral')\n", " ret_df = create_scenario(weight_gap, target_vol=0.01, method='risk_neutral')\n",
" res_df = create_report(ret_df, 25)\n", " res_df = create_report(ret_df, 25)\n",
...@@ -168,7 +168,7 @@ ...@@ -168,7 +168,7 @@
"source": [ "source": [
"target_vols = [0.015, 0.030, 0.045, 0.060]\n", "target_vols = [0.015, 0.030, 0.045, 0.060]\n",
"\n", "\n",
"with pd.ExcelWriter(f'{universe.name}_{benchmark_code}_tv.xlsx', engine='xlsxwriter') as writer:\n", "with pd.ExcelWriter(f'zz800_cyb_{benchmark_code}_tv.xlsx', engine='xlsxwriter') as writer:\n",
" for i, target_vol in enumerate(target_vols):\n", " for i, target_vol in enumerate(target_vols):\n",
" ret_df = create_scenario(0.01, target_vol=target_vol, method='tv')\n", " ret_df = create_scenario(0.01, target_vol=target_vol, method='tv')\n",
" res_df = create_report(ret_df, 25)\n", " res_df = create_report(ret_df, 25)\n",
......
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
"benchmark_total_upper = 1.0\n", "benchmark_total_upper = 1.0\n",
"batch = 1\n", "batch = 1\n",
"horizon = map_freq(freq)\n", "horizon = map_freq(freq)\n",
"universe = Universe(\"custom\", ['zz800'])\n", "universe = Universe('zz800')\n",
"data_source = os.environ['DB_URI']\n", "data_source = os.environ['DB_URI']\n",
"benchmark_code = 905\n", "benchmark_code = 905\n",
"weight_gap = 0.01\n", "weight_gap = 0.01\n",
...@@ -113,8 +113,7 @@ ...@@ -113,8 +113,7 @@
"Shared Data\n", "Shared Data\n",
"\"\"\"\n", "\"\"\"\n",
"\n", "\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",
...@@ -262,7 +261,7 @@ ...@@ -262,7 +261,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.6.3" "version": "3.6.5"
}, },
"varInspector": { "varInspector": {
"cols": { "cols": {
......
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
"category = 'sw'\n", "category = 'sw'\n",
"level = 1\n", "level = 1\n",
"freq = '20b'\n", "freq = '20b'\n",
"universe = Universe('custom', ['ashare_ex'])\n", "universe = Universe('ashare_ex')\n",
"\n", "\n",
"horizon = map_freq(freq)\n", "horizon = map_freq(freq)\n",
"ref_dates = makeSchedule(start_date, end_date, freq, 'china.sse')" "ref_dates = makeSchedule(start_date, end_date, freq, 'china.sse')"
...@@ -118,6 +118,13 @@ ...@@ -118,6 +118,13 @@
"df[['factor', 'abs t.']].groupby('factor').mean().sort_values('abs t.', ascending=False).head()" "df[['factor', 'abs t.']].groupby('factor').mean().sort_values('abs t.', ascending=False).head()"
] ]
}, },
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
...@@ -142,7 +149,7 @@ ...@@ -142,7 +149,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.6.3" "version": "3.6.5"
}, },
"varInspector": { "varInspector": {
"cols": { "cols": {
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
"source": [ "source": [
"ref_date = '2018-01-08'\n", "ref_date = '2018-01-08'\n",
"engine = SqlEngine(os.environ['DB_URI'])\n", "engine = SqlEngine(os.environ['DB_URI'])\n",
"universe = Universe('custom', ['zz800'])" "universe = Universe('zz800')"
] ]
}, },
{ {
...@@ -148,7 +148,7 @@ ...@@ -148,7 +148,7 @@
"risk_model = 'short'\n", "risk_model = 'short'\n",
"batch = 0\n", "batch = 0\n",
"horizon = map_freq(freq)\n", "horizon = map_freq(freq)\n",
"universe = Universe(\"custom\", ['zz800'])\n", "universe = Universe('zz800')\n",
"data_source = os.environ['DB_URI']\n", "data_source = os.environ['DB_URI']\n",
"benchmark_code = 906\n", "benchmark_code = 906\n",
"target_vol = 0.05\n", "target_vol = 0.05\n",
...@@ -190,7 +190,7 @@ ...@@ -190,7 +190,7 @@
"Constraintes settings\n", "Constraintes settings\n",
"\"\"\"\n", "\"\"\"\n",
"\n", "\n",
"constraint_risk = ['SIZE', 'SIZENL', 'BETA'] + industry_names\n", "constraint_risk = ['SIZE', 'SIZENL', 'BETA']\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",
...@@ -284,7 +284,7 @@ ...@@ -284,7 +284,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.6.3" "version": "3.6.5"
}, },
"varInspector": { "varInspector": {
"cols": { "cols": {
......
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