Commit 38c1a6a9 authored by Dr.李's avatar Dr.李

FEATURE: update notebooks

parent 63634fd2
......@@ -9,7 +9,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
......@@ -32,7 +32,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
......@@ -60,7 +60,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
......@@ -80,22 +80,14 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Wall time: 976 µs\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"D:\\ProgramData\\Anaconda3\\envs\\alpha-mind\\lib\\site-packages\\ipykernel\\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.\n",
" and should_run_async(code)\n"
"Wall time: 1.98 ms\n"
]
}
],
......@@ -118,7 +110,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 5,
"metadata": {},
"outputs": [
{
......@@ -142,17 +134,17 @@
" warm start: on, polish: on, time_limit: off\n",
"\n",
"iter objective pri res dua res rho time\n",
" 1 -7.8878e+03 4.61e+00 6.68e+04 1.00e-01 1.04e-03s\n",
" 125 -2.4830e+02 3.58e-07 2.76e-05 5.82e-01 3.81e-03s\n",
" 1 -7.8878e+03 4.61e+00 6.68e+04 1.00e-01 1.10e-03s\n",
" 125 -2.4830e+02 3.58e-07 2.76e-05 5.82e-01 3.80e-03s\n",
"\n",
"status: solved\n",
"solution polish: unsuccessful\n",
"number of iterations: 125\n",
"optimal objective: -248.2989\n",
"run time: 4.41e-03s\n",
"run time: 4.54e-03s\n",
"optimal rho estimate: 1.87e+00\n",
"\n",
"Wall time: 42 ms\n"
"Wall time: 48 ms\n"
]
},
{
......@@ -161,7 +153,7 @@
"-248.29894124530716"
]
},
"execution_count": 19,
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
......@@ -173,7 +165,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 6,
"metadata": {},
"outputs": [
{
......@@ -182,7 +174,7 @@
"('optimal', -248.29894124530716)"
]
},
"execution_count": 20,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
......@@ -193,7 +185,7 @@
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 7,
"metadata": {},
"outputs": [
{
......@@ -219,9 +211,9 @@
"12 -2.483e+02 -2.483e+02 +3e-07 5e-13 2e-15 1e-10 8e-10 0.9775 1e-04 1 1 1 | 0 0\n",
"\n",
"OPTIMAL (within feastol=5.3e-13, reltol=1.3e-09, abstol=3.2e-07).\n",
"Runtime: 0.008978 seconds.\n",
"Runtime: 0.013942 seconds.\n",
"\n",
"Wall time: 40 ms\n"
"Wall time: 51.3 ms\n"
]
},
{
......@@ -230,7 +222,7 @@
"-248.2989614228091"
]
},
"execution_count": 21,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
......@@ -242,7 +234,7 @@
},
{
"cell_type": "code",
"execution_count": 22,
"execution_count": 8,
"metadata": {},
"outputs": [
{
......@@ -251,7 +243,7 @@
"('optimal', -248.2989614228091)"
]
},
"execution_count": 22,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
......@@ -262,7 +254,7 @@
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 9,
"metadata": {},
"outputs": [
{
......@@ -285,7 +277,7 @@
"12: -2.4829e+02 -2.4831e+02 1e-02 2e-16 4e-16\n",
"13: -2.4830e+02 -2.4830e+02 1e-04 2e-16 1e-15\n",
"Optimal solution found.\n",
"Wall time: 62 ms\n"
"Wall time: 108 ms\n"
]
}
],
......@@ -316,14 +308,14 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Wall time: 18 ms\n"
"Wall time: 24 ms\n"
]
},
{
......@@ -332,7 +324,7 @@
"0"
]
},
"execution_count": 24,
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
......@@ -369,7 +361,7 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
......@@ -378,7 +370,7 @@
},
{
"cell_type": "code",
"execution_count": 26,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
......@@ -390,18 +382,9 @@
},
{
"cell_type": "code",
"execution_count": 36,
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"D:\\ProgramData\\Anaconda3\\envs\\alpha-mind\\lib\\site-packages\\ipykernel\\ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.\n",
" and should_run_async(code)\n"
]
}
],
"outputs": [],
"source": [
"def cvxpy(n):\n",
" w = Variable(n)\n",
......@@ -423,7 +406,7 @@
},
{
"cell_type": "code",
"execution_count": 37,
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
......@@ -455,7 +438,7 @@
},
{
"cell_type": "code",
"execution_count": 38,
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
......@@ -474,7 +457,7 @@
},
{
"cell_type": "code",
"execution_count": 39,
"execution_count": 16,
"metadata": {},
"outputs": [
{
......@@ -482,9 +465,9 @@
"output_type": "stream",
"text": [
"Scale(n) cvxpy cvxopt ipopt\n",
"100 0.0230 0.0200 0.0050\n",
"200 0.0290 0.0360 0.0110\n",
"300 0.0360 0.0500 0.0150\n"
"100 0.0527 0.0660 0.0142\n",
"200 0.0710 0.3040 0.0601\n",
"300 0.1614 0.0690 0.0155\n"
]
}
],
......
This source diff could not be displayed because it is too large. You can view the blob instead.
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": 10,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
......@@ -46,7 +46,7 @@
" np.random.seed(1)\n",
" er = np.random.randn(n)\n",
"\n",
" objective = cvxpy.Minimize(-w.T * er)\n",
" objective = cvxpy.Minimize(-w.T @ er)\n",
" prob = cvxpy.Problem(objective, constraints)\n",
" prob.solve(solver='ECOS')\n",
" return w, prob"
......@@ -54,7 +54,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 5,
"metadata": {},
"outputs": [
{
......@@ -62,21 +62,21 @@
"output_type": "stream",
"text": [
"Scale(n) time(ms) feval min(x) max(x) sum(x) x(0) + x(1)\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"
"200 23.15 -0.82 -0.000000 0.010000 1.0000000.014999999999355636\n",
"400 29.00 -1.28 -0.000000 0.010000 1.0000000.014999999999977868\n",
"600 31.04 -1.54 -0.000000 0.010000 1.0000000.014999999999630973\n",
"800 37.00 -1.63 -0.000000 0.010000 1.0000000.014999999999937863\n",
"1000 42.99 -1.72 -0.000000 0.010000 1.0000000.014999999999985369\n",
"1200 83.97 -1.81 -0.000000 0.010000 1.0000000.014999999999661145\n",
"1400 121.77 -1.90 -0.000000 0.010000 1.0000000.014999999999617875\n",
"1600 125.93 -1.96 -0.000000 0.010000 1.0000000.01499999999998295\n",
"1800 75.05 -2.03 -0.000000 0.010000 1.0000000.014999999999785373\n",
"2000 45.95 -2.06 -0.000000 0.010000 1.0000000.014999999999994327\n",
"2200 68.05 -2.07 -0.000000 0.010000 1.0000000.014999999999979582\n",
"2400 144.36 -2.13 -0.000000 0.010000 1.0000000.014999999999836155\n",
"2600 140.00 -2.14 -0.000000 0.010000 1.0000000.01499999999985058\n",
"2800 145.48 -2.16 -0.000000 0.010000 1.0000000.014999999999853686\n",
"3000 125.97 -2.19 -0.000000 0.010000 1.0000000.014999999999981861\n"
]
}
],
......@@ -91,7 +91,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
......@@ -114,7 +114,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 7,
"metadata": {},
"outputs": [
{
......@@ -122,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.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"
"200 4.00 -0.82 0.000000 0.010000 1.0000000.015000000005429394\n",
"400 5.38 -1.28 0.000000 0.010000 1.0000000.015000000000751215\n",
"600 5.02 -1.54 0.000000 0.010000 1.0000000.01500000000851949\n",
"800 7.89 -1.63 0.000000 0.010000 1.0000000.015000000002481837\n",
"1000 7.97 -1.72 0.000000 0.010000 1.0000000.015000000001100414\n",
"1200 14.04 -1.81 0.000000 0.010000 1.0000000.01500000000548405\n",
"1400 13.85 -1.90 0.000000 0.010000 1.0000000.015000000001956426\n",
"1600 20.96 -1.96 0.000000 0.010000 1.0000000.015000000000082848\n",
"1800 26.95 -2.03 0.000000 0.010000 1.0000000.01500000000204834\n",
"2000 25.59 -2.06 0.000000 0.010000 1.0000000.0150000000008303\n",
"2200 27.25 -2.07 0.000000 0.010000 1.0000000.01500000000729576\n",
"2400 13.10 -2.13 0.000000 0.010000 1.0000000.015000000004022507\n",
"2600 19.00 -2.14 0.000000 0.010000 1.0000000.015000000001118521\n",
"2800 30.60 -2.16 0.000000 0.010000 1.0000000.01500000000064263\n",
"3000 25.00 -2.19 0.000000 0.010000 1.0000000.015000000003030482\n"
]
}
],
......@@ -159,9 +159,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python [conda env:alpha-mind]",
"language": "python",
"name": "python3"
"name": "conda-env-alpha-mind-py"
},
"language_info": {
"codemirror_mode": {
......@@ -173,7 +173,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
"version": "3.7.9"
},
"varInspector": {
"cols": {
......@@ -206,5 +206,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}
......@@ -2,9 +2,7 @@
"cells": [
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"metadata": {},
"source": [
"alpha-mind的portfolio文件夹提供了构建组合的工具函数。\n",
"- 不同的构建方式实质上对应了不同的优化问题。\n",
......@@ -33,10 +31,24 @@
"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"
"Optimal expect return - 0.750529042208698\n",
"Optimial portfolio weights - [0.1 0.2 0.05 0.4 0.25]\n",
"Initial portfolio weights - [0.1 0.2 0. 0.4 0.3]\n",
"Turn over amount - 0.10000000000050759\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"D:\\ProgramData\\Anaconda3\\envs\\alpha-mind\\lib\\site-packages\\cvxpy\\expressions\\expression.py:550: UserWarning: \n",
"This use of ``*`` has resulted in matrix multiplication.\n",
"Using ``*`` for matrix multiplication has been deprecated since CVXPY 1.1.\n",
" Use ``*`` for matrix-scalar and vector-scalar multiplication.\n",
" Use ``@`` for matrix-matrix and matrix-vector multiplication.\n",
" Use ``multiply`` for elementwise multiplication.\n",
"\n",
" warnings.warn(__STAR_MATMUL_WARNING__, UserWarning)\n"
]
}
],
......@@ -183,7 +195,16 @@
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"D:\\ProgramData\\Anaconda3\\envs\\alpha-mind\\lib\\importlib\\_bootstrap.py:219: RuntimeWarning: numpy.ufunc size changed, may indicate binary incompatibility. Expected 192 from C header, got 216 from PyObject\n",
" return f(*args, **kwds)\n"
]
}
],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
......@@ -260,9 +281,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python [conda env:alpha-mind]",
"language": "python",
"name": "python3"
"name": "conda-env-alpha-mind-py"
},
"language_info": {
"codemirror_mode": {
......@@ -274,7 +295,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
"version": "3.7.9"
},
"varInspector": {
"cols": {
......@@ -307,5 +328,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 4
}
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