Commit 2e2868bd authored by Dr.李's avatar Dr.李

modified examples

parent ccf193f6
...@@ -323,6 +323,13 @@ ...@@ -323,6 +323,13 @@
" print(\"{0:<8}{1:>12.4f}{2:>12.4f}{3:>12.4f}\".format(n, cvxpy_times[i], cvxopt_times[i], ipopt_times[i]))" " 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", "cell_type": "code",
"execution_count": null, "execution_count": null,
...@@ -347,7 +354,7 @@ ...@@ -347,7 +354,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.6.6" "version": "3.6.5"
}, },
"varInspector": { "varInspector": {
"cols": { "cols": {
......
...@@ -450,7 +450,7 @@ ...@@ -450,7 +450,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.6.6" "version": "3.6.5"
}, },
"varInspector": { "varInspector": {
"cols": { "cols": {
......
...@@ -155,7 +155,7 @@ ...@@ -155,7 +155,7 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"\n", "\n",
"kernal_feature = 'roe_q'\n", "kernal_feature = 'ROE'\n",
"regress_features = {kernal_feature: LAST(kernal_feature),\n", "regress_features = {kernal_feature: LAST(kernal_feature),\n",
" kernal_feature + '_l1': SHIFT(kernal_feature, 1),\n", " kernal_feature + '_l1': SHIFT(kernal_feature, 1),\n",
" kernal_feature + '_l2': SHIFT(kernal_feature, 2),\n", " kernal_feature + '_l2': SHIFT(kernal_feature, 2),\n",
...@@ -395,7 +395,7 @@ ...@@ -395,7 +395,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.6.6" "version": "3.6.5"
}, },
"varInspector": { "varInspector": {
"cols": { "cols": {
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -81,7 +81,7 @@ ...@@ -81,7 +81,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -102,19 +102,9 @@ ...@@ -102,19 +102,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"total weight is 1.0000\n",
"portfolio activate weight forecasting vol is 0.0250\n",
"portfolio er: 2.2232 comparing with benchmark er: 1.2359\n"
]
}
],
"source": [ "source": [
"# check the result\n", "# check the result\n",
"print(f\"total weight is {p_weight.sum(): .4f}\")\n", "print(f\"total weight is {p_weight.sum(): .4f}\")\n",
...@@ -132,7 +122,7 @@ ...@@ -132,7 +122,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -159,7 +149,7 @@ ...@@ -159,7 +149,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -184,7 +174,7 @@ ...@@ -184,7 +174,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -219,7 +209,7 @@ ...@@ -219,7 +209,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 1,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -54,9 +54,48 @@ ...@@ -54,9 +54,48 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 3,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"name": "stdout",
"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"
]
}
],
"source": [ "source": [
"print(\"{0:<8}{1:>12}{2:>12}{3:>12}{4:>12}{5:>12}{6:>15}\".format('Scale(n)', 'time(ms)', 'feval', 'min(x)', 'max(x)', 'sum(x)', 'x(0) + x(1)'))\n", "print(\"{0:<8}{1:>12}{2:>12}{3:>12}{4:>12}{5:>12}{6:>15}\".format('Scale(n)', 'time(ms)', 'feval', 'min(x)', 'max(x)', 'sum(x)', 'x(0) + x(1)'))\n",
"\n", "\n",
...@@ -68,7 +107,7 @@ ...@@ -68,7 +107,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 4,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -91,9 +130,32 @@ ...@@ -91,9 +130,32 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 5,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
{
"name": "stdout",
"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"
]
}
],
"source": [ "source": [
"print(\"{0:<8}{1:>12}{2:>12}{3:>12}{4:>12}{5:>12}{6:>15}\".format('Scale(n)', 'time(ms)', 'feval', 'min(x)', 'max(x)', 'sum(x)', 'x(0) + x(1)'))\n", "print(\"{0:<8}{1:>12}{2:>12}{3:>12}{4:>12}{5:>12}{6:>15}\".format('Scale(n)', 'time(ms)', 'feval', 'min(x)', 'max(x)', 'sum(x)', 'x(0) + x(1)'))\n",
"\n", "\n",
...@@ -127,7 +189,7 @@ ...@@ -127,7 +189,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.6.6" "version": "3.6.5"
}, },
"varInspector": { "varInspector": {
"cols": { "cols": {
......
...@@ -267,7 +267,7 @@ ...@@ -267,7 +267,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.6.6" "version": "3.6.5"
} }
}, },
"nbformat": 4, "nbformat": 4,
......
...@@ -71,7 +71,7 @@ ...@@ -71,7 +71,7 @@
"from alphamind.data.quantile import quantile\n", "from alphamind.data.quantile import quantile\n",
"\n", "\n",
"factors['quantile'] = quantile(factors['factor_1'].values, n_bins=5)\n", "factors['quantile'] = quantile(factors['factor_1'].values, n_bins=5)\n",
"factors\n" "factors"
] ]
}, },
{ {
...@@ -98,7 +98,7 @@ ...@@ -98,7 +98,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.6.6" "version": "3.6.5"
} }
}, },
"nbformat": 4, "nbformat": 4,
......
...@@ -25,22 +25,9 @@ ...@@ -25,22 +25,9 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"Optimization status - optimal\n",
"Optimal expect return - -0.3075339260279713\n",
"Optimial portfolio weights - [3.33333333e-01 3.13308565e-13 2.16666667e-01 3.33333333e-01\n",
" 1.16666667e-01]\n",
"Initial portfolio weights - [0.33333333 0. 0.16666667 0.33333333 0.16666667]\n",
"Turn over amount - 0.10000000000113718\n"
]
}
],
"source": [ "source": [
"import numpy as np\n", "import numpy as np\n",
"from alphamind.portfolio.linearbuilder import linear_builder\n", "from alphamind.portfolio.linearbuilder import linear_builder\n",
...@@ -182,7 +169,7 @@ ...@@ -182,7 +169,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": null,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -234,22 +221,20 @@ ...@@ -234,22 +221,20 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": null,
"metadata": {}, "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": [ "source": [
"print('Optimal weight is {0}'.format(x))\n", "print('Optimal weight is {0}'.format(x))\n",
"print('Risk exposure of optimal potfolio is {0}'.format(x @ risk_exposure))" "print('Risk exposure of optimal potfolio is {0}'.format(x @ risk_exposure))"
] ]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
} }
], ],
"metadata": { "metadata": {
...@@ -269,6 +254,35 @@ ...@@ -269,6 +254,35 @@
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.6.5" "version": "3.6.5"
},
"varInspector": {
"cols": {
"lenName": 16,
"lenType": 16,
"lenVar": 40
},
"kernels_config": {
"python": {
"delete_cmd_postfix": "",
"delete_cmd_prefix": "del ",
"library": "var_list.py",
"varRefreshCmd": "print(var_dic_list())"
},
"r": {
"delete_cmd_postfix": ") ",
"delete_cmd_prefix": "rm(",
"library": "var_list.r",
"varRefreshCmd": "cat(var_dic_list()) "
}
},
"types_to_exclude": [
"module",
"function",
"builtin_function_or_method",
"instance",
"_Feature"
],
"window_display": false
} }
}, },
"nbformat": 4, "nbformat": 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