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

fixed bug for mv optimizer

parent 857b3ce6
......@@ -230,8 +230,8 @@ def factor_analysis(factors: pd.DataFrame,
lbound, ubound, cons_exp, risk_lbound, risk_ubound = create_constraints(benchmark, **kwargs)
cov = kwargs['cov']
if 'lambda' in kwargs:
lam = kwargs['lambda']
if 'lam' in kwargs:
lam = kwargs['lam']
else:
lam = 1.
......
......@@ -209,33 +209,18 @@ class SqlEngine(object):
if __name__ == '__main__':
db_url = 'mssql+pymssql://licheng:A12345678!@10.63.6.220/alpha?charset=cp936'
from alphamind.data.dbmodel.models import Uqer
import datetime as dt
universe = Universe('custom', ['ashare'])
universe = Universe('custom', ['zz500'])
engine = SqlEngine(db_url)
ref_date = '2017-07-21'
ref_date = '2017-01-17'
codes = engine.fetch_codes(ref_date, universe)
data = engine.fetch_data(ref_date, ['EPS'], codes, 905)
d1ret = engine.fetch_dx_return(ref_date, codes, horizon=0)
start = dt.datetime.now()
for i in range(100):
codes = engine.fetch_codes(ref_date, universe)
print(dt.datetime.now() - start)
print(codes)
print(len(codes))
universe = Universe('zz500', ['zz500'])
engine = SqlEngine(db_url)
ref_date = '2017-07-04'
start = dt.datetime.now()
for i in range(100):
codes = engine.fetch_codes(ref_date, universe)
print(dt.datetime.now() - start)
print(codes)
print(len(codes))
missing_codes = [c for c in data['factor'].Code if c not in set(d1ret.Code)]
print(len(data['factor']))
print(len(d1ret))
print(missing_codes)
......@@ -5,69 +5,80 @@ Created on 2017-7-10
@author: cheng.li
"""
import datetime as dt
import numpy as np
import pandas as pd
from alphamind.analysis.factoranalysis import factor_analysis
from alphamind.data.engines.sqlengine import risk_styles
from alphamind.data.engines.sqlengine import industry_styles
from alphamind.portfolio.constraints import Constraints
from alphamind.data.engines.sqlengine import SqlEngine
from alphamind.data.engines.universe import Universe
from alphamind.data.engines.sqlengine import industry_styles
from PyFin.api import bizDatesList
from PyFin.api import makeSchedule
engine = SqlEngine('mssql+pymssql://licheng:A12345678!@10.63.6.220/alpha')
universe = Universe('custom', ['zz500'])
dates = bizDatesList('china.sse', '2017-01-01', '2017-08-05')
factors = ['EPS', 'FEARNG', 'VAL', 'NIAP']
f_weights = np.array([1., 1., 1., 1.])
used_risk_styles = ['SIZE']
total_risks = used_risk_styles + industry_styles
build_type = 'risk_neutral'
neutralize_risk = ['SIZE'] + industry_styles
constraint_risk = []
def calculate_one_day(ref_date, factors, factor_weights, horizon_end=None):
print(ref_date)
rets = []
for date in dates:
print(date)
ref_date = date.strftime('%Y-%m-%d')
codes = engine.fetch_codes(ref_date, universe)
total_data = engine.fetch_data(ref_date, factors, codes, 905)
factor_data = total_data['factor']
factor_df = factor_data[['Code', 'industry', 'weight', 'isOpen'] + total_risks + factors].dropna()
dx_return = engine.fetch_dx_return(ref_date, codes, expiry_date=horizon_end)
factor_df = pd.merge(factor_df, dx_return, on=['Code'])
weights, _ = factor_analysis(factor_df[factors],
factor_weights,
factor_df.industry.values,
None,
detail_analysis=False,
benchmark=factor_df.weight.values,
risk_exp=factor_df[total_risks].values,
is_tradable=factor_df.isOpen.values.astype(bool),
method=build_type)
return ref_date, (weights.weight - factor_df.weight).dot(factor_df.dx)
if __name__ == '__main__':
from matplotlib import pyplot as plt
factors = ['BDTO', 'CFinc1', 'DivP', 'EPS', 'RVOL', 'DROEAfterNonRecurring']
factor_weights = [0.10, 0.30, 0.15, 0.18, 0.11, 0.35]
biz_dates = makeSchedule('2015-01-01', '2017-07-07', '1w', 'china.sse')
ers = []
dates = []
for i, ref_date in enumerate(biz_dates[:-1]):
ref_date = ref_date.strftime("%Y-%m-%d")
try:
ref_date, er = calculate_one_day(ref_date, factors, factor_weights, horizon_end=biz_dates[i+1])
dates.append(ref_date)
ers.append(er)
except Exception as e:
print(str(e) + ": {0}".format(ref_date))
res = pd.Series(ers, index=dates)
res.cumsum().plot()
plt.show()
data = engine.fetch_data(ref_date, factors, codes, 905, risk_model='short')
returns = engine.fetch_dx_return(ref_date, codes, 0)
total_data = pd.merge(data['factor'], returns, on=['Code']).dropna()
risk_cov = data['risk_cov']
total_risks = risk_cov.Factor
risk_cov = risk_cov[total_risks]
risk_exp = total_data[total_risks]
stocks_cov = ((risk_exp.values @ risk_cov.values @ risk_exp.values.T) + np.diag(total_data.SRISK ** 2)) / 10000.
f_data = total_data[factors]
industry = total_data.industry_code.values
dx_return = total_data.dx.values
benchmark = total_data.weight.values
risk_exp = total_data[neutralize_risk].values
constraint_exp = total_data[constraint_risk].values
risk_exp_expand = np.concatenate((constraint_exp, np.ones((len(risk_exp), 1))), axis=1).astype(float)
risk_names = constraint_risk + ['total']
risk_target = risk_exp_expand.T @ benchmark
lbound = 0.
ubound = 0.05 + benchmark
constraint = Constraints(risk_exp_expand, risk_names)
for i, name in enumerate(risk_names):
constraint.set_constraints(name, lower_bound=risk_target[i], upper_bound=risk_target[i])
try:
pos, analysis = factor_analysis(f_data,
f_weights,
industry,
dx_return,
benchmark=benchmark,
risk_exp=risk_exp,
is_tradable=total_data.isOpen.values.astype(bool),
method='mv',
constraints=constraint,
cov=stocks_cov,
use_rank=100,
lam=100.,
lbound=lbound,
ubound=ubound)
except:
rets.append(0.)
print("{0} is error!".format(date))
else:
rets.append(analysis.er[-1])
ret_series = pd.Series(rets, dates)
\ No newline at end of file
......@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
......@@ -15,7 +15,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {
"collapsed": true
},
......@@ -26,8 +26,10 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def time_function(py_callable, n):\n",
......@@ -66,13 +68,36 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"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.01 -0.82 0.000000 0.010000 1.000000 0.015\n",
"400 23.02 -1.28 -0.000000 0.010000 1.000000 0.015\n",
"600 42.63 -1.54 -0.000000 0.010000 1.000000 0.015\n",
"800 62.04 -1.63 -0.000000 0.010000 1.000000 0.015\n",
"1000 76.57 -1.72 -0.000000 0.010000 1.000000 0.015\n",
"1200 108.73 -1.81 -0.000000 0.010000 1.000000 0.015\n",
"1400 136.22 -1.90 -0.000000 0.010000 1.000000 0.015\n",
"1600 166.64 -1.96 -0.000000 0.010000 1.000000 0.015\n",
"1800 197.72 -2.03 -0.000000 0.010000 1.000000 0.015\n",
"2000 258.51 -2.06 -0.000000 0.010000 1.000000 0.015\n",
"2200 291.34 -2.07 -0.000000 0.010000 1.000000 0.015\n",
"2400 348.30 -2.13 -0.000000 0.010000 1.000000 0.015\n",
"2600 398.31 -2.14 -0.000000 0.010000 1.000000 0.015\n",
"2800 462.13 -2.16 -0.000000 0.010000 1.000000 0.015\n",
"3000 547.84 -2.19 -0.000000 0.010000 1.000000 0.015\n"
]
}
],
"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",
"\n",
"for n in range(200, 10200, 200):\n",
"for n in range(200, 3200, 200):\n",
" elapsed, result = time_function(cvxpy_lp, n)\n",
" s = np.array(result[0].value).flatten()\n",
" print(\"{0:<8}{1:>12.2f}{2:>12.2f}{3:>12f}{4:>12f}{5:>12f}{6:>15}\".format(n, elapsed*1000, result[1].value, s.min(), s.max(), s.sum(), s[0] + s[1]))"
......@@ -80,7 +105,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {
"collapsed": true
},
......@@ -105,13 +130,36 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"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 19.01 -0.82 0.000000 0.010000 1.000000 0.015\n",
"400 1.00 -1.28 0.000000 0.010000 1.000000 0.015\n",
"600 2.00 -1.54 0.000000 0.010000 1.000000 0.015\n",
"800 3.00 -1.63 0.000000 0.010000 1.000000 0.015\n",
"1000 2.00 -1.72 0.000000 0.010000 1.000000 0.015\n",
"1200 3.00 -1.81 0.000000 0.010000 1.000000 0.015\n",
"1400 2.02 -1.90 0.000000 0.010000 1.000000 0.015\n",
"1600 2.02 -1.96 0.000000 0.010000 1.000000 0.015\n",
"1800 1.98 -2.03 0.000000 0.010000 1.000000 0.015\n",
"2000 2.02 -2.06 0.000000 0.010000 1.000000 0.015\n",
"2200 2.00 -2.07 0.000000 0.010000 1.000000 0.015\n",
"2400 2.00 -2.13 0.000000 0.010000 1.000000 0.015\n",
"2600 3.00 -2.14 0.000000 0.010000 1.000000 0.015\n",
"2800 3.02 -2.16 0.000000 0.010000 1.000000 0.015\n",
"3000 3.00 -2.19 0.000000 0.010000 1.000000 0.015\n"
]
}
],
"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",
"\n",
"for n in range(200, 10200, 200):\n",
"for n in range(200, 3200, 200):\n",
" elapsed, result = time_function(clp_lp, n)\n",
" s = result[2]\n",
" print(\"{0:<8}{1:>12.2f}{2:>12.2f}{3:>12f}{4:>12f}{5:>12f}{6:>15}\".format(n, elapsed*1000, result[1], s.min(), s.max(), s.sum(), s[0] + s[1]))"
......@@ -129,7 +177,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python [default]",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
......
......@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {
"collapsed": true
},
......@@ -25,7 +25,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {
"collapsed": true
},
......@@ -36,7 +36,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {
"collapsed": true
},
......@@ -48,7 +48,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {
"collapsed": true
},
......@@ -70,9 +70,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Wall time: 121 ms\n"
]
}
],
"source": [
"%%time\n",
"w = Variable(n)\n",
......@@ -90,9 +98,51 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"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 9e-16 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 5e-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.184433 seconds.\n",
"\n",
"Wall time: 265 ms\n"
]
},
{
"data": {
"text/plain": [
"-0.14330450116149787"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%time\n",
"prob.solve(verbose=True)"
......@@ -100,18 +150,62 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"('optimal', -0.14330450116149787)"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"prob.status, prob.value"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"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 7e-12 9e-11\n",
"Optimal solution found.\n",
"Wall time: 195 ms\n"
]
},
{
"data": {
"text/plain": [
"-0.1433045111926663"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%time\n",
"prob.solve(verbose=True, solver='CVXOPT')"
......@@ -119,18 +213,50 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"('optimal', -0.1433045111926663)"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"prob.status, prob.value"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"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 1e-15\n",
" 1: -2.1701e-01 -1.8470e+01 4e+01 8e-01 2e-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 3e-15\n",
" 4: -9.7185e-02 -3.4512e-01 3e-01 1e-03 2e-15\n",
" 5: -1.2997e-01 -1.8100e-01 5e-02 1e-04 1e-15\n",
" 6: -1.4069e-01 -1.4831e-01 8e-03 1e-05 1e-15\n",
" 7: -1.4300e-01 -1.4373e-01 7e-04 9e-07 1e-15\n",
" 8: -1.4329e-01 -1.4332e-01 3e-05 2e-08 1e-15\n",
" 9: -1.4330e-01 -1.4330e-01 8e-07 3e-10 1e-15\n",
"10: -1.4330e-01 -1.4330e-01 5e-08 6e-12 1e-15\n",
"Optimal solution found.\n",
"Wall time: 55.1 ms\n"
]
}
],
"source": [
"%%time\n",
"P = matrix(sec_cov_values)\n",
......@@ -158,14 +284,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 16,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Wall time: 37 ms\n"
]
}
],
"source": [
"%%time\n",
"lbound = np.zeros(n)\n",
"ubound = np.ones(n) * 20 / n\n",
"qpopt = QPOptimizer(signal, sec_cov_values, lbound, ubound, 1.)\n",
"cons_matrix = np.ones((1, n))\n",
"clb = np.ones(1)\n",
"cub = np.ones(1)\n",
"qpopt = QPOptimizer(signal, sec_cov_values, lbound, ubound, cons_matrix, clb, cub, 1.)\n",
"qpopt.feval()\n",
"qpopt.status()"
]
......@@ -180,7 +317,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 17,
"metadata": {
"collapsed": true
},
......@@ -191,7 +328,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 18,
"metadata": {
"collapsed": true
},
......@@ -205,7 +342,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 19,
"metadata": {
"collapsed": true
},
......@@ -228,7 +365,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 20,
"metadata": {
"collapsed": true
},
......@@ -261,7 +398,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 23,
"metadata": {
"collapsed": true
},
......@@ -270,15 +407,42 @@
"def ipopt(n):\n",
" lbound = np.zeros(n)\n",
" ubound = np.ones(n) * 0.01\n",
" qpopt = QPOptimizer(signal, sec_cov_values, lbound, ubound, 1.)\n",
" cons_matrix = np.ones((1, n))\n",
" clb = np.ones(1)\n",
" cub = np.ones(1)\n",
" qpopt = QPOptimizer(signal, sec_cov_values, lbound, ubound, cons_matrix, clb, cub, 1.)\n",
" qpopt.feval()"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 24,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Scale(n) cvxpy cvxopt ipopt\n",
"200 197.63 45.03 25.02\n",
"400 1029.54 392.71 66.05\n",
"600 2765.32 1290.11 101.07\n",
"800 5906.85 3147.61 123.10\n",
"1000 11623.60 5949.30 181.69\n",
"1200 19327.03 9837.68 279.76\n",
"1400 28894.03 14138.84 529.42\n",
"1600 40706.67 21410.84 550.92\n",
"1800 59016.47 29610.92 737.62\n",
"2000 77980.53 41321.95 818.84\n",
"2200 98591.72 52743.93 1310.13\n",
"2400 139175.23 76199.42 2156.20\n",
"2600 170922.06 89493.43 1591.01\n",
"2800 197469.52 112762.10 1569.06\n",
"3000 246957.32 135002.46 1484.89\n",
"3200 291831.05 160416.66 1919.71\n"
]
}
],
"source": [
"n_steps = list(range(200, 3201, 200))\n",
"cvxpy_times = [None] * len(n_steps)\n",
......@@ -298,11 +462,168 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"execution_count": 21,
"metadata": {},
"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",
" <th>ipopt</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Problem Scale (n)</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>200</th>\n",
" <td>49.039</td>\n",
" <td>207.656</td>\n",
" <td>27.019</td>\n",
" </tr>\n",
" <tr>\n",
" <th>400</th>\n",
" <td>358.899</td>\n",
" <td>976.404</td>\n",
" <td>51.080</td>\n",
" </tr>\n",
" <tr>\n",
" <th>600</th>\n",
" <td>1222.190</td>\n",
" <td>2811.124</td>\n",
" <td>108.764</td>\n",
" </tr>\n",
" <tr>\n",
" <th>800</th>\n",
" <td>3051.363</td>\n",
" <td>5794.853</td>\n",
" <td>121.119</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1000</th>\n",
" <td>5858.366</td>\n",
" <td>11435.303</td>\n",
" <td>192.262</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1200</th>\n",
" <td>9806.112</td>\n",
" <td>18855.293</td>\n",
" <td>272.055</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1400</th>\n",
" <td>13928.818</td>\n",
" <td>28437.877</td>\n",
" <td>536.453</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1600</th>\n",
" <td>20971.899</td>\n",
" <td>39959.689</td>\n",
" <td>583.744</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1800</th>\n",
" <td>28056.363</td>\n",
" <td>63106.509</td>\n",
" <td>630.622</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2000</th>\n",
" <td>39500.814</td>\n",
" <td>74439.178</td>\n",
" <td>797.706</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2200</th>\n",
" <td>49913.609</td>\n",
" <td>97029.306</td>\n",
" <td>1434.759</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2400</th>\n",
" <td>71256.090</td>\n",
" <td>140969.086</td>\n",
" <td>2002.379</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2600</th>\n",
" <td>88315.444</td>\n",
" <td>159561.312</td>\n",
" <td>1576.816</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2800</th>\n",
" <td>112728.898</td>\n",
" <td>200788.253</td>\n",
" <td>1523.572</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3000</th>\n",
" <td>135712.700</td>\n",
" <td>259485.171</td>\n",
" <td>1641.147</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3200</th>\n",
" <td>175046.983</td>\n",
" <td>314367.647</td>\n",
" <td>2021.378</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" cvxopt cvxpy ipopt\n",
"Problem Scale (n) \n",
"200 49.039 207.656 27.019\n",
"400 358.899 976.404 51.080\n",
"600 1222.190 2811.124 108.764\n",
"800 3051.363 5794.853 121.119\n",
"1000 5858.366 11435.303 192.262\n",
"1200 9806.112 18855.293 272.055\n",
"1400 13928.818 28437.877 536.453\n",
"1600 20971.899 39959.689 583.744\n",
"1800 28056.363 63106.509 630.622\n",
"2000 39500.814 74439.178 797.706\n",
"2200 49913.609 97029.306 1434.759\n",
"2400 71256.090 140969.086 2002.379\n",
"2600 88315.444 159561.312 1576.816\n",
"2800 112728.898 200788.253 1523.572\n",
"3000 135712.700 259485.171 1641.147\n",
"3200 175046.983 314367.647 2021.378"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = pd.DataFrame({'cvxpy': cvxpy_times,\n",
" 'cvxopt': cvxopt_times,\n",
......@@ -324,7 +645,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python [default]",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
......
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