Commit 515ec9c6 authored by Dr.李's avatar Dr.李

update all the example

parent 33e49554
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -14,7 +14,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
......@@ -48,13 +48,13 @@
"\n",
" objective = cvxpy.Minimize(-w.T * er)\n",
" prob = cvxpy.Problem(objective, constraints)\n",
" prob.solve()\n",
" prob.solve(solver='ECOS')\n",
" return w, prob"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 11,
"metadata": {},
"outputs": [
{
......@@ -62,37 +62,21 @@
"output_type": "stream",
"text": [
"Scale(n) time(ms) feval min(x) max(x) sum(x) x(0) + x(1)\n",
"200 18.00 -0.82 -0.000021 0.011996 1.0000100.013991955470964355\n",
"400 21.40 -1.28 -0.000000 0.010000 1.000000 0.015\n",
"600 21.00 -1.64 -0.000435 0.009980 1.0001740.014845697577983343\n",
"800 24.01 -1.83 -0.000802 0.010028 1.0002310.01474166785085744\n",
"1000 44.88 -1.89 -0.000166 0.010000 1.0001490.014851819526468822\n",
"1200 44.02 -2.07 -0.000571 0.009999 1.0001670.014833266833006432\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"d:\\ProgramData\\Anaconda3\\lib\\site-packages\\cvxpy-1.0.8-py3.6-win-amd64.egg\\cvxpy\\problems\\problem.py:614: RuntimeWarning: overflow encountered in long_scalars\n",
" if self.max_big_small_squared < big*small**2:\n",
"d:\\ProgramData\\Anaconda3\\lib\\site-packages\\cvxpy-1.0.8-py3.6-win-amd64.egg\\cvxpy\\problems\\problem.py:615: RuntimeWarning: overflow encountered in long_scalars\n",
" self.max_big_small_squared = big*small**2\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"1400 57.00 -2.31 -0.000504 0.009997 1.0002170.014785380519459417\n",
"1600 47.02 -2.90 -0.001650 0.009905 1.0004330.014667925787486116\n",
"1800 79.06 -2.67 -0.000885 0.009999 1.0002300.014771011591262167\n",
"2000 68.01 -2.81 -0.000333 0.010001 1.0002410.014758149340884413\n",
"2200 72.02 -3.71 -0.000849 0.009969 1.0004940.014536311105299406\n",
"2400 94.19 -2.46 -0.000536 0.010001 1.0000810.014917972574632015\n",
"2600 135.07 -2.54 -0.000105 0.010001 1.0000900.01490885499964943\n",
"2800 106.02 -3.40 -0.000983 0.010000 1.0002670.014733268551116162\n",
"3000 109.02 -3.77 -0.001612 0.010001 1.0003180.014680802417975643\n"
"200 8.98 -0.82 -0.000000 0.010000 1.0000000.014999999999355636\n",
"400 10.97 -1.28 -0.000000 0.010000 1.0000000.014999999999977868\n",
"600 12.01 -1.54 -0.000000 0.010000 1.0000000.014999999999630973\n",
"800 11.93 -1.63 -0.000000 0.010000 1.0000000.014999999999937863\n",
"1000 12.00 -1.72 -0.000000 0.010000 1.0000000.014999999999985369\n",
"1200 13.97 -1.81 -0.000000 0.010000 1.0000000.014999999999661145\n",
"1400 15.92 -1.90 -0.000000 0.010000 1.0000000.014999999999617875\n",
"1600 18.97 -1.96 -0.000000 0.010000 1.0000000.01499999999998295\n",
"1800 19.99 -2.03 -0.000000 0.010000 1.0000000.014999999999785373\n",
"2000 22.93 -2.06 -0.000000 0.010000 1.0000000.014999999999994327\n",
"2200 21.92 -2.07 -0.000000 0.010000 1.0000000.014999999999979582\n",
"2400 25.90 -2.13 -0.000000 0.010000 1.0000000.014999999999836155\n",
"2600 29.93 -2.14 -0.000000 0.010000 1.0000000.01499999999985058\n",
"2800 28.87 -2.16 -0.000000 0.010000 1.0000000.014999999999853686\n",
"3000 32.96 -2.19 -0.000000 0.010000 1.0000000.014999999999981861\n"
]
}
],
......@@ -138,21 +122,21 @@
"output_type": "stream",
"text": [
"Scale(n) time(ms) feval min(x) max(x) sum(x) x(0) + x(1)\n",
"200 2.99 -0.82 0.000000 0.010000 1.0000000.015000000005429394\n",
"400 2.99 -1.28 0.000000 0.010000 1.0000000.015000000000751215\n",
"600 4.00 -1.54 0.000000 0.010000 1.0000000.01500000000851949\n",
"800 5.00 -1.63 0.000000 0.010000 1.0000000.015000000002481837\n",
"1000 7.00 -1.72 0.000000 0.010000 1.0000000.015000000001100414\n",
"1200 6.00 -1.81 0.000000 0.010000 1.0000000.01500000000548405\n",
"1400 9.01 -1.90 0.000000 0.010000 1.0000000.015000000001956426\n",
"1600 10.00 -1.96 0.000000 0.010000 1.0000000.015000000000082848\n",
"1800 10.16 -2.03 0.000000 0.010000 1.0000000.01500000000204834\n",
"2000 12.05 -2.06 0.000000 0.010000 1.0000000.0150000000008303\n",
"2200 12.99 -2.07 0.000000 0.010000 1.0000000.01500000000729576\n",
"2400 12.00 -2.13 0.000000 0.010000 1.0000000.015000000004022507\n",
"2600 23.02 -2.14 0.000000 0.010000 1.0000000.015000000001118521\n",
"2800 20.99 -2.16 0.000000 0.010000 1.0000000.01500000000064263\n",
"3000 22.00 -2.19 0.000000 0.010000 1.0000000.015000000003030482\n"
"200 2.00 -0.82 0.000000 0.010000 1.0000000.015000000005429394\n",
"400 4.00 -1.28 0.000000 0.010000 1.0000000.015000000000751215\n",
"600 4.02 -1.54 0.000000 0.010000 1.0000000.01500000000851949\n",
"800 3.99 -1.63 0.000000 0.010000 1.0000000.015000000002481837\n",
"1000 7.94 -1.72 0.000000 0.010000 1.0000000.015000000001100414\n",
"1200 5.03 -1.81 0.000000 0.010000 1.0000000.01500000000548405\n",
"1400 8.94 -1.90 0.000000 0.010000 1.0000000.015000000001956426\n",
"1600 8.02 -1.96 0.000000 0.010000 1.0000000.015000000000082848\n",
"1800 9.98 -2.03 0.000000 0.010000 1.0000000.01500000000204834\n",
"2000 9.97 -2.06 0.000000 0.010000 1.0000000.0150000000008303\n",
"2200 14.91 -2.07 0.000000 0.010000 1.0000000.01500000000729576\n",
"2400 12.97 -2.13 0.000000 0.010000 1.0000000.015000000004022507\n",
"2600 15.96 -2.14 0.000000 0.010000 1.0000000.015000000001118521\n",
"2800 19.92 -2.16 0.000000 0.010000 1.0000000.01500000000064263\n",
"3000 21.93 -2.19 0.000000 0.010000 1.0000000.015000000003030482\n"
]
}
],
......@@ -189,7 +173,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
"version": "3.6.8"
},
"varInspector": {
"cols": {
......
......@@ -25,9 +25,21 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Optimization status - optimal\n",
"Optimal expect return - -0.18504428442588658\n",
"Optimial portfolio weights - [0.05 0.05 0.3 0.3 0.3 ]\n",
"Initial portfolio weights - [0. 0.1 0.3 0.3 0.3]\n",
"Turn over amount - 0.1000000000000593\n"
]
}
],
"source": [
"import numpy as np\n",
"from alphamind.portfolio.linearbuilder import linear_builder\n",
......@@ -169,7 +181,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
......@@ -221,9 +233,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Optimal weight is [0.09999998 0.4 0.5 ]\n",
"Risk exposure of optimal potfolio is [0.99999998 0.59999998]\n"
]
}
],
"source": [
"print('Optimal weight is {0}'.format(x))\n",
"print('Risk exposure of optimal potfolio is {0}'.format(x @ risk_exposure))"
......@@ -253,7 +274,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.5"
"version": "3.6.8"
},
"varInspector": {
"cols": {
......
......@@ -87,7 +87,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Wall time: 459 ms\n"
"Wall time: 454 ms\n"
]
}
],
......@@ -346,7 +346,7 @@
"2 6 房地产\n",
"3 8 机械设备\n",
"4 9 综合\n",
"Wall time: 185 ms\n"
"Wall time: 198 ms\n"
]
}
],
......@@ -387,7 +387,7 @@
"2 6 0.00039\n",
"3 8 0.00071\n",
"4 9 0.00075\n",
"Wall time: 121 ms\n"
"Wall time: 150 ms\n"
]
}
],
......@@ -461,7 +461,7 @@
"2 6 -0.043098\n",
"3 8 -0.174035\n",
"4 9 -0.138300\n",
"Wall time: 98.7 ms\n"
"Wall time: 118 ms\n"
]
}
],
......@@ -525,7 +525,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Wall time: 6.98 ms\n"
"Wall time: 8.97 ms\n"
]
}
],
......@@ -574,7 +574,7 @@
{
"data": {
"text/plain": [
"<matplotlib.axes._subplots.AxesSubplot at 0x195c3192358>"
"<matplotlib.axes._subplots.AxesSubplot at 0x2844b3c43c8>"
]
},
"execution_count": 15,
......@@ -684,7 +684,7 @@
{
"data": {
"text/plain": [
"<matplotlib.axes._subplots.AxesSubplot at 0x195c36554a8>"
"<matplotlib.axes._subplots.AxesSubplot at 0x284521258d0>"
]
},
"execution_count": 19,
......
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