Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
A
alpha-mind
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dr.李
alpha-mind
Commits
574f2fd4
Commit
574f2fd4
authored
Feb 27, 2018
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update examples
parent
2578387a
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
1207 additions
and
516 deletions
+1207
-516
Example 1 - Factor IC analysis.ipynb
notebooks/Example 1 - Factor IC analysis.ipynb
+42
-54
Example 2 - Strategy Analysis.ipynb
notebooks/Example 2 - Strategy Analysis.ipynb
+52
-462
Example 3 - Multi Weight Gap Comparison.ipynb
notebooks/Example 3 - Multi Weight Gap Comparison.ipynb
+1113
-0
No files found.
notebooks/Example 1 - Factor IC analysis.ipynb
View file @
574f2fd4
...
...
@@ -3,9 +3,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
...
...
@@ -21,10 +19,8 @@
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"\"\"\"\n",
...
...
@@ -35,6 +31,8 @@
"end_date = '2018-02-14'\n",
"\n",
"frequency = '10b'\n",
"industry_lower = 1.0\n",
"industry_upper = 1.0\n",
"method = 'risk_neutral'\n",
"neutralize_risk = industry_styles\n",
"industry_name = 'sw_adj'\n",
...
...
@@ -43,22 +41,20 @@
"benchmark_total_upper = 1.0\n",
"horizon = map_freq(frequency)\n",
"weight_gap = 0.01\n",
"benchmark_code =
905
\n",
"benchmark_code =
300
\n",
"universe_name = ['zz800']\n",
"universe = Universe('custom', universe_name)\n",
"ref_dates = makeSchedule(start_date, end_date, frequency, 'china.sse')\n",
"\n",
"executor = NaiveExecutor()\n",
"data_source = 'postgres+psycopg2://postgres:
we083826@192.168.0.102
/alpha'\n",
"data_source = 'postgres+psycopg2://postgres:
A12345678!@10.63.6.220
/alpha'\n",
"engine = SqlEngine(data_source)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"\"\"\"\n",
...
...
@@ -78,20 +74,22 @@
" b_type.append(BoundaryType.RELATIVE)\n",
" l_val.append(benchmark_total_lower)\n",
" u_val.append(benchmark_total_upper)\n",
" el
se
:\n",
" el
if name in {'SIZE', 'SIZENL', 'BETA'}
:\n",
" b_type.append(BoundaryType.ABSOLUTE)\n",
" l_val.append(0.0)\n",
" u_val.append(0.0)\n",
" else:\n",
" b_type.append(BoundaryType.RELATIVE)\n",
" l_val.append(industry_lower)\n",
" u_val.append(industry_upper)\n",
"\n",
"bounds = create_box_bounds(total_risk_names, b_type, l_val, u_val)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": true
},
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"\"\"\"\n",
...
...
@@ -106,17 +104,13 @@
" horizon=horizon,\n",
" offset=1)\n",
"\n",
"return_groups = codes_return.groupby('trade_date')\n",
"industry_total = engine.fetch_industry_matrix_range(universe, dates=ref_dates, category=industry_name, level=industry_level)\n",
"industry_groups = industry_total.groupby('trade_date')"
"return_groups = codes_return.groupby('trade_date')"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": true
},
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"def factor_analysis(engine, factor_name, universe, benchmark_code, positive):\n",
...
...
@@ -124,6 +118,9 @@
" \"\"\"\n",
" Model phase: we need 1 constant linear model and one linear regression model\n",
" \"\"\"\n",
" industry_total = engine.fetch_industry_matrix_range(universe, dates=ref_dates, category=industry_name, level=industry_level)\n",
" industry_groups = industry_total.groupby('trade_date')\n",
" \n",
" alpha_name = [str(factor_name) + '_' + ('pos' if positive else 'neg')]\n",
" simple_expression = LAST(factor_name) if positive else -LAST(factor_name)\n",
"\n",
...
...
@@ -233,10 +230,8 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"df = engine.fetch_factor_coverage(start_date='2011-01-01',\n",
...
...
@@ -244,22 +239,28 @@
" universe=universe_name[0])\n",
"df = df[df.source != 'risk_exposure']\n",
"df = df.groupby('factor').mean()\n",
"df = df[df.coverage >= 0.9
8
]"
"df = df[df.coverage >= 0.9
5
]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Wall time: 39min 15s\n"
]
}
],
"source": [
"%%time\n",
"\n",
"from dask.distributed import Client\n",
"\n",
"client = Client('1
92.168.0.102
:8786')\n",
"client = Client('1
0.63.6.13
:8786')\n",
"\n",
"tasks = client.map(worker_func_positive, df.index.tolist(), pure=False)\n",
"res1 = client.gather(tasks)\n",
...
...
@@ -281,13 +282,11 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"writer = pd.ExcelWriter(f'{universe_name[0]}.xlsx', engine='xlsxwriter')\n",
"writer = pd.ExcelWriter(f'{universe_name[0]}
_{benchmark_code}
.xlsx', engine='xlsxwriter')\n",
"factor_df.to_excel(writer, sheet_name='returns')\n",
"ic_df.to_excel(writer, sheet_name='ics')\n",
"writer.close()"
...
...
@@ -296,18 +295,7 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": []
}
...
...
@@ -328,7 +316,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.
3
"
"version": "3.6.
4
"
}
},
"nbformat": 4,
...
...
notebooks/Example 2 - Strategy Analysis.ipynb
View file @
574f2fd4
This diff is collapsed.
Click to expand it.
notebooks/Example 3 - Multi Weight Gap Comparison.ipynb
0 → 100644
View file @
574f2fd4
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment