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
a1d74db0
Commit
a1d74db0
authored
Jul 30, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update to new interface
parent
6e29c702
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
83 additions
and
99 deletions
+83
-99
optimizers.pyx
alphamind/cython/optimizers.pyx
+42
-28
lpoptimizer.hpp
libs/include/pfopt/lpoptimizer.hpp
+8
-6
meanvariance.hpp
libs/include/pfopt/meanvariance.hpp
+12
-13
mvoptimizer.hpp
libs/include/pfopt/mvoptimizer.hpp
+13
-9
qpalglib.hpp
libs/include/pfopt/qpalglib.hpp
+1
-1
types.hpp
libs/include/pfopt/types.hpp
+0
-36
utilities.hpp
libs/include/pfopt/utilities.hpp
+5
-5
libpfopt.so
libs/lib/linux/libpfopt.so
+0
-0
setup.py
setup.py
+2
-1
No files found.
alphamind/cython/optimizers.pyx
View file @
a1d74db0
...
...
@@ -13,7 +13,7 @@ from libcpp.vector cimport vector
cdef extern from "lpoptimizer.hpp" namespace "pfopt":
cdef cppclass LpOptimizer:
LpOptimizer(
vector[double], vector[double], vector[double], vector[double]
) except +
LpOptimizer(
int, int, double*, double*, double*, double*
) except +
vector[double] xValue()
double feval()
int status()
...
...
@@ -25,14 +25,19 @@ cdef class LPOptimizer:
def __init__(self,
cnp.ndarray[double, ndim=2] cons_matrix,
cnp.ndarray[double] lbound,
cnp.ndarray[double] ubound,
cnp.ndarray[double] objective):
self.cobj = new LpOptimizer(cons_matrix.flatten(order='C'),
lbound,
ubound,
objective)
double[:] lbound,
double[:] ubound,
double[:] objective):
cdef int n = lbound.shape[0]
cdef int m = cons_matrix.shape[0]
cdef double[:] cons = cons_matrix.flatten(order='C');
self.cobj = new LpOptimizer(n,
m,
&cons[0],
&lbound[0],
&ubound[0],
&objective[0])
def __del__(self):
del self.cobj
...
...
@@ -49,13 +54,15 @@ cdef class LPOptimizer:
cdef extern from "mvoptimizer.hpp" namespace "pfopt":
cdef cppclass MVOptimizer:
MVOptimizer(vector[double],
vector[double],
vector[double],
vector[double],
vector[double],
vector[double],
vector[double],
MVOptimizer(int,
double*,
double*,
double*,
double*,
int,
double*,
double*,
double*,
double) except +
vector[double] xValue()
double feval()
...
...
@@ -67,22 +74,29 @@ cdef class QPOptimizer:
cdef MVOptimizer* cobj
def __init__(self,
cnp.ndarray[double
] expected_return,
double[:
] expected_return,
cnp.ndarray[double, ndim=2] cov_matrix,
cnp.ndarray[double
] lbound,
cnp.ndarray[double
] ubound,
double[:
] lbound,
double[:
] ubound,
cnp.ndarray[double, ndim=2] cons_matrix,
cnp.ndarray[double
] clbound,
cnp.ndarray[double
] cubound,
double[:
] clbound,
double[:
] cubound,
double risk_aversion=1.0):
self.cobj = new MVOptimizer(expected_return,
cov_matrix.flatten(order='C'),
lbound,
ubound,
cons_matrix.flatten(order='C'),
clbound,
cubound,
cdef int n = lbound.shape[0]
cdef int m = cons_matrix.shape[0]
cdef double[:] cov = cov_matrix.flatten(order='C')
cdef double[:] cons = cons_matrix.flatten(order='C');
self.cobj = new MVOptimizer(n,
&expected_return[0],
&cov[0],
&lbound[0],
&ubound[0],
m,
&cons[0],
&clbound[0],
&cubound[0],
risk_aversion)
def __del__(self):
...
...
libs/include/pfopt/lpoptimizer.hpp
View file @
a1d74db0
...
...
@@ -7,12 +7,14 @@
namespace
pfopt
{
class
PFOPT_CLASS
LpOptimizer
{
class
LpOptimizer
{
public
:
LpOptimizer
(
const
std
::
vector
<
double
>&
constraintsMatraix
,
const
std
::
vector
<
double
>&
lowerBound
,
const
std
::
vector
<
double
>&
upperBound
,
const
std
::
vector
<
double
>&
objective
);
LpOptimizer
(
int
numVariables
,
int
numCons
,
double
*
constraintMatrix
,
double
*
lowerBound
,
double
*
upperBound
,
double
*
objective
);
std
::
vector
<
double
>
xValue
()
const
;
double
feval
()
const
;
...
...
@@ -20,7 +22,7 @@ namespace pfopt {
private
:
ClpSimplex
model_
;
in
t
numberOfProb_
;
size_
t
numberOfProb_
;
};
}
...
...
libs/include/pfopt/meanvariance.hpp
View file @
a1d74db0
...
...
@@ -14,15 +14,16 @@ using Ipopt::IpoptCalculatedQuantities;
namespace
pfopt
{
class
PFOPT_CLASS
MeanVariance
:
public
TNLP
{
class
MeanVariance
:
public
TNLP
{
public
:
MeanVariance
(
const
std
::
vector
<
double
>
&
expectReturn
,
const
std
::
vector
<
double
>
&
varMatrix
,
MeanVariance
(
int
numAssets
,
double
*
expectReturn
,
double
*
varMatrix
,
double
riskAversion
=
1.
);
bool
setBoundedConstraint
(
const
std
::
vector
<
double
>&
lb
,
const
std
::
vector
<
double
>&
ub
);
bool
setLinearConstrains
(
const
std
::
vector
<
double
>&
consMatrix
,
const
std
::
vector
<
double
>&
clb
,
const
std
::
vector
<
double
>&
cub
);
bool
setBoundedConstraint
(
const
double
*
lb
,
const
double
*
ub
);
bool
setLinearConstrains
(
int
numCons
,
const
double
*
consMatrix
,
const
double
*
clb
,
const
double
*
cub
);
virtual
bool
get_nlp_info
(
Index
&
n
,
Index
&
m
,
Index
&
nnz_jac_g
,
Index
&
nnz_h_lag
,
IndexStyleEnum
&
index_style
);
...
...
@@ -58,22 +59,20 @@ namespace pfopt {
private
:
VectorXd
expectReturn_
;
MatrixXd
varMatrix_
;
int
numOfAssets_
;
const
int
numOfAssets_
;
VectorXd
xReal_
;
double
riskAversion_
;
const
double
riskAversion_
;
std
::
vector
<
double
>
lb_
;
std
::
vector
<
double
>
ub_
;
const
double
*
lb_
;
const
double
*
ub_
;
VectorXd
grad_f_
;
double
feval_
;
std
::
vector
<
double
>
x_
;
std
::
vector
<
Index
>
iRow_
;
std
::
vector
<
Index
>
jCol_
;
std
::
vector
<
double
>
g_grad_values_
;
std
::
vector
<
double
>
consMatrix_
;
std
::
vector
<
double
>
clb_
;
std
::
vector
<
double
>
cub_
;
const
double
*
clb_
;
const
double
*
cub_
;
Index
m_
;
};
}
...
...
libs/include/pfopt/mvoptimizer.hpp
View file @
a1d74db0
...
...
@@ -5,19 +5,23 @@
#include <coin/IpIpoptApplication.hpp>
namespace
pfopt
{
class
PFOPT_CLASS
MVOptimizer
{
class
MVOptimizer
{
public
:
MVOptimizer
(
const
std
::
vector
<
double
>
&
expectReturn
,
const
std
::
vector
<
double
>
&
varMatrix
,
const
std
::
vector
<
double
>
&
lbound
,
const
std
::
vector
<
double
>
&
ubound
,
const
std
::
vector
<
double
>
&
consMatrix
=
std
::
vector
<
double
>
(),
const
std
::
vector
<
double
>
&
clb
=
std
::
vector
<
double
>
(),
const
std
::
vector
<
double
>
&
cub
=
std
::
vector
<
double
>
(),
double
riskAversion
=
1.
);
MVOptimizer
(
int
numAssets
,
double
*
expectReturn
,
double
*
varMatrix
,
double
*
lbound
,
double
*
ubound
,
int
numConstraints
,
double
*
consMatrix
=
nullptr
,
double
*
clb
=
nullptr
,
double
*
cub
=
nullptr
,
double
riskAversion
=
1.
);
std
::
vector
<
double
>
xValue
()
const
{
return
mvImpl_
->
xValue
();
}
double
feval
()
const
{
return
mvImpl_
->
feval
();
}
int
status
()
const
{
return
status_
;
}
private
:
...
...
libs/include/pfopt/qpalglib.hpp
View file @
a1d74db0
...
...
@@ -8,7 +8,7 @@ using namespace alglib;
namespace
pfopt
{
class
PFOPT_CLASS
AlglibData
{
class
AlglibData
{
public
:
AlglibData
(
const
std
::
vector
<
double
>
&
expectReturn
,
const
std
::
vector
<
double
>
&
varMatrix
,
...
...
libs/include/pfopt/types.hpp
View file @
a1d74db0
...
...
@@ -10,40 +10,4 @@ using Eigen::Map;
using
alglib
::
real_1d_array
;
using
alglib
::
real_2d_array
;
#ifdef WIN32
#ifdef __cplusplus
#define DLL_EXPORT_C_DECL extern "C" __declspec(dllexport)
#define DLL_IMPORT_C_DECL extern "C" __declspec(dllimport)
#define DLL_EXPORT_DECL extern __declspec(dllexport)
#define DLL_IMPORT_DECL extern __declspec(dllimport)
#define DLL_EXPORT_CLASS_DECL __declspec(dllexport)
#define DLL_IMPORT_CLASS_DECL __declspec(dllimport)
#else
#define DLL_EXPORT_DECL __declspec(dllexport)
#define DLL_IMPORT_DECL __declspec(dllimport)
#endif
#else
#ifdef __cplusplus
#define DLL_EXPORT_C_DECL extern "C"
#define DLL_IMPORT_C_DECL extern "C"
#define DLL_EXPORT_DECL extern
#define DLL_IMPORT_DECL extern
#define DLL_EXPORT_CLASS_DECL
#define DLL_IMPORT_CLASS_DECL
#else
#define DLL_EXPORT_DECL extern
#define DLL_IMPORT_DECL extern
#endif
#endif
#ifdef PFOPF_EXPORTS
#define PFOPT_CLASS DLL_EXPORT_CLASS_DECL
#define PFOPT_API DLL_EXPORT_DECL
#else
#define PFOPT_CLASS DLL_IMPORT_CLASS_DECL
#define PFOPT_API DLL_IMPORT_DECL
#endif
#endif
libs/include/pfopt/utilities.hpp
View file @
a1d74db0
...
...
@@ -6,14 +6,14 @@
namespace
pfopt
{
namespace
io
{
PFOPT_API
std
::
vector
<
double
>
read_csv
(
const
std
::
string
&
filePath
);
std
::
vector
<
double
>
read_csv
(
const
std
::
string
&
filePath
);
}
PFOPT_API
double
min
(
const
real_1d_array
&
array
,
int
n
=
0
);
PFOPT_API
double
max
(
const
real_1d_array
&
array
,
int
n
=
0
);
PFOPT_API
double
sum
(
const
real_1d_array
&
array
,
int
n
=
0
);
double
min
(
const
real_1d_array
&
array
,
int
n
=
0
);
double
max
(
const
real_1d_array
&
array
,
int
n
=
0
);
double
sum
(
const
real_1d_array
&
array
,
int
n
=
0
);
bool
is_close
(
double
a
,
double
b
,
double
tol
=
1e-9
);
bool
is_close
(
double
a
,
double
b
,
double
tol
=
1e-9
);
}
#endif
\ No newline at end of file
libs/lib/linux/libpfopt.so
View file @
a1d74db0
No preview for this file type
setup.py
View file @
a1d74db0
...
...
@@ -32,7 +32,8 @@ if platform.system() != "Windows":
"./libs/include/eigen"
,
"./libs/include/alglib"
],
libraries
=
[
'pfopt'
],
library_dirs
=
[
'./libs/lib/linux'
]),
library_dirs
=
[
'./libs/lib/linux'
],
extra_compile_args
=
[
'-std=c++11'
]),
]
else
:
extensions
=
[
...
...
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