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

update examples

parent 35c6aae3
......@@ -89,12 +89,12 @@
"lbound = 0.\n",
"ubound = 1. / n * 20\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",
"risk = sum_squares(multiply(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",
" w <= ubound,\n",
" sum_entries(w) == 1,]\n",
" sum(w) == 1,]\n",
"\n",
"prob = Problem(objective, constraints)"
]
......@@ -125,7 +125,7 @@
"outputs": [],
"source": [
"%%time\n",
"prob.solve(verbose=True, solver='CVXOPT')"
"prob.solve(verbose=True, solver='ECOS')"
]
},
{
......@@ -235,15 +235,15 @@
" lbound = 0.\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",
" risk = sum_squares(multiply(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",
" w <= ubound,\n",
" sum_entries(w) == 1,]\n",
" sum(w) == 1,]\n",
"\n",
" prob = Problem(objective, constraints)\n",
" prob.solve(verbose=False)\n",
" prob.solve(verbose=False, solver='ECOS')\n",
" return prob.value"
]
},
......@@ -347,7 +347,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
"version": "3.6.6"
},
"varInspector": {
"cols": {
......
......@@ -407,7 +407,6 @@
" result2 = pd.merge(target_pos2, dx_returns, on=['code'])\n",
" ret2 = result2.weight.values @ (np.exp(result2.dx.values) - 1.)\n",
" rets2.append(np.log(1. + ret2))\n",
" ## perfect forcast\n",
" \n",
" alpha_logger.info('{0} is finished'.format(ref_date))"
]
......@@ -451,7 +450,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
"version": "3.6.6"
},
"varInspector": {
"cols": {
......
......@@ -9,19 +9,9 @@
"import datetime as dt\n",
"import numpy as np\n",
"import cvxpy\n",
"from cvxopt import solvers\n",
"from alphamind.portfolio.linearbuilder import linear_builder"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"solvers.options['glpk'] = {'msg_lev': 'GLP_MSG_OFF'}"
]
},
{
"cell_type": "code",
"execution_count": null,
......@@ -137,7 +127,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
"version": "3.6.6"
},
"varInspector": {
"cols": {
......
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