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
55b727e7
Commit
55b727e7
authored
Jul 09, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more specific naming
parent
03ea0ad0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
400 additions
and
54 deletions
+400
-54
factoranalysis.py
alphamind/analysis/factoranalysis.py
+1
-1
optimizer check.ipynb
notebooks/optimizer check.ipynb
+399
-53
No files found.
alphamind/analysis/factoranalysis.py
View file @
55b727e7
...
@@ -197,7 +197,7 @@ def factor_analysis(factors: pd.DataFrame,
...
@@ -197,7 +197,7 @@ def factor_analysis(factors: pd.DataFrame,
risk_target
=
(
risk_lbound
,
risk_ubound
),
risk_target
=
(
risk_lbound
,
risk_ubound
),
**
kwargs
)
**
kwargs
)
el
se
:
el
if
method
==
'rank'
:
# using rank builder
# using rank builder
weights
=
build_portfolio
(
er
,
weights
=
build_portfolio
(
er
,
builder
=
'rank'
,
builder
=
'rank'
,
...
...
notebooks/optimizer check.ipynb
View file @
55b727e7
...
@@ -2,15 +2,13 @@
...
@@ -2,15 +2,13 @@
"cells": [
"cells": [
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {
"metadata": {},
"collapsed": true
},
"outputs": [],
"outputs": [],
"source": [
"source": [
"import numpy as np\n",
"import numpy as np\n",
"import pandas as pd\n",
"import pandas as pd\n",
"import sqlalchemy as sa
http://localhost:8888/notebooks/optimizer%20check.ipynb#
\n",
"import sqlalchemy as sa\n",
"from cvxpy import *\n",
"from cvxpy import *\n",
"from cvxopt import *\n",
"from cvxopt import *\n",
"from alphamind.data.neutralize import neutralize\n",
"from alphamind.data.neutralize import neutralize\n",
...
@@ -22,7 +20,7 @@
...
@@ -22,7 +20,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
null
,
"execution_count":
3
,
"metadata": {
"metadata": {
"collapsed": true
"collapsed": true
},
},
...
@@ -45,7 +43,7 @@
...
@@ -45,7 +43,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
null
,
"execution_count":
4
,
"metadata": {
"metadata": {
"collapsed": true
"collapsed": true
},
},
...
@@ -57,9 +55,18 @@
...
@@ -57,9 +55,18 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
null
,
"execution_count":
5
,
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 248 ms, sys: 40 ms, total: 288 ms\n",
"Wall time: 4.32 s\n"
]
}
],
"source": [
"source": [
"%%time\n",
"%%time\n",
"\n",
"\n",
...
@@ -81,7 +88,7 @@
...
@@ -81,7 +88,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
null
,
"execution_count":
6
,
"metadata": {
"metadata": {
"collapsed": true
"collapsed": true
},
},
...
@@ -92,9 +99,18 @@
...
@@ -92,9 +99,18 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
null
,
"execution_count":
7
,
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 4 ms, sys: 0 ns, total: 4 ms\n",
"Wall time: 3.08 ms\n"
]
}
],
"source": [
"source": [
"%%time\n",
"%%time\n",
"factor_values = factor_data[factor_list].values\n",
"factor_values = factor_data[factor_list].values\n",
...
@@ -104,9 +120,18 @@
...
@@ -104,9 +120,18 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
null
,
"execution_count":
8
,
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 2.29 s, sys: 16 ms, total: 2.3 s\n",
"Wall time: 1.73 s\n"
]
}
],
"source": [
"source": [
"%%time\n",
"%%time\n",
"ne_factor_values = neutralize(risk_exposure_values, standardize(winsorize_normal(factor_values)))\n",
"ne_factor_values = neutralize(risk_exposure_values, standardize(winsorize_normal(factor_values)))\n",
...
@@ -115,18 +140,38 @@
...
@@ -115,18 +140,38 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
null
,
"execution_count":
9
,
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"(3236, 38)"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"source": [
"risk_exposure_values.shape"
"risk_exposure_values.shape"
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
null
,
"execution_count":
10
,
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 192 ms, sys: 28 ms, total: 220 ms\n",
"Wall time: 56.2 ms\n"
]
}
],
"source": [
"source": [
"%%time\n",
"%%time\n",
"risk_cov_values = risk_cov_data.loc[risk_factor_columns, risk_factor_columns].astype(float) \n",
"risk_cov_values = risk_cov_data.loc[risk_factor_columns, risk_factor_columns].astype(float) \n",
...
@@ -135,7 +180,7 @@
...
@@ -135,7 +180,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
null
,
"execution_count":
11
,
"metadata": {
"metadata": {
"collapsed": true
"collapsed": true
},
},
...
@@ -157,9 +202,18 @@
...
@@ -157,9 +202,18 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
null
,
"execution_count":
12
,
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 44 ms, sys: 0 ns, total: 44 ms\n",
"Wall time: 17.5 ms\n"
]
}
],
"source": [
"source": [
"%%time\n",
"%%time\n",
"w = Variable(n)\n",
"w = Variable(n)\n",
...
@@ -177,9 +231,52 @@
...
@@ -177,9 +231,52 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
null
,
"execution_count":
13
,
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"ECOS 2.0.4 - (C) embotech GmbH, Zurich Switzerland, 2012-15. Web: www.embotech.com/ECOS\n",
"\n",
"It pcost dcost gap pres dres k/t mu step sigma IR | BT\n",
" 0 -2.559e-02 -3.082e+01 +3e+03 9e-01 8e-05 1e+00 7e+00 --- --- 1 1 - | - - \n",
" 1 -2.473e+01 -2.541e+01 +7e+01 1e-01 2e-06 1e-02 2e-01 0.9779 1e-04 1 2 2 | 0 0\n",
" 2 -1.412e+00 -1.437e+00 +3e+00 5e-03 6e-08 5e-04 7e-03 0.9598 2e-03 2 3 3 | 0 0\n",
" 3 -1.019e+00 -1.035e+00 +2e+00 3e-03 4e-08 1e-03 5e-03 0.4692 3e-01 3 4 4 | 0 0\n",
" 4 -9.719e-01 -9.842e-01 +2e+00 3e-03 3e-08 2e-03 4e-03 0.5240 6e-01 3 4 3 | 0 0\n",
" 5 -3.633e-01 -3.662e-01 +4e-01 7e-04 8e-09 6e-04 1e-03 0.8629 1e-01 3 4 4 | 0 0\n",
" 6 -2.058e-01 -2.066e-01 +1e-01 2e-04 2e-09 2e-04 3e-04 0.8197 1e-01 3 4 4 | 0 0\n",
" 7 -1.579e-01 -1.581e-01 +3e-02 5e-05 6e-10 5e-05 7e-05 0.8711 1e-01 3 3 3 | 0 0\n",
" 8 -1.495e-01 -1.496e-01 +1e-02 2e-05 2e-10 2e-05 3e-05 0.7478 2e-01 2 3 3 | 0 0\n",
" 9 -1.468e-01 -1.468e-01 +7e-03 1e-05 2e-10 1e-05 2e-05 0.7025 5e-01 3 4 4 | 0 0\n",
"10 -1.440e-01 -1.440e-01 +1e-03 2e-06 3e-11 3e-06 4e-06 0.9500 1e-01 2 2 2 | 0 0\n",
"11 -1.434e-01 -1.434e-01 +2e-04 3e-07 4e-12 4e-07 5e-07 0.8916 4e-02 3 4 3 | 0 0\n",
"12 -1.433e-01 -1.433e-01 +2e-05 3e-08 3e-13 3e-08 4e-08 0.9253 3e-03 2 2 2 | 0 0\n",
"13 -1.433e-01 -1.433e-01 +7e-07 2e-09 1e-14 1e-09 2e-09 0.9585 5e-04 2 1 2 | 0 0\n",
"14 -1.433e-01 -1.433e-01 +4e-08 1e-09 1e-15 8e-11 1e-10 0.9563 2e-02 3 2 2 | 0 0\n",
"15 -1.433e-01 -1.433e-01 +1e-09 1e-10 8e-17 3e-12 4e-12 0.9676 8e-04 3 2 2 | 0 0\n",
"\n",
"OPTIMAL (within feastol=1.5e-10, reltol=1.0e-08, abstol=1.5e-09).\n",
"Runtime: 0.167465 seconds.\n",
"\n",
"CPU times: user 192 ms, sys: 0 ns, total: 192 ms\n",
"Wall time: 192 ms\n"
]
},
{
"data": {
"text/plain": [
"-0.14330450116208024"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"source": [
"%%time\n",
"%%time\n",
"prob.solve(verbose=True)"
"prob.solve(verbose=True)"
...
@@ -187,18 +284,63 @@
...
@@ -187,18 +284,63 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
null
,
"execution_count":
14
,
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"('optimal', -0.14330450116208024)"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"source": [
"prob.status, prob.value"
"prob.status, prob.value"
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
null
,
"execution_count":
15
,
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" pcost dcost gap pres dres k/t\n",
" 0: -2.3359e-02 -3.1007e+01 7e+02 1e+01 9e-03 1e+00\n",
" 1: -1.1146e+01 -1.5653e+01 6e+01 1e+00 1e-03 2e-02\n",
" 2: -1.7778e+00 -2.7042e+00 7e+00 3e-01 3e-04 3e-02\n",
" 3: -3.8072e-01 -5.2347e-01 8e-01 5e-02 4e-05 5e-03\n",
" 4: -2.0231e-01 -2.3403e-01 2e-01 1e-02 9e-06 1e-03\n",
" 5: -1.5540e-01 -1.6212e-01 3e-02 2e-03 2e-06 2e-04\n",
" 6: -1.4464e-01 -1.4561e-01 4e-03 3e-04 3e-07 3e-05\n",
" 7: -1.4358e-01 -1.4376e-01 8e-04 6e-05 5e-08 4e-06\n",
" 8: -1.4340e-01 -1.4346e-01 3e-04 2e-05 2e-08 1e-06\n",
" 9: -1.4333e-01 -1.4334e-01 5e-05 4e-06 4e-09 2e-07\n",
"10: -1.4331e-01 -1.4331e-01 8e-06 6e-07 5e-10 3e-08\n",
"11: -1.4330e-01 -1.4330e-01 4e-07 3e-08 3e-11 1e-09\n",
"12: -1.4330e-01 -1.4330e-01 3e-08 2e-09 5e-12 9e-11\n",
"Optimal solution found.\n",
"CPU times: user 248 ms, sys: 12 ms, total: 260 ms\n",
"Wall time: 103 ms\n"
]
},
{
"data": {
"text/plain": [
"-0.14330451119270352"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"source": [
"%%time\n",
"%%time\n",
"prob.solve(verbose=True, solver='CVXOPT')"
"prob.solve(verbose=True, solver='CVXOPT')"
...
@@ -206,18 +348,51 @@
...
@@ -206,18 +348,51 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
null
,
"execution_count":
16
,
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"('optimal', -0.14330451119270352)"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"source": [
"prob.status, prob.value"
"prob.status, prob.value"
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
null
,
"execution_count":
17
,
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" pcost dcost gap pres dres\n",
" 0: -2.6176e-01 -2.1588e+01 5e+02 2e+01 7e-16\n",
" 1: -2.1701e-01 -1.8470e+01 4e+01 8e-01 1e-15\n",
" 2: -4.4680e-02 -5.2189e+00 6e+00 5e-02 2e-15\n",
" 3: -4.2473e-02 -1.4144e+00 1e+00 1e-02 2e-15\n",
" 4: -9.7185e-02 -3.4512e-01 3e-01 1e-03 1e-15\n",
" 5: -1.2997e-01 -1.8100e-01 5e-02 1e-04 9e-16\n",
" 6: -1.4069e-01 -1.4831e-01 8e-03 1e-05 9e-16\n",
" 7: -1.4300e-01 -1.4373e-01 7e-04 9e-07 8e-16\n",
" 8: -1.4329e-01 -1.4332e-01 3e-05 2e-08 8e-16\n",
" 9: -1.4330e-01 -1.4330e-01 8e-07 3e-10 7e-16\n",
"10: -1.4330e-01 -1.4330e-01 5e-08 6e-12 8e-16\n",
"Optimal solution found.\n",
"CPU times: user 36 ms, sys: 0 ns, total: 36 ms\n",
"Wall time: 10.4 ms\n"
]
}
],
"source": [
"source": [
"%%time\n",
"%%time\n",
"P = matrix(sec_cov_values)\n",
"P = matrix(sec_cov_values)\n",
...
@@ -253,7 +428,7 @@
...
@@ -253,7 +428,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
null
,
"execution_count":
18
,
"metadata": {
"metadata": {
"collapsed": true
"collapsed": true
},
},
...
@@ -264,7 +439,7 @@
...
@@ -264,7 +439,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
null
,
"execution_count":
19
,
"metadata": {
"metadata": {
"collapsed": true
"collapsed": true
},
},
...
@@ -278,7 +453,7 @@
...
@@ -278,7 +453,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
null
,
"execution_count":
26
,
"metadata": {
"metadata": {
"collapsed": true
"collapsed": true
},
},
...
@@ -288,7 +463,7 @@
...
@@ -288,7 +463,7 @@
" w = Variable(n)\n",
" w = Variable(n)\n",
"\n",
"\n",
" lbound = 0.\n",
" lbound = 0.\n",
" ubound = 0.
2
\n",
" ubound = 0.
01
\n",
"\n",
"\n",
" objective = Minimize(risk_penlty * quad_form(w, sec_cov_values) - signal * w)\n",
" objective = Minimize(risk_penlty * quad_form(w, sec_cov_values) - signal * w)\n",
" constraints = [w >= lbound,\n",
" constraints = [w >= lbound,\n",
...
@@ -302,7 +477,7 @@
...
@@ -302,7 +477,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
null
,
"execution_count":
27
,
"metadata": {
"metadata": {
"collapsed": true
"collapsed": true
},
},
...
@@ -316,7 +491,7 @@
...
@@ -316,7 +491,7 @@
" h = np.zeros(2*n)\n",
" h = np.zeros(2*n)\n",
" for i in range(n):\n",
" for i in range(n):\n",
" G[i, i] = 1.\n",
" G[i, i] = 1.\n",
" h[i] = 0.
2
\n",
" h[i] = 0.
01
\n",
" G[i+n, i] = -1.\n",
" G[i+n, i] = -1.\n",
" h[i+n] = 0.\n",
" h[i+n] = 0.\n",
"\n",
"\n",
...
@@ -336,9 +511,32 @@
...
@@ -336,9 +511,32 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
null
,
"execution_count":
28
,
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Scale(n) cvxpy cvxopt\n",
"200 87.80 7.70\n",
"400 366.22 33.57\n",
"600 838.53 110.26\n",
"800 1725.66 260.92\n",
"1000 3044.70 419.04\n",
"1200 4837.05 700.29\n",
"1400 7262.97 986.25\n",
"1600 10164.79 1630.48\n",
"1800 14156.31 2087.67\n",
"2000 18535.12 2939.18\n",
"2200 23514.86 3707.77\n",
"2400 31820.74 5012.17\n",
"2600 36870.51 6059.89\n",
"2800 44492.36 7884.96\n",
"3000 57279.62 10197.77\n"
]
}
],
"source": [
"source": [
"n_steps = list(range(200, 3001, 200))\n",
"n_steps = list(range(200, 3001, 200))\n",
"cvxpy_times = [None] * len(n_steps)\n",
"cvxpy_times = [None] * len(n_steps)\n",
...
@@ -357,16 +555,150 @@
...
@@ -357,16 +555,150 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null,
"execution_count": 30,
"metadata": {
"metadata": {},
"collapsed": true
"outputs": [
},
{
"outputs": [],
"data": {
"text/html": [
"<div>\n",
"<style>\n",
" .dataframe thead tr:only-child th {\n",
" text-align: right;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>cvxopt</th>\n",
" <th>cvxpy</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Problem Scale (n)</th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>200</th>\n",
" <td>7.700</td>\n",
" <td>87.805</td>\n",
" </tr>\n",
" <tr>\n",
" <th>400</th>\n",
" <td>33.566</td>\n",
" <td>366.222</td>\n",
" </tr>\n",
" <tr>\n",
" <th>600</th>\n",
" <td>110.256</td>\n",
" <td>838.531</td>\n",
" </tr>\n",
" <tr>\n",
" <th>800</th>\n",
" <td>260.924</td>\n",
" <td>1725.662</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1000</th>\n",
" <td>419.037</td>\n",
" <td>3044.700</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1200</th>\n",
" <td>700.287</td>\n",
" <td>4837.045</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1400</th>\n",
" <td>986.254</td>\n",
" <td>7262.970</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1600</th>\n",
" <td>1630.484</td>\n",
" <td>10164.791</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1800</th>\n",
" <td>2087.670</td>\n",
" <td>14156.305</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2000</th>\n",
" <td>2939.184</td>\n",
" <td>18535.122</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2200</th>\n",
" <td>3707.774</td>\n",
" <td>23514.858</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2400</th>\n",
" <td>5012.174</td>\n",
" <td>31820.735</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2600</th>\n",
" <td>6059.892</td>\n",
" <td>36870.513</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2800</th>\n",
" <td>7884.956</td>\n",
" <td>44492.361</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3000</th>\n",
" <td>10197.773</td>\n",
" <td>57279.625</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" cvxopt cvxpy\n",
"Problem Scale (n) \n",
"200 7.700 87.805\n",
"400 33.566 366.222\n",
"600 110.256 838.531\n",
"800 260.924 1725.662\n",
"1000 419.037 3044.700\n",
"1200 700.287 4837.045\n",
"1400 986.254 7262.970\n",
"1600 1630.484 10164.791\n",
"1800 2087.670 14156.305\n",
"2000 2939.184 18535.122\n",
"2200 3707.774 23514.858\n",
"2400 5012.174 31820.735\n",
"2600 6059.892 36870.513\n",
"2800 7884.956 44492.361\n",
"3000 10197.773 57279.625"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"source": [
"df = pd.DataFrame({'cvxpy': cvxpy_times,\n",
"df = pd.DataFrame({'cvxpy': cvxpy_times,\n",
" 'cvxopt': cvxopt_times},\n",
" 'cvxopt': cvxopt_times},\n",
" index=n_steps)\n",
" index=n_steps)\n",
"df.index.name = 'Problem Scale (n)'"
"df.index.name = 'Problem Scale (n)'\n",
"df"
]
]
},
},
{
{
...
@@ -383,7 +715,9 @@
...
@@ -383,7 +715,9 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null,
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"outputs": [],
"source": [
"source": [
"df"
"df"
...
@@ -392,7 +726,9 @@
...
@@ -392,7 +726,9 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null,
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"outputs": [],
"source": [
"source": [
"risk_penlty"
"risk_penlty"
...
@@ -401,7 +737,9 @@
...
@@ -401,7 +737,9 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null,
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"outputs": [],
"source": [
"source": [
"np.array(sol['x']).flatten()"
"np.array(sol['x']).flatten()"
...
@@ -410,7 +748,9 @@
...
@@ -410,7 +748,9 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null,
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"outputs": [],
"source": [
"source": [
"np.linalg.det(sec_cov_values_full)"
"np.linalg.det(sec_cov_values_full)"
...
@@ -419,7 +759,9 @@
...
@@ -419,7 +759,9 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null,
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"outputs": [],
"source": [
"source": [
"sec_cov_values_full.diagonal().mean()"
"sec_cov_values_full.diagonal().mean()"
...
@@ -428,7 +770,9 @@
...
@@ -428,7 +770,9 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null,
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"outputs": [],
"source": [
"source": [
"np.linalg.svd(sec_cov_values_full)"
"np.linalg.svd(sec_cov_values_full)"
...
@@ -459,7 +803,9 @@
...
@@ -459,7 +803,9 @@
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": null,
"execution_count": null,
"metadata": {},
"metadata": {
"collapsed": true
},
"outputs": [],
"outputs": [],
"source": [
"source": [
"sol['dual objective']"
"sol['dual objective']"
...
@@ -477,7 +823,7 @@
...
@@ -477,7 +823,7 @@
],
],
"metadata": {
"metadata": {
"kernelspec": {
"kernelspec": {
"display_name": "Python
[default]
",
"display_name": "Python
3
",
"language": "python",
"language": "python",
"name": "python3"
"name": "python3"
},
},
...
...
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