Commit 1f2a9f99 authored by Dr.李's avatar Dr.李

added mean variance optimizer

parent 614b98a4
......@@ -10,5 +10,4 @@ Alpha_Mind.egg-info/*
*.nbc
*.nbi
/notebooks/.ipynb_checkpoints
alphamind/examples/*
notebooks/*
\ No newline at end of file
alphamind/examples/*
\ No newline at end of file
......@@ -29,7 +29,7 @@ cdef class LPOptimizer:
cnp.ndarray[double] ubound,
cnp.ndarray[double] objective):
self.cobj = new LpOptimizer(cons_matrix.flatten(),
self.cobj = new LpOptimizer(cons_matrix.flatten(order='C'),
lbound,
ubound,
objective)
......@@ -47,25 +47,30 @@ cdef class LPOptimizer:
return np.array(self.cobj.xValue())
cdef extern from "meanvariance.hpp" namespace "pfopt":
cdef cppclass MeanVariance:
MeanVariance(vector[double], vector[double], double) except +
cdef extern from "mvoptimizer.hpp" namespace "pfopt":
cdef cppclass MVOptimizer:
MVOptimizer(vector[double], vector[double], vector[double], vector[double], double) except +
vector[double] xValue()
double feval()
int status()
cdef class MVOptimizer:
cdef class QPOptimizer:
cdef MeanVariance* cobj
cdef MVOptimizer* cobj
def __init__(self,
cnp.ndarray[double] expected_return,
cnp.ndarray[double, ndim=2] cov_matrix,
cnp.ndarray[double] lbound,
cnp.ndarray[double] ubound,
double risk_aversion):
self.cobj = new MeanVariance(expected_return,
cov_matrix.flatten(),
risk_aversion)
self.cobj = new MVOptimizer(expected_return,
cov_matrix.flatten(order='C'),
lbound,
ubound,
risk_aversion)
def __del__(self):
del self.cobj
......@@ -74,4 +79,7 @@ cdef class MVOptimizer:
return self.cobj.feval()
def x_value(self):
return np.array(self.cobj.xValue())
\ No newline at end of file
return np.array(self.cobj.xValue())
def status(self):
return self.cobj.status()
\ No newline at end of file
......@@ -8,19 +8,19 @@
namespace pfopt {
class PFOPT_CLASS LpOptimizer {
public:
LpOptimizer(const std::vector<double>& constraintsMatraix,
const std::vector<double>& lowerBound,
const std::vector<double>& upperBound,
const std::vector<double>& objective);
public:
LpOptimizer(const std::vector<double>& constraintsMatraix,
const std::vector<double>& lowerBound,
const std::vector<double>& upperBound,
const std::vector<double>& objective);
std::vector<double> xValue() const;
double feval() const;
int status() const { return model_.status();}
std::vector<double> xValue() const;
double feval() const;
int status() const { return model_.status(); }
private:
ClpSimplex model_;
int numberOfProb_;
private:
ClpSimplex model_;
int numberOfProb_;
};
}
......
......@@ -21,7 +21,7 @@ namespace pfopt {
const std::vector<double> &varMatrix,
double riskAversion=1.);
bool setBoundedConstraint(const VectorXd& lb, const VectorXd& ub);
bool setBoundedConstraint(const std::vector<double>& lb, const std::vector<double>& ub);
virtual bool get_nlp_info(Index &n, Index &m, Index &nnz_jac_g,
Index &nnz_h_lag, IndexStyleEnum &index_style);
......
#ifndef pfopt_mv_optimizer_hpp
#define pfopt_mv_optimizer_hpp
#include "meanvariance.hpp"
#include <coin/IpIpoptApplication.hpp>
namespace pfopt {
class PFOPT_CLASS MVOptimizer {
public:
MVOptimizer(const std::vector<double> &expectReturn,
const std::vector<double> &varMatrix,
const std::vector<double> &lbound,
const std::vector<double> &ubound,
double riskAversion);
std::vector<double> xValue() const { return mvImpl_->xValue(); }
double feval() const { return mvImpl_->feval(); }
int status() const { return status_; }
private:
Ipopt::SmartPtr<MeanVariance> mvImpl_;
Ipopt::SmartPtr<Ipopt::IpoptApplication> app_;
Ipopt::ApplicationReturnStatus status_;
};
}
#endif
\ No newline at end of file
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"from cvxpy import *\n",
"from cvxopt import *\n",
"from alphamind.cython.optimizers import QPOptimizer"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Data Preparing\n",
"--------------------------"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"risk_penlty = 0.5"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"sec_cov_values_full = np.genfromtxt('sec_cov_values.csv', delimiter=',')\n",
"signal_full = np.genfromtxt('signal.csv', delimiter=',')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"n = 200\n",
"\n",
"sec_cov_values = sec_cov_values_full[:n, :n]\n",
"signal = signal_full[:n]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Optimizing Weights\n",
"-------------------------------------"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%time\n",
"w = Variable(n)\n",
"\n",
"lbound = 0.\n",
"ubound = 1. / n * 20\n",
"\n",
"objective = Minimize(risk_penlty * quad_form(w, sec_cov_values) - signal * w)\n",
"constraints = [w >= lbound,\n",
" w <= ubound,\n",
" sum_entries(w) == 1,]\n",
"\n",
"prob = Problem(objective, constraints)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%time\n",
"prob.solve(verbose=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"prob.status, prob.value"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%time\n",
"prob.solve(verbose=True, solver='CVXOPT')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"prob.status, prob.value"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%time\n",
"P = matrix(sec_cov_values)\n",
"q = -matrix(signal)\n",
"\n",
"G = np.zeros((2*n, n))\n",
"h = np.zeros(2*n)\n",
"for i in range(n):\n",
" G[i, i] = 1.\n",
" h[i] = 1. / n * 20\n",
" G[i+n, i] = -1.\n",
" h[i+n] = 0.\n",
" \n",
"G = matrix(G)\n",
"h = matrix(h)\n",
" \n",
"A = np.ones((1, n))\n",
"b = np.ones(1)\n",
"\n",
"A = matrix(A)\n",
"b = matrix(b)\n",
"\n",
"sol = solvers.qp(P, q, G, h, A, b)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"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",
"qpopt.feval()\n",
"qpopt.status()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Performace Timing\n",
"-------------------------"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import datetime as dt"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def time_function(py_callable, n):\n",
" start = dt.datetime.now()\n",
" py_callable(n)\n",
" return (dt.datetime.now() - start).total_seconds()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def cvxpy(n):\n",
" w = Variable(n)\n",
"\n",
" lbound = 0.\n",
" ubound = 0.01\n",
"\n",
" objective = Minimize(risk_penlty * quad_form(w, sec_cov_values) - signal * w)\n",
" constraints = [w >= lbound,\n",
" w <= ubound,\n",
" sum_entries(w) == 1,]\n",
"\n",
" prob = Problem(objective, constraints)\n",
" prob.solve(verbose=False, solver='CVXOPT', display=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def cvxopt(n):\n",
" P = matrix(sec_cov_values)\n",
" q = -matrix(signal)\n",
"\n",
" G = np.zeros((2*n, n))\n",
" h = np.zeros(2*n)\n",
" for i in range(n):\n",
" G[i, i] = 1.\n",
" h[i] = 0.01\n",
" G[i+n, i] = -1.\n",
" h[i+n] = 0.\n",
"\n",
" G = matrix(G)\n",
" h = matrix(h)\n",
"\n",
" A = np.ones((1, n))\n",
" b = np.ones(1)\n",
"\n",
" A = matrix(A)\n",
" b = matrix(b)\n",
" \n",
" solvers.options['show_progress'] = False\n",
" sol = solvers.qp(P, q, G, h, A, b)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"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",
" qpopt.feval()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"n_steps = list(range(200, 3201, 200))\n",
"cvxpy_times = [None] * len(n_steps)\n",
"cvxopt_times = [None] * len(n_steps)\n",
"ipopt_times = [None] * len(n_steps)\n",
"print(\"{0:<8}{1:>12}{2:>12}{3:>12}\".format('Scale(n)', 'cvxpy', 'cvxopt', 'ipopt'))\n",
"\n",
"for i, n in enumerate(n_steps):\n",
" sec_cov_values = sec_cov_values_full[:n, :n]\n",
" signal = signal_full[:n]\n",
" cvxpy_times[i] = time_function(cvxpy, n) * 1000\n",
" cvxopt_times[i] = time_function(cvxopt, n) * 1000\n",
" ipopt_times[i] = time_function(ipopt, n) * 1000\n",
" \n",
" print(\"{0:<8}{1:>12.2f}{2:>12.2f}{3:>12.2f}\".format(n, cvxpy_times[i], cvxopt_times[i], ipopt_times[i]))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"df = pd.DataFrame({'cvxpy': cvxpy_times,\n",
" 'cvxopt': cvxopt_times,\n",
" 'ipopt': ipopt_times},\n",
" index=n_steps)\n",
"df.index.name = 'Problem Scale (n)'\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [default]",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
{
"cells": [
{
"cell_type": "code",
"execution_count": 28,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import sqlalchemy as sa\n",
"from cvxpy import *\n",
"from cvxopt import *\n",
"from alphamind.data.neutralize import neutralize\n",
"from alphamind.data.winsorize import winsorize_normal\n",
"from alphamind.data.standardize import standardize\n",
"\n",
"#engine = sa.create_engine('mysql+mysqldb://sa:We051253524522@rm-bp1psdz5615icqc0yo.mysql.rds.aliyuncs.com/uqer?charset=utf8')\n",
"engine = sa.create_engine('mssql+pymssql://licheng:A12345678!@10.63.6.220/alpha')"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"codes_list = [ \"1\",\"2\",\"4\",\"5\",\"6\",\"7\",\"8\",\"9\",\"10\",\"11\",\"12\",\"14\",\"16\",\"17\",\"18\",\"19\",\"20\",\"21\",\"22\",\"23\",\"25\",\"26\",\"27\",\"28\",\"29\",\"30\",\"31\",\"32\",\"33\",\"34\",\"35\",\"36\",\"37\",\"38\",\"39\",\"40\",\"42\",\"43\",\"45\",\"46\",\"48\",\"49\",\"50\",\"55\",\"56\",\"58\",\"59\",\"60\",\"61\",\"62\",\"63\",\"65\",\"66\",\"68\",\"69\",\"70\",\"78\",\"88\",\"89\",\"90\",\"96\",\"99\",\"100\",\"150\",\"151\",\"153\",\"155\",\"156\",\"157\",\"158\",\"159\",\"166\",\"301\",\"333\",\"338\",\"400\",\"401\",\"402\",\"403\",\"404\",\"407\",\"408\",\"409\",\"410\",\"411\",\"413\",\"415\",\"416\",\"417\",\"418\",\"419\",\"420\",\"421\",\"422\",\"423\",\"425\",\"426\",\"428\",\"429\",\"430\",\"488\",\"498\",\"501\",\"502\",\"503\",\"504\",\"505\",\"506\",\"507\",\"509\",\"510\",\"511\",\"513\",\"514\",\"516\",\"517\",\"518\",\"519\",\"520\",\"521\",\"523\",\"524\",\"525\",\"526\",\"528\",\"529\",\"530\",\"531\",\"532\",\"533\",\"534\",\"536\",\"537\",\"538\",\"539\",\"540\",\"541\",\"543\",\"544\",\"545\",\"546\",\"547\",\"548\",\"550\",\"551\",\"552\",\"553\",\"554\",\"555\",\"557\",\"558\",\"559\",\"560\",\"561\",\"563\",\"564\",\"565\",\"566\",\"567\",\"568\",\"570\",\"571\",\"572\",\"573\",\"576\",\"581\",\"582\",\"584\",\"585\",\"586\",\"587\",\"589\",\"590\",\"591\",\"592\",\"593\",\"595\",\"596\",\"597\",\"598\",\"599\",\"600\",\"601\",\"603\",\"605\",\"606\",\"607\",\"608\",\"609\",\"610\",\"611\",\"612\",\"613\",\"615\",\"616\",\"617\",\"619\",\"620\",\"622\",\"623\",\"625\",\"626\",\"627\",\"628\",\"629\",\"630\",\"631\",\"632\",\"633\",\"635\",\"636\",\"637\",\"638\",\"639\",\"650\",\"651\",\"652\",\"655\",\"656\",\"657\",\"659\",\"661\",\"662\",\"663\",\"665\",\"666\",\"667\",\"668\",\"669\",\"670\",\"671\",\"672\",\"673\",\"676\",\"677\",\"678\",\"679\",\"680\",\"681\",\"682\",\"683\",\"685\",\"686\",\"687\",\"688\",\"690\",\"691\",\"692\",\"693\",\"695\",\"697\",\"698\",\"700\",\"701\",\"702\",\"703\",\"705\",\"707\",\"708\",\"709\",\"710\",\"711\",\"712\",\"713\",\"715\",\"716\",\"717\",\"718\",\"719\",\"720\",\"721\",\"722\",\"723\",\"725\",\"726\",\"727\",\"728\",\"729\",\"731\",\"732\",\"733\",\"735\",\"736\",\"737\",\"738\",\"739\",\"750\",\"751\",\"752\",\"753\",\"755\",\"756\",\"757\",\"758\",\"759\",\"760\",\"761\",\"762\",\"766\",\"767\",\"768\",\"776\",\"777\",\"778\",\"779\",\"780\",\"782\",\"783\",\"785\",\"786\",\"788\",\"789\",\"790\",\"791\",\"792\",\"793\",\"795\",\"796\",\"797\",\"798\",\"799\",\"800\",\"801\",\"802\",\"803\",\"806\",\"807\",\"809\",\"810\",\"811\",\"812\",\"813\",\"815\",\"816\",\"818\",\"819\",\"820\",\"821\",\"822\",\"823\",\"825\",\"826\",\"828\",\"829\",\"830\",\"831\",\"833\",\"835\",\"836\",\"837\",\"838\",\"839\",\"848\",\"850\",\"851\",\"852\",\"856\",\"858\",\"859\",\"860\",\"861\",\"862\",\"863\",\"868\",\"869\",\"875\",\"876\",\"877\",\"878\",\"880\",\"881\",\"882\",\"883\",\"885\",\"886\",\"887\",\"888\",\"889\",\"890\",\"892\",\"893\",\"895\",\"897\",\"898\",\"899\",\"900\",\"901\",\"902\",\"903\",\"905\",\"906\",\"908\",\"909\",\"910\",\"911\",\"912\",\"913\",\"915\",\"916\",\"917\",\"918\",\"919\",\"920\",\"921\",\"922\",\"923\",\"925\",\"926\",\"927\",\"928\",\"929\",\"930\",\"931\",\"932\",\"933\",\"935\",\"936\",\"937\",\"938\",\"939\",\"948\",\"949\",\"950\",\"951\",\"952\",\"953\",\"955\",\"957\",\"958\",\"959\",\"960\",\"961\",\"962\",\"963\",\"965\",\"966\",\"967\",\"968\",\"969\",\"970\",\"971\",\"972\",\"973\",\"975\",\"976\",\"977\",\"978\",\"979\",\"980\",\"981\",\"982\",\"983\",\"985\",\"987\",\"988\",\"989\",\"990\",\"993\",\"995\",\"996\",\"997\",\"998\",\"999\",\"1696\",\"1896\",\"1979\",\"2001\",\"2002\",\"2003\",\"2004\",\"2005\",\"2006\",\"2007\",\"2008\",\"2009\",\"2010\",\"2011\",\"2012\",\"2013\",\"2014\",\"2015\",\"2016\",\"2017\",\"2018\",\"2019\",\"2020\",\"2021\",\"2022\",\"2023\",\"2024\",\"2025\",\"2026\",\"2027\",\"2028\",\"2029\",\"2030\",\"2031\",\"2032\",\"2033\",\"2034\",\"2035\",\"2036\",\"2037\",\"2038\",\"2039\",\"2040\",\"2041\",\"2042\",\"2043\",\"2044\",\"2045\",\"2046\",\"2047\",\"2048\",\"2049\",\"2050\",\"2051\",\"2052\",\"2053\",\"2054\",\"2055\",\"2056\",\"2057\",\"2058\",\"2059\",\"2060\",\"2061\",\"2062\",\"2063\",\"2064\",\"2065\",\"2066\",\"2067\",\"2068\",\"2069\",\"2070\",\"2071\",\"2072\",\"2073\",\"2074\",\"2075\",\"2076\",\"2077\",\"2078\",\"2079\",\"2080\",\"2081\",\"2082\",\"2083\",\"2084\",\"2085\",\"2086\",\"2087\",\"2088\",\"2089\",\"2090\",\"2091\",\"2092\",\"2093\",\"2094\",\"2095\",\"2096\",\"2097\",\"2098\",\"2099\",\"2100\",\"2101\",\"2102\",\"2103\",\"2104\",\"2105\",\"2106\",\"2107\",\"2108\",\"2109\",\"2110\",\"2111\",\"2112\",\"2113\",\"2114\",\"2115\" ]\n",
"factor_list = [\"DebtEquityRatio\",\"EBITToTOR\"]\n",
"ref_date = '2017-05-23'\n",
"weights = np.array([0.3,0.7])\n",
"risk_penlty = 0.5"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Data Preparing\n",
"--------------------------"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"codes = ','.join(codes_list)\n",
"factors = ','.join(factor_list)"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Wall time: 66.6 ms\n"
]
}
],
"source": [
"%%time\n",
"\n",
"# risk_exposure_data = pd.read_sql(\"select * from risk_exposure where Date = '{0}'\".format(ref_date), engine).sort_values('Code')\n",
"# risk_exposure_data.drop(['Date', 'exchangeCD', 'secShortName'], axis=1, inplace=True)\n",
"# risk_exposure_data.dropna(inplace=True)\n",
"# codes_list = risk_exposure_data.Code.astype(str).tolist()\n",
"# codes = ','.join(codes_list)\n",
"\n",
"factor_data = pd.read_sql(\"select Code, {1} from uqer where Date = '{0}' and Code in ({2})\".format(ref_date, factors, codes), engine).sort_values('Code')\n",
"\n",
"risk_exposure_data = pd.read_sql(\"select * from risk_exposure where Date = '{0}' and Code in ({1})\".format(ref_date, codes), engine).sort_values('Code')\n",
"risk_exposure_data.drop(['Date', 'exchangeCD', 'secShortName'], axis=1, inplace=True)\n",
"risk_cov_data = pd.read_sql(\"select * from risk_cov_day where Date = '{0}'\".format(ref_date), engine).sort_values('FactorID')\n",
"risk_cov_data.drop(['Date', 'FactorID'], axis=1, inplace=True)\n",
"risk_cov_data.set_index('Factor', inplace=True)\n",
"specific_risk = pd.read_sql(\"select Code, SRISK from specific_risk_day where Date = '{0}' and Code in ({1})\".format(ref_date, codes), engine).sort_values('Code')"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"n = len(codes_list)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Wall time: 2 ms\n"
]
}
],
"source": [
"%%time\n",
"factor_values = factor_data[factor_list].values\n",
"risk_factor_columns = sorted(risk_cov_data.columns[:38])\n",
"risk_exposure_values = risk_exposure_data[risk_factor_columns].values"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Wall time: 113 ms\n"
]
}
],
"source": [
"%%time\n",
"ne_factor_values = neutralize(risk_exposure_values, standardize(winsorize_normal(factor_values)))\n",
"signal_full = ne_factor_values @ weights / 5"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(581, 38)"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"risk_exposure_values.shape"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Wall time: 8 ms\n"
]
}
],
"source": [
"%%time\n",
"risk_cov_values = risk_cov_data.loc[risk_factor_columns, risk_factor_columns].astype(float) \n",
"sec_cov_values_full = (risk_exposure_values @ risk_cov_values @ risk_exposure_values.T + np.diag(specific_risk.SRISK.values ** 2)) / 10000."
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"n = 200\n",
"\n",
"sec_cov_values = sec_cov_values_full[:n, :n]\n",
"signal = signal_full[:n]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Optimizing Weights\n",
"-------------------------------------"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"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": [
"%%time\n",
"w = Variable(n)\n",
"\n",
"lbound = 0.\n",
"ubound = 1. / n * 20\n",
"\n",
"objective = Minimize(risk_penlty * quad_form(w, sec_cov_values) - signal * w)\n",
"constraints = [w >= lbound,\n",
" w <= ubound,\n",
" sum_entries(w) == 1,]\n",
"\n",
"prob = Problem(objective, constraints)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"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": [
"%%time\n",
"prob.solve(verbose=True)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"('optimal', -0.14330450116208024)"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"prob.status, prob.value"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"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": [
"%%time\n",
"prob.solve(verbose=True, solver='CVXOPT')"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"('optimal', -0.14330451119270352)"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"prob.status, prob.value"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"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": [
"%%time\n",
"P = matrix(sec_cov_values)\n",
"q = -matrix(signal)\n",
"\n",
"G = np.zeros((2*n, n))\n",
"h = np.zeros(2*n)\n",
"for i in range(n):\n",
" G[i, i] = 1.\n",
" h[i] = 1. / n * 20\n",
" G[i+n, i] = -1.\n",
" h[i+n] = 0.\n",
" \n",
"G = matrix(G)\n",
"h = matrix(h)\n",
" \n",
"A = np.ones((1, n))\n",
"b = np.ones(1)\n",
"\n",
"A = matrix(A)\n",
"b = matrix(b)\n",
"\n",
"sol = solvers.qp(P, q, G, h, A, b)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Performace Timing\n",
"-------------------------"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import datetime as dt"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def time_function(py_callable, n):\n",
" start = dt.datetime.now()\n",
" py_callable(n)\n",
" return (dt.datetime.now() - start).total_seconds()"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def cvxpy(n):\n",
" w = Variable(n)\n",
"\n",
" lbound = 0.\n",
" ubound = 0.01\n",
"\n",
" objective = Minimize(risk_penlty * quad_form(w, sec_cov_values) - signal * w)\n",
" constraints = [w >= lbound,\n",
" w <= ubound,\n",
" sum_entries(w) == 1,]\n",
"\n",
" prob = Problem(objective, constraints)\n",
" prob.solve(verbose=False, solver='CVXOPT', display=False)\n",
" #print('cvxpy({0}): '.format(n), prob.value)"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def cvxopt(n):\n",
" P = matrix(sec_cov_values)\n",
" q = -matrix(signal)\n",
"\n",
" G = np.zeros((2*n, n))\n",
" h = np.zeros(2*n)\n",
" for i in range(n):\n",
" G[i, i] = 1.\n",
" h[i] = 0.01\n",
" G[i+n, i] = -1.\n",
" h[i+n] = 0.\n",
"\n",
" G = matrix(G)\n",
" h = matrix(h)\n",
"\n",
" A = np.ones((1, n))\n",
" b = np.ones(1)\n",
"\n",
" A = matrix(A)\n",
" b = matrix(b)\n",
" \n",
" solvers.options['show_progress'] = False\n",
" sol = solvers.qp(P, q, G, h, A, b)\n",
" #print('cvxopt({0}): '.format(n), sol['dual objective'])"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"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": [
"n_steps = list(range(200, 3001, 200))\n",
"cvxpy_times = [None] * len(n_steps)\n",
"cvxopt_times = [None] * len(n_steps)\n",
"\n",
"print(\"{0:<8}{1:>12}{2:>12}\".format('Scale(n)', 'cvxpy', 'cvxopt'))\n",
"\n",
"for i, n in enumerate(n_steps):\n",
" sec_cov_values = sec_cov_values_full[:n, :n]\n",
" signal = signal_full[:n]\n",
" cvxpy_times[i] = time_function(cvxpy, n) * 1000\n",
" cvxopt_times[i] = time_function(cvxopt, n) * 1000\n",
" \n",
" print(\"{0:<8}{1:>12.2f}{2:>12.2f}\".format(n, cvxpy_times[i], cvxopt_times[i]))"
]
},
{
"cell_type": "code",
"execution_count": 30,
"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",
" </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": [
"df = pd.DataFrame({'cvxpy': cvxpy_times,\n",
" 'cvxopt': cvxopt_times},\n",
" index=n_steps)\n",
"df.index.name = 'Problem Scale (n)'\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"df['ipopt'] = ipopt_times"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"risk_penlty"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"np.array(sol['x']).flatten()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"np.linalg.det(sec_cov_values_full)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"sec_cov_values_full.diagonal().mean()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"np.linalg.svd(sec_cov_values_full)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"np.savetxt(\"sec_cov_values_sqlserver.csv\", sec_cov_values_full, delimiter=\",\")"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"np.savetxt(\"signal_sqlserver.csv\", signal_full, delimiter=\",\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"sol['dual objective']"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"np.savetxt(\"factor_data_sqlserver.csv\", factor_data.values, delimiter=\",\")"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 8.12683254e-16, -6.65975686e-02, -1.28129893e-02,\n",
" 3.39443807e-02, 1.37508611e-01, 6.79932784e-01,\n",
" 5.73968448e-02, 1.63259416e-02, 5.10522501e-02,\n",
" 4.71701940e-02, 4.46583770e-03, -3.27754312e-02,\n",
" 7.22843760e-02, -1.97246616e-02, 1.98407659e-02,\n",
" 1.68488882e-01, -1.45745488e-01, -1.39566019e-02,\n",
" -1.79127900e-02, -3.68258990e-03, -4.82757334e-02,\n",
" 1.49072018e-02, -1.13283270e-02, -1.19819860e-01,\n",
" -3.32749056e-02, -3.77998277e-02, 3.82986952e-02,\n",
" -6.17955347e-02, 4.02263704e-04, -2.63129448e-02,\n",
" -1.24579426e-02, 1.43607890e-01, 3.71685473e-01,\n",
" 4.10883344e-02, -2.59507503e-02, -3.80253673e-02,\n",
" -1.22340476e-03, 3.66129020e-02, -3.96080512e-02,\n",
" 9.26881083e-02, -1.00456932e-01, -6.81170452e-02,\n",
" 2.57356484e-02, -2.07050201e-02, 3.27495346e-01,\n",
" 4.44225698e-02, -2.92201457e-02, -3.40106787e-02,\n",
" 7.43789973e-02, -5.26983454e-02, -6.96179386e-02,\n",
" -4.61845288e-02, -6.78248238e-02, -5.04111723e-02,\n",
" -6.53359936e-05, -3.57769351e-02, -4.36965683e-02,\n",
" 6.53482678e-01, -1.15188084e-01, 2.33641703e-02,\n",
" 1.33023449e-01, -1.11824363e-01, 2.85460131e-02,\n",
" -1.74994148e-02, -2.68958448e-02, -4.22228841e-02,\n",
" 1.11670649e-01, -1.15538433e-01, 1.04612734e-02,\n",
" -4.53836952e-02, 1.26837912e-01, -1.98392634e-02,\n",
" 3.18095858e-02, -2.24450408e-02, -3.54109804e-02,\n",
" 6.89997014e-02, -6.20174689e-03, 7.50724854e-02,\n",
" -4.78114588e-03, 9.57241127e-02, -9.57950094e-02,\n",
" 6.89890588e-02, -1.13277757e-02, 4.89191718e-01,\n",
" 5.29549721e-03, 9.78059370e-02, -7.37939318e-02,\n",
" 4.28509845e-02, -5.42827048e-02, -2.63583599e-02,\n",
" -1.25037905e-02, 8.59397672e-03, -5.68375037e-02,\n",
" 1.41084733e-02, 2.90880287e-02, -1.69263283e-03,\n",
" 8.81050922e-02, -1.53358939e-01, 8.44836443e-02,\n",
" 1.31341935e-02, 9.68621799e-03, -5.75536515e-03,\n",
" -1.09847651e-01, 1.53221571e-02, -4.17245293e-02,\n",
" 7.82533058e-01, 8.43620415e-02, -6.36230800e-02,\n",
" -1.28980957e-01, -2.34259553e-01, -2.05538657e-02,\n",
" -5.83637017e-02, -6.18424063e-02, 1.13654071e-01,\n",
" -7.74295780e-02, -3.12192080e-02, -5.64188476e-02,\n",
" -1.53388400e-02, -1.91766256e-01, 8.37594120e-02,\n",
" 4.94395237e-03, -3.83384644e-02, -1.71540023e-02,\n",
" 5.33141102e-01, 8.48697534e-03, -4.25195975e-02,\n",
" 2.21698335e-03, 1.54956798e-02, 1.15980750e-01,\n",
" -8.06781431e-03, 3.48056409e-01, 1.09177393e-01,\n",
" 6.67584894e-02, -8.30734686e-02, -8.07600141e-02,\n",
" -1.73916635e-02, 1.21360837e-01, -8.26216517e-02,\n",
" 1.26690094e-02, 4.75760976e-02, 5.25067885e-02,\n",
" 4.48270146e-02, 5.01756715e-02, -8.35274975e-02,\n",
" 2.81365125e-02, 5.30906238e-02, -1.00407664e-01,\n",
" -5.98952994e-03, -8.42100281e-04, 3.37615154e-03,\n",
" -5.79703528e-02, -2.58105990e-02, -6.11600190e-02,\n",
" 1.60126323e-02, 1.29071580e-01, -5.80425683e-02,\n",
" 1.72966653e-02, 2.97227272e-02, 1.41930788e-01,\n",
" 3.71977256e-02, -1.11658606e-02, -1.79051340e-02,\n",
" 4.04232715e-03, 9.56732025e-02, 8.33311932e-02,\n",
" 4.67617575e-02, -8.82501900e-02, -3.47585002e-01,\n",
" -7.76268259e-01, -6.42512137e-02, 8.27352504e-04,\n",
" 6.70967229e-02, 3.38880065e-02, 2.40820458e-01,\n",
" 1.01326530e-03, -4.96943952e-02, -1.36383357e-01,\n",
" -5.42479974e-03, -8.32308779e-02, 7.51000781e-03,\n",
" 6.35639956e-02, -3.34739783e-02, -4.54842381e-02,\n",
" 2.78006962e-01, -7.71754464e-02, -2.79404472e-02,\n",
" 9.87990273e-03, -1.57833494e-01, 2.19870851e-01,\n",
" -2.31001676e-02, 1.41472173e-01, -2.17081958e-02,\n",
" -2.28809596e-01, -8.76789169e-02, -8.17684929e-01,\n",
" 2.42798629e-01, 7.47318643e-02, 2.48698481e-02,\n",
" 5.72717704e-01, 2.99426784e-01, -5.55880021e-02,\n",
" -4.79222518e-02, 1.63373687e-02, 3.67073759e-02,\n",
" -3.23576249e-01, -4.77801019e-02, -1.32217293e-02,\n",
" 4.27695734e-02, 3.03490341e-01, -1.23108561e-02,\n",
" 2.96806350e-02, 8.78971177e-03, 4.51999596e-02,\n",
" -2.34322230e-02, -1.44478278e-02, 1.37596601e-02,\n",
" 8.25342310e-02, -2.96790906e-01, -6.59564224e-02,\n",
" -4.04793534e-03, -1.35339356e-01, 2.41096249e-02,\n",
" 1.08676261e-01, 9.18781634e-02, -1.38198926e-01,\n",
" -7.28101645e-02, 3.92216055e-02, -8.24992924e-01,\n",
" 1.49007724e-03, -4.16514051e-02, 1.15926416e-01,\n",
" -4.76235077e-03, -1.41219804e-01, -2.90378388e-02,\n",
" -2.42639642e-02, -8.55210801e-03, 6.77035575e-03,\n",
" -1.34103029e-03, -1.00477676e-02, 8.73613052e-02,\n",
" -6.00179374e-03, 2.56784280e-01, -4.66838635e-02,\n",
" 3.93420442e-02, 8.15923944e-02, -3.11645717e-02,\n",
" 1.66202218e-02, -8.81102123e-02, -1.39332657e-01,\n",
" -6.03640801e-02, -8.79410604e-01, 2.06815766e-02,\n",
" 3.66844566e-03, 4.47238518e-02, -2.77374717e-02,\n",
" -6.11142748e-02, 1.74595815e-03, 2.77050186e-02,\n",
" -1.13694418e-02, 2.72841602e-02, -1.40978068e-01,\n",
" -1.57233223e-01, -2.06674198e-03, 5.82804013e-02,\n",
" -6.57407968e-03, -7.36170942e-02, 1.35169246e-01,\n",
" -1.19710839e-02, -1.85914679e-01, -8.93226441e-02,\n",
" -2.39616214e-02, 2.15716137e-01, -7.91451571e-03,\n",
" -5.69136184e-02, -3.50976961e-02, -5.39278265e-02,\n",
" 7.32658101e-02, -1.57668257e-02, -7.72695199e-03,\n",
" -1.32203299e-02, 1.23500619e-02, 7.36572612e-02,\n",
" 1.13053202e-01, 1.94280042e-01, 9.79947615e-04,\n",
" -5.07344023e-02, -2.17626964e-02, -4.36211962e-02,\n",
" 4.64549689e-02, 4.69176577e-02, 9.08537410e-03,\n",
" -4.36537939e-02, 2.07709870e-02, 1.07647953e-02,\n",
" -5.71942227e-02, 5.41470978e-02, -1.81389200e-02,\n",
" 5.69755372e-02, 1.59985421e-02, -1.32375743e-02,\n",
" -3.32077328e-02, 1.90335650e-02, -2.20813229e-02,\n",
" 7.53590093e-03, 6.43058524e-02, -4.39685888e-03,\n",
" -4.02146488e-02, 1.55857059e-02, -7.92150152e-03,\n",
" 2.57381164e-02, -5.62883548e-02, 4.15137221e-02,\n",
" 3.84109990e-02, 9.17085919e-02, 1.01163612e-01,\n",
" -1.12174142e-01, -8.36051893e-04, -1.37412601e-01,\n",
" 1.27938417e-02, 3.44972162e-02, 6.61313074e-02,\n",
" -7.43145883e-02, 8.47096640e-02, 2.06270121e-01,\n",
" -4.14736088e-01, 2.06441787e-02, -1.68413436e-02,\n",
" -7.63533086e-01, -5.86456009e-02, -9.74391261e-03,\n",
" 3.75743967e-02, 1.57313394e-01, -8.28972365e-03,\n",
" -1.26235878e-01, -5.04025043e-02, -1.66902731e-02,\n",
" 1.18280575e-01, -3.48840984e-02, -5.86908750e-02,\n",
" -1.12152539e-02, -3.20797721e-02, -8.64774331e-02,\n",
" 1.84965491e-01, -1.89501025e-02, -2.90483136e-02,\n",
" 8.46917987e-02, 4.60857238e-03, -3.61792267e-02,\n",
" -5.22326470e-02, -4.79564871e-03, -4.02183725e-02,\n",
" 4.08165076e-03, 5.78296986e-02, 3.30969695e-02,\n",
" 3.71689772e-02, -1.71557787e-01, -1.11867475e-01,\n",
" 7.35934622e-02, 1.50820731e-02, -1.10233673e-02,\n",
" 5.73279142e-02, 2.88999742e-02, -1.11713510e-02,\n",
" 4.79721744e-02, 6.69148556e-02, -1.86641305e-02,\n",
" -5.13639173e-02, 2.60222710e-02, -3.91555038e-02,\n",
" -1.55104126e-02, -3.66263518e-02, 1.89705511e-01,\n",
" -4.45483447e-02, 2.86804778e-02, 7.98608063e-02,\n",
" -3.15531839e-02, -2.76398937e-02, 1.98213948e-03,\n",
" 9.69480126e-02, 1.13704150e-01, -5.44630738e-02,\n",
" -1.04563573e-01, 1.09779268e-02, -2.79846220e-02,\n",
" -4.28951764e-02, -1.88756154e-01, -4.40106134e-02,\n",
" -1.53504183e-02, 5.20412183e-03, -1.87469460e-01,\n",
" 1.91318195e-02, 2.45197648e-02, -1.38550940e-02,\n",
" -7.28075143e-02, 4.47687047e-03, 4.88329302e-01,\n",
" -1.78328854e-02, 4.94087778e-02, 2.89865695e-02,\n",
" -8.22126093e-02, 4.24560188e-01, -3.80360571e-02,\n",
" -4.07051777e-02, -3.86293780e-02, -9.80215226e-02,\n",
" -4.37703369e-02, -1.09341638e-01, 4.90217015e-02,\n",
" 2.26432350e-03, -1.30583016e-02, 2.44170591e-02,\n",
" -1.81332754e-02, -4.66718448e-02, -2.39955860e-02,\n",
" -1.43469942e-02, -4.58784904e-02, 1.64453394e-01,\n",
" 8.54574456e-02, -4.93999322e-02, -6.72957407e-03,\n",
" 3.26896560e-02, 9.80857923e-03, -1.56019964e-01,\n",
" 4.79049796e-03, 7.27166032e-02, -3.88105853e-01,\n",
" 3.75553309e-03, -4.55136222e-02, -7.40687305e-02,\n",
" 1.44700916e-02, -3.72466726e-02, 2.73590247e-02,\n",
" 1.40718443e-01, -1.20750481e-01, 1.32368465e-01,\n",
" -7.90328388e-02, 6.91591884e-02, 1.81612703e-01,\n",
" 1.33132183e-02, 1.83178389e-02, 5.04316043e-02,\n",
" -1.85895500e-01, 4.01562103e-02, 1.55542723e-01,\n",
" -4.44926068e-02, -6.14340946e-02, -5.34716736e-02,\n",
" -4.47074496e-02, -1.09953475e-01, 1.58439670e-02,\n",
" -1.43626215e-01, 5.66078336e-02, -1.34523694e-04,\n",
" 9.11379886e-02, -2.00712771e-02, 2.31234518e-02,\n",
" 4.39705595e-02, 6.23294580e-03, -3.34008451e-01,\n",
" 7.51475273e-02, -1.62766816e-02, 6.17115150e-02,\n",
" -4.20589062e-02, 1.03162598e-02, -4.09440933e-02,\n",
" 2.72697113e-02, 6.26448163e-02, 1.99724609e-02,\n",
" -3.72830174e-02, 2.59653871e-02, 4.17150986e-02,\n",
" 1.79309338e-02, 1.04684474e-01, -4.10596016e-02,\n",
" 2.17147803e-02, -3.30579721e-02, 1.23981306e-01,\n",
" -4.72447376e-02, -2.73832625e-02, 7.93599676e-03,\n",
" -1.75565346e-01, -5.20879084e-03, 1.60830991e-02,\n",
" -5.85592245e-02, 2.65932684e-02, -1.87679629e-02,\n",
" -7.55003990e-02, 1.32831661e-02, 5.96110477e-02,\n",
" -5.93862848e-02, -2.80348415e-03, 8.68168816e-03,\n",
" 1.33779120e-01, 4.66782056e-02, 1.93152217e-02,\n",
" 3.44939435e-03, 3.46230307e-02, -2.57591807e-02,\n",
" 8.53029673e-02, -1.20312691e-01, -1.49691768e-02,\n",
" -4.73918118e-02, 8.20576187e-02, 1.82364019e-01,\n",
" 1.08211508e-01, 2.80542000e-02, 1.23508428e-01,\n",
" -5.59219426e-02, -5.06433770e-02, -5.12859160e-02,\n",
" -7.23309320e-02, 6.42195709e-02, -2.38411593e-03,\n",
" -6.14406959e-02, 2.26060862e-02, 3.14823611e-02,\n",
" 1.14303504e-02, -3.98017955e-01, 3.27112250e-02,\n",
" -1.91888119e-02, 4.48251075e-04, -3.58195830e-02,\n",
" 6.05167192e-02, 5.16925765e-02, -8.15079013e-02,\n",
" 5.99044732e-02, -3.80609425e-02, -1.50919054e-02,\n",
" 3.35160893e-02, -9.49373939e-02, 9.74936874e-03,\n",
" 9.28798242e-02, 2.27303122e-02, 1.79827433e-02,\n",
" 1.03069681e-02, 2.60655782e-03, 9.38127175e-02,\n",
" 4.36536284e-01, -1.77327346e-01, 1.21666176e-01,\n",
" -3.34637547e-02, -1.91385657e-02, -1.30247098e-02,\n",
" -4.22722793e-02, 2.55006640e-02, 5.09101967e-03,\n",
" -3.90486027e-02, -4.85443505e-02, -3.51819193e-02,\n",
" 1.06052324e-02, -9.01475647e-02, 4.74820575e-02,\n",
" -1.29657473e-02, 4.74335562e-02, 6.72075743e-04,\n",
" 9.30396533e-02, -9.80561940e-02, -5.34761284e-04,\n",
" 1.84546437e-02, -4.91005708e-02, -2.03496819e-01,\n",
" 3.09450920e-02, 3.99958848e-02, -1.51978938e-02,\n",
" -1.22142775e-02, -1.90168086e-02, -3.08715708e-02,\n",
" 8.83456421e-03, -5.80801511e-02, 4.44158930e-02,\n",
" 2.25741830e-02, 8.70872927e-03, -4.11430460e-02,\n",
" 4.95398509e-02, 1.04895895e-02, -5.65591215e-02,\n",
" 1.95155979e-02, 7.42283374e-02, 5.47088113e-02,\n",
" 8.94284264e-03, 1.42841454e-02])"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"signal_full"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
......@@ -3,7 +3,7 @@ cvxpy >= 0.4.9
cython >= 0.25.2
mysqlclient >= 1.3.10
numpy >= 1.12.1
numba >= 0.34.0
numba >= 0.33.0
scikit-learn >= 0.18.1
scipy >= 0.19.0
simpleutils >= 0.1.0
......
......@@ -43,7 +43,7 @@ else:
"./libs/include/pfopt",
"./libs/include/eigen",
"./libs/include/alglib"],
libraries=['pfopt', 'alglib', 'libClp', 'libCoinUtils'],
libraries=['pfopt', 'alglib', 'libClp', 'libCoinUtils', 'IpOptFSS', 'Ipopt-vc8'],
library_dirs=['./libs/lib/windows']),
]
......
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