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
657d8d97
Commit
657d8d97
authored
May 30, 2018
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update examples
parent
f24bdfd1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
58 deletions
+44
-58
Example 10 - Quadratic Optimizer Comparison with CVXOPT.ipynb
...ple 10 - Quadratic Optimizer Comparison with CVXOPT.ipynb
+22
-5
Example 7 - Portfolio Optimizer Performance.ipynb
notebooks/Example 7 - Portfolio Optimizer Performance.ipynb
+22
-46
Example 9 - Linear Optimizer Comparison with CVXOPT.ipynb
...Example 9 - Linear Optimizer Comparison with CVXOPT.ipynb
+0
-7
No files found.
notebooks/Example 10 - Quadratic Optimizer Comparison with CVXOPT.ipynb
View file @
657d8d97
...
@@ -89,7 +89,9 @@
...
@@ -89,7 +89,9 @@
"lbound = 0.\n",
"lbound = 0.\n",
"ubound = 1. / n * 20\n",
"ubound = 1. / n * 20\n",
"\n",
"\n",
"objective = Minimize(risk_penlty * quad_form(w, sec_cov_values) - signal * w)\n",
"risk = sum_squares(mul_elemwise(special_risk_values[:n] / 100., w)) + quad_form((w.T * risk_exposure_values[:n]).T, risk_cov_values[:n, :n] / 10000.)\n",
"\n",
"objective = Minimize(risk_penlty * risk - signal * w)\n",
"constraints = [w >= lbound,\n",
"constraints = [w >= lbound,\n",
" w <= ubound,\n",
" w <= ubound,\n",
" sum_entries(w) == 1,]\n",
" sum_entries(w) == 1,]\n",
...
@@ -177,7 +179,17 @@
...
@@ -177,7 +179,17 @@
"cons_matrix = np.ones((1, n))\n",
"cons_matrix = np.ones((1, n))\n",
"clb = np.ones(1)\n",
"clb = np.ones(1)\n",
"cub = np.ones(1)\n",
"cub = np.ones(1)\n",
"qpopt = QPOptimizer(signal, sec_cov_values, lbound, ubound, cons_matrix, clb, cub, 1.)\n",
"qpopt = QPOptimizer(signal,\n",
" None,\n",
" lbound,\n",
" ubound,\n",
" cons_matrix,\n",
" clb,\n",
" cub,\n",
" 1.,\n",
" risk_cov_values[:n, :n] / 10000.,\n",
" risk_exposure_values[:n],\n",
" special_risk_values[:n] * special_risk_values[:n] / 10000.)\n",
"qpopt.feval()\n",
"qpopt.feval()\n",
"qpopt.status()"
"qpopt.status()"
]
]
...
@@ -222,14 +234,16 @@
...
@@ -222,14 +234,16 @@
"\n",
"\n",
" lbound = 0.\n",
" lbound = 0.\n",
" ubound = 0.01\n",
" ubound = 0.01\n",
" \n",
" risk = sum_squares(mul_elemwise(special_risk_values[:n] / 100., w)) + quad_form((w.T * risk_exposure_values[:n]).T, risk_cov_values[:n, :n] / 10000.)\n",
"\n",
"\n",
" objective = Minimize(risk_penlty *
quad_form(w, sec_cov_values)
- signal * w)\n",
" objective = Minimize(risk_penlty *
risk
- signal * w)\n",
" constraints = [w >= lbound,\n",
" constraints = [w >= lbound,\n",
" w <= ubound,\n",
" w <= ubound,\n",
" sum_entries(w) == 1,]\n",
" sum_entries(w) == 1,]\n",
"\n",
"\n",
" prob = Problem(objective, constraints)\n",
" prob = Problem(objective, constraints)\n",
" prob.solve(verbose=False
, solver='CVXOPT', display=False
)\n",
" prob.solve(verbose=False)\n",
" return prob.value"
" return prob.value"
]
]
},
},
...
@@ -277,7 +291,10 @@
...
@@ -277,7 +291,10 @@
" cons_matrix = np.ones((1, n))\n",
" cons_matrix = np.ones((1, n))\n",
" clb = np.ones(1)\n",
" clb = np.ones(1)\n",
" cub = np.ones(1)\n",
" cub = np.ones(1)\n",
" qpopt = QPOptimizer(signal, sec_cov_values, lbound, ubound, cons_matrix, clb, cub, 1.)\n",
" qpopt = QPOptimizer(signal, None, lbound, ubound, cons_matrix, clb, cub, 1.,\n",
" risk_cov_values[:n, :n] / 10000.,\n",
" risk_exposure_values[:n],\n",
" special_risk_values[:n] * special_risk_values[:n] / 10000.)\n",
" return qpopt.feval()"
" return qpopt.feval()"
]
]
},
},
...
...
notebooks/Example 7 - Portfolio Optimizer Performance.ipynb
View file @
657d8d97
...
@@ -261,29 +261,24 @@
...
@@ -261,29 +261,24 @@
" bm = np.zeros(n)\n",
" bm = np.zeros(n)\n",
" lbound = -np.ones(n) * np.inf\n",
" lbound = -np.ones(n) * np.inf\n",
" ubound = np.ones(n) * np.inf\n",
" ubound = np.ones(n) * np.inf\n",
" risk_model = dict(cov=None, factor_cov=risk_cov/10000., factor_loading=risk_exposure, idsync=(special_risk**2)/10000.)\n",
"\n",
"\n",
" status, y, x1 = mean_variance_builder(er,\n",
" status, y, x1 = mean_variance_builder(er,\n",
"
None
,\n",
"
risk_model
,\n",
" bm,\n",
" bm,\n",
" lbound,\n",
" lbound,\n",
" ubound,\n",
" ubound,\n",
" None,\n",
" None,\n",
" None,\n",
" None,\n",
" lam=1,\n",
" lam=1)\n",
" factor_cov=risk_cov / 10000.,\n",
" factor_loading=risk_exposure,\n",
" idsync=(special_risk ** 2.) / 10000)\n",
" elasped_time1 = timeit.timeit(\"\"\"mean_variance_builder(er,\n",
" elasped_time1 = timeit.timeit(\"\"\"mean_variance_builder(er,\n",
"
None
,\n",
"
risk_model
,\n",
" bm,\n",
" bm,\n",
" lbound,\n",
" lbound,\n",
" ubound,\n",
" ubound,\n",
" None,\n",
" None,\n",
" None,\n",
" None,\n",
" lam=1,\n",
" lam=1)\"\"\",\n",
" factor_cov=risk_cov / 10000.,\n",
" factor_loading=risk_exposure,\n",
" idsync=(special_risk ** 2.) / 10000)\"\"\",\n",
" number=number, globals=globals()) / number * 1000\n",
" number=number, globals=globals()) / number * 1000\n",
" \n",
" \n",
" w = cvxpy.Variable(n)\n",
" w = cvxpy.Variable(n)\n",
...
@@ -344,29 +339,23 @@
...
@@ -344,29 +339,23 @@
" bm = np.zeros(n)\n",
" bm = np.zeros(n)\n",
" lbound = np.zeros(n)\n",
" lbound = np.zeros(n)\n",
" ubound = np.ones(n) * 0.1\n",
" ubound = np.ones(n) * 0.1\n",
" \n",
" risk_model = dict(cov=None, factor_cov=risk_cov/10000., factor_loading=risk_exposure, idsync=(special_risk**2)/10000.)\n",
"\n",
"\n",
" status, y, x1 = mean_variance_builder(er,\n",
" status, y, x1 = mean_variance_builder(er,\n",
"
None
,\n",
"
risk_model
,\n",
" bm,\n",
" bm,\n",
" lbound,\n",
" lbound,\n",
" ubound,\n",
" ubound,\n",
" None,\n",
" None,\n",
" None,\n",
" None)\n",
" lam=1,\n",
" factor_cov=risk_cov / 10000.,\n",
" factor_loading=risk_exposure,\n",
" idsync=(special_risk ** 2.) / 10000)\n",
" elasped_time1 = timeit.timeit(\"\"\"mean_variance_builder(er,\n",
" elasped_time1 = timeit.timeit(\"\"\"mean_variance_builder(er,\n",
"
None
,\n",
"
risk_model
,\n",
" bm,\n",
" bm,\n",
" lbound,\n",
" lbound,\n",
" ubound,\n",
" ubound,\n",
" None,\n",
" None,\n",
" None,\n",
" None)\"\"\",\n",
" lam=1,\n",
" factor_cov=risk_cov / 10000.,\n",
" factor_loading=risk_exposure,\n",
" idsync=(special_risk ** 2.) / 10000)\"\"\",\n",
" number=number, globals=globals()) / number * 1000\n",
" number=number, globals=globals()) / number * 1000\n",
" \n",
" \n",
" w = cvxpy.Variable(n)\n",
" w = cvxpy.Variable(n)\n",
...
@@ -432,29 +421,23 @@
...
@@ -432,29 +421,23 @@
" \n",
" \n",
" risk_constraints = np.ones((len(er), 1))\n",
" risk_constraints = np.ones((len(er), 1))\n",
" risk_target = (np.array([1.]), np.array([1.]))\n",
" risk_target = (np.array([1.]), np.array([1.]))\n",
" \n",
" risk_model = dict(cov=None, factor_cov=risk_cov/10000., factor_loading=risk_exposure, idsync=(special_risk**2)/10000.)\n",
"\n",
"\n",
" status, y, x1 = mean_variance_builder(er,\n",
" status, y, x1 = mean_variance_builder(er,\n",
"
None
,\n",
"
risk_model
,\n",
" bm,\n",
" bm,\n",
" lbound,\n",
" lbound,\n",
" ubound,\n",
" ubound,\n",
" risk_constraints,\n",
" risk_constraints,\n",
" risk_target,\n",
" risk_target)\n",
" lam=1,\n",
" factor_cov=risk_cov / 10000.,\n",
" factor_loading=risk_exposure,\n",
" idsync=(special_risk ** 2.) / 10000)\n",
" elasped_time1 = timeit.timeit(\"\"\"mean_variance_builder(er,\n",
" elasped_time1 = timeit.timeit(\"\"\"mean_variance_builder(er,\n",
"
None
,\n",
"
risk_model
,\n",
" bm,\n",
" bm,\n",
" lbound,\n",
" lbound,\n",
" ubound,\n",
" ubound,\n",
" risk_constraints,\n",
" risk_constraints,\n",
" risk_target,\n",
" risk_target)\"\"\",\n",
" lam=1,\n",
" factor_cov=risk_cov / 10000.,\n",
" factor_loading=risk_exposure,\n",
" idsync=(special_risk ** 2.) / 10000)\"\"\",\n",
" number=number, globals=globals()) / number * 1000\n",
" number=number, globals=globals()) / number * 1000\n",
" \n",
" \n",
" w = cvxpy.Variable(n)\n",
" w = cvxpy.Variable(n)\n",
...
@@ -527,31 +510,24 @@
...
@@ -527,31 +510,24 @@
" \n",
" \n",
" risk_constraints = np.ones((n, 1))\n",
" risk_constraints = np.ones((n, 1))\n",
" risk_target = (np.array([bm.sum()]), np.array([bm.sum()]))\n",
" risk_target = (np.array([bm.sum()]), np.array([bm.sum()]))\n",
" risk_model = dict(cov=None, factor_cov=risk_cov/10000., factor_loading=risk_exposure, idsync=(special_risk**2)/10000.)\n",
"\n",
"\n",
" status, y, x1 = target_vol_builder(er,\n",
" status, y, x1 = target_vol_builder(er,\n",
"
None
,\n",
"
risk_model
,\n",
" bm,\n",
" bm,\n",
" lbound,\n",
" lbound,\n",
" ubound,\n",
" ubound,\n",
" risk_constraints,\n",
" risk_constraints,\n",
" risk_target,\n",
" risk_target,\n",
" vol_low=0,\n",
" vol_target=target_vol)\n",
" vol_high=target_vol,\n",
" factor_cov=risk_cov / 10000.,\n",
" factor_loading=risk_exposure,\n",
" idsync=(special_risk ** 2.) / 10000)\n",
" elasped_time1 = timeit.timeit(\"\"\"target_vol_builder(er,\n",
" elasped_time1 = timeit.timeit(\"\"\"target_vol_builder(er,\n",
"
None
,\n",
"
risk_model
,\n",
" bm,\n",
" bm,\n",
" lbound,\n",
" lbound,\n",
" ubound,\n",
" ubound,\n",
" risk_constraints,\n",
" risk_constraints,\n",
" risk_target,\n",
" risk_target,\n",
" vol_low=0,\n",
" vol_target=target_vol)\"\"\",\n",
" vol_high=target_vol,\n",
" factor_cov=risk_cov / 10000.,\n",
" factor_loading=risk_exposure,\n",
" idsync=(special_risk ** 2.) / 10000)\"\"\",\n",
" number=number, globals=globals()) / number * 1000\n",
" number=number, globals=globals()) / number * 1000\n",
" \n",
" \n",
" w = cvxpy.Variable(n)\n",
" w = cvxpy.Variable(n)\n",
...
...
notebooks/Example 9 - Linear Optimizer Comparison with CVXOPT.ipynb
View file @
657d8d97
...
@@ -113,13 +113,6 @@
...
@@ -113,13 +113,6 @@
" print(\"{0:<8}{1:>12.2f}{2:>12.2f}{3:>12f}{4:>12f}{5:>12f}{6:>15}\".format(n, elapsed*1000, result[1], s.min(), s.max(), s.sum(), s[0] + s[1]))"
" print(\"{0:<8}{1:>12.2f}{2:>12.2f}{3:>12f}{4:>12f}{5:>12f}{6:>15}\".format(n, elapsed*1000, result[1], s.min(), s.max(), s.sum(), s[0] + s[1]))"
]
]
},
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null,
"execution_count": null,
...
...
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