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
651c34cb
Commit
651c34cb
authored
May 06, 2018
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update example
parent
61bfd381
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
46 deletions
+44
-46
Example 10 - Quadratic Optimizer Comparison with CVXOPT.ipynb
...ple 10 - Quadratic Optimizer Comparison with CVXOPT.ipynb
+15
-24
Example 7 - Portfolio Optimizer Performance.ipynb
notebooks/Example 7 - Portfolio Optimizer Performance.ipynb
+19
-19
Example 8 - Neutralize Algorithm Comparison.ipynb
notebooks/Example 8 - Neutralize Algorithm Comparison.ipynb
+1
-1
Example 9 - Linear Optimizer Comparison with CVXOPT.ipynb
...Example 9 - Linear Optimizer Comparison with CVXOPT.ipynb
+9
-2
No files found.
notebooks/Example 10 - Quadratic Optimizer Comparison with CVXOPT.ipynb
View file @
651c34cb
...
...
@@ -207,8 +207,8 @@
"source": [
"def time_function(py_callable, n):\n",
" start = dt.datetime.now()\n",
" py_callable(n)\n",
" return (dt.datetime.now() - start).total_seconds()"
"
val =
py_callable(n)\n",
" return (dt.datetime.now() - start).total_seconds()
, val
"
]
},
{
...
...
@@ -229,7 +229,8 @@
" sum_entries(w) == 1,]\n",
"\n",
" prob = Problem(objective, constraints)\n",
" prob.solve(verbose=False, solver='CVXOPT', display=False)"
" prob.solve(verbose=False, solver='CVXOPT', display=False)\n",
" return prob.value"
]
},
{
...
...
@@ -260,7 +261,8 @@
" b = matrix(b)\n",
" \n",
" solvers.options['show_progress'] = False\n",
" sol = solvers.qp(P, q, G, h, A, b)"
" sol = solvers.qp(P, q, G, h, A, b)\n",
" return sol['primal objective']"
]
},
{
...
...
@@ -276,7 +278,7 @@
" clb = np.ones(1)\n",
" cub = np.ones(1)\n",
" qpopt = QPOptimizer(signal, sec_cov_values, lbound, ubound, cons_matrix, clb, cub, 1.)\n",
" qpopt.feval()"
"
return
qpopt.feval()"
]
},
{
...
...
@@ -294,27 +296,16 @@
"for i, n in enumerate(n_steps):\n",
" sec_cov_values = sec_cov_values_full[:n, :n]\n",
" signal = signal_full[:n]\n",
" cvxpy_times[i]
= time_function(cvxpy, n) * 1000
\n",
" cvxopt_times[i]
= time_function(cvxopt, n) * 1000
\n",
" ipopt_times[i]
= time_function(ipopt, n) * 1000
\n",
" cvxpy_times[i]
, val1 = time_function(cvxpy, n)
\n",
" cvxopt_times[i]
, val2 = time_function(cvxopt, n)
\n",
" ipopt_times[i]
, val3 = time_function(ipopt, n)
\n",
" \n",
" print(\"{0:<8}{1:>12.2f}{2:>12.2f}{3:>12.2f}\".format(n, cvxpy_times[i], cvxopt_times[i], ipopt_times[i]))"
" np.testing.assert_almost_equal(val1, val2, 4)\n",
" np.testing.assert_almost_equal(val2, val3, 4)\n",
" \n",
" print(\"{0:<8}{1:>12.4f}{2:>12.4f}{3:>12.4f}\".format(n, cvxpy_times[i], cvxopt_times[i], ipopt_times[i]))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
...
...
@@ -339,7 +330,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.
3
"
"version": "3.6.
5
"
},
"varInspector": {
"cols": {
...
...
notebooks/Example 7 - Portfolio Optimizer Performance.ipynb
View file @
651c34cb
...
...
@@ -113,8 +113,8 @@
" objective = cvxpy.Minimize(-w.T * er)\n",
" prob = cvxpy.Problem(objective, constraints)\n",
" \n",
" prob.solve(
solver='GLPK'
)\n",
" elasped_time2 = timeit.timeit(\"prob.solve(
solver='GLPK'
)\",\n",
" prob.solve()\n",
" elasped_time2 = timeit.timeit(\"prob.solve()\",\n",
" number=number, globals=globals()) / number * 1000\n",
"\n",
" np.testing.assert_almost_equal(x1 @ er, np.array(w.value).flatten() @ er, 4)\n",
...
...
@@ -177,13 +177,13 @@
" current_position=current_position,\n",
" method='interior')\n",
" elasped_time1 = timeit.timeit(\"\"\"linear_builder(er,\n",
"
lbound,\n",
"
ubound,\n",
"
risk_constraints,\n",
"
risk_target,\n",
"
turn_over_target=turn_over_target,\n",
"
current_position=current_position,\n",
"
method='interior')\"\"\", number=number, globals=globals()) / number * 1000\n",
" lbound,\n",
" ubound,\n",
" risk_constraints,\n",
" risk_target,\n",
" turn_over_target=turn_over_target,\n",
" current_position=current_position,\n",
" method='interior')\"\"\", number=number, globals=globals()) / number * 1000\n",
" \n",
" w = cvxpy.Variable(n)\n",
" curr_risk_exposure = risk_constraints.T @ w\n",
...
...
@@ -196,18 +196,18 @@
" objective = cvxpy.Minimize(-w.T * er)\n",
" prob = cvxpy.Problem(objective, constraints)\n",
" \n",
" prob.solve(
solver='GLPK'
)\n",
" elasped_time2 = timeit.timeit(\"prob.solve(
solver='GLPK'
)\",\n",
" prob.solve()\n",
" elasped_time2 = timeit.timeit(\"prob.solve()\",\n",
" number=number, globals=globals()) / number * 1000\n",
" \n",
" elasped_time3 = timeit.timeit(\"\"\"linear_builder(er,\n",
"
lbound,\n",
"
ubound,\n",
"
risk_constraints,\n",
"
risk_target,\n",
"
turn_over_target=turn_over_target,\n",
"
current_position=current_position,\n",
"
method='simplex')\"\"\", number=number, globals=globals()) / number * 1000\n",
" lbound,\n",
" ubound,\n",
" risk_constraints,\n",
" risk_target,\n",
" turn_over_target=turn_over_target,\n",
" current_position=current_position,\n",
" method='simplex')\"\"\", number=number, globals=globals()) / number * 1000\n",
" \n",
" \n",
" np.testing.assert_almost_equal(x1 @ er, np.array(w.value).flatten() @ er, 4)\n",
...
...
@@ -529,7 +529,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.
3
"
"version": "3.6.
5
"
},
"varInspector": {
"cols": {
...
...
notebooks/Example 8 - Neutralize Algorithm Comparison.ipynb
View file @
651c34cb
...
...
@@ -355,7 +355,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.
3
"
"version": "3.6.
5
"
},
"varInspector": {
"cols": {
...
...
notebooks/Example 9 - Linear Optimizer Comparison with CVXOPT.ipynb
View file @
651c34cb
...
...
@@ -58,7 +58,7 @@
"\n",
" objective = cvxpy.Minimize(-w.T * er)\n",
" prob = cvxpy.Problem(objective, constraints)\n",
" prob.solve(
solver='GLPK'
)\n",
" prob.solve()\n",
" return w, prob"
]
},
...
...
@@ -113,6 +113,13 @@
" 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",
"execution_count": null,
...
...
@@ -137,7 +144,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.
4
"
"version": "3.6.
5
"
},
"varInspector": {
"cols": {
...
...
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