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
896a96c9
Commit
896a96c9
authored
Aug 13, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
some codes refined
parent
00ab6bb5
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
15 additions
and
19 deletions
+15
-19
linearbuild.py
alphamind/benchmarks/portfolio/linearbuild.py
+8
-9
models.py
alphamind/data/dbmodel/models.py
+1
-1
sqlengine.py
alphamind/data/engines/sqlengine.py
+4
-5
test_riskanalysis.py
alphamind/tests/analysis/test_riskanalysis.py
+1
-0
test_constraints.py
alphamind/tests/portfolio/test_constraints.py
+1
-0
utilities.py
alphamind/utilities.py
+0
-4
No files found.
alphamind/benchmarks/portfolio/linearbuild.py
View file @
896a96c9
...
...
@@ -38,33 +38,32 @@ def benchmark_build_linear(n_samples: int, n_risks: int, n_loop: int) -> None:
ubound
,
risk_exp
,
risk_target
=
(
risk_lbound
,
risk_ubound
),
solver
=
'ECOS'
)
risk_ubound
))
impl_model_time
=
dt
.
datetime
.
now
()
-
start
print
(
'{0:20s}: {1}'
.
format
(
'Implemented model (ECOS)'
,
impl_model_time
))
c
=
-
er
bounds
=
[(
lbound
,
ubound
)
for
_
in
range
(
n_samples
)]
A
_eq
=
np
.
ones
((
1
,
n_samples
))
A_eq
=
np
.
vstack
((
A
_eq
,
risk_exp
.
T
))
a
_eq
=
np
.
ones
((
1
,
n_samples
))
a_eq
=
np
.
vstack
((
a
_eq
,
risk_exp
.
T
))
b_eq
=
np
.
hstack
((
np
.
array
([
1.
]),
risk_exp
.
T
@
bm
))
start
=
dt
.
datetime
.
now
()
for
_
in
range
(
n_loop
):
res
=
linprog
(
c
,
A_eq
=
A
_eq
,
b_eq
=
b_eq
,
bounds
=
bounds
,
options
=
{
'maxiter'
:
10000
})
res
=
linprog
(
c
,
A_eq
=
a
_eq
,
b_eq
=
b_eq
,
bounds
=
bounds
,
options
=
{
'maxiter'
:
10000
})
benchmark_model_time
=
dt
.
datetime
.
now
()
-
start
print
(
'{0:20s}: {1}'
.
format
(
'Benchmark model (scipy)'
,
benchmark_model_time
))
np
.
testing
.
assert_array_almost_equal
(
x
,
res
[
'x'
])
c
=
matrix
(
-
er
)
A
=
matrix
(
A
_eq
)
aneq
=
matrix
(
a
_eq
)
b
=
matrix
(
b_eq
)
G
=
matrix
(
np
.
vstack
((
np
.
diag
(
np
.
ones
(
n_samples
)),
-
np
.
diag
(
np
.
ones
(
n_samples
)))))
g
=
matrix
(
np
.
vstack
((
np
.
diag
(
np
.
ones
(
n_samples
)),
-
np
.
diag
(
np
.
ones
(
n_samples
)))))
h
=
matrix
(
np
.
hstack
((
ubound
*
np
.
ones
(
n_samples
),
-
lbound
*
np
.
ones
(
n_samples
))))
solvers
.
lp
(
c
,
G
,
h
,
solver
=
'glpk'
)
solvers
.
lp
(
c
,
g
,
h
,
solver
=
'glpk'
)
start
=
dt
.
datetime
.
now
()
for
_
in
range
(
n_loop
):
res2
=
solvers
.
lp
(
c
,
G
,
h
,
A
,
b
,
solver
=
'glpk'
)
res2
=
solvers
.
lp
(
c
,
g
,
h
,
aneq
,
b
,
solver
=
'glpk'
)
benchmark_model_time
=
dt
.
datetime
.
now
()
-
start
print
(
'{0:20s}: {1}'
.
format
(
'Benchmark model (glpk)'
,
benchmark_model_time
))
np
.
testing
.
assert_array_almost_equal
(
x
,
np
.
array
(
res2
[
'x'
])
.
flatten
())
...
...
alphamind/data/dbmodel/models.py
View file @
896a96c9
...
...
@@ -1073,5 +1073,5 @@ if __name__ == '__main__':
from
sqlalchemy
import
create_engine
engine
=
create_engine
(
'postgresql+psycopg2://
postgres:A12345678!@10.63.6.220
/alpha'
)
engine
=
create_engine
(
'postgresql+psycopg2://
user:pwd@host
/alpha'
)
Base
.
metadata
.
create_all
(
engine
)
alphamind/data/engines/sqlengine.py
View file @
896a96c9
...
...
@@ -80,11 +80,12 @@ class SqlEngine(object):
def
__init__
(
self
,
db_url
:
str
):
self
.
engine
=
sa
.
create_engine
(
db_url
)
self
.
session
=
None
self
.
create_session
()
def
create_session
(
self
):
S
ession
=
orm
.
sessionmaker
(
bind
=
self
.
engine
)
self
.
session
=
S
ession
()
db_s
ession
=
orm
.
sessionmaker
(
bind
=
self
.
engine
)
self
.
session
=
db_s
ession
()
def
fetch_factors_meta
(
self
)
->
pd
.
DataFrame
:
query
=
self
.
session
.
query
(
FactorMaster
)
...
...
@@ -207,9 +208,7 @@ class SqlEngine(object):
if
__name__
==
'__main__'
:
db_url
=
'mssql+pymssql://licheng:A12345678!@10.63.6.220/alpha?charset=cp936'
import
datetime
as
dt
db_url
=
'mssql+pymssql://user:pwd@host/alpha?charset=cp936'
universe
=
Universe
(
'custom'
,
[
'zz500'
])
engine
=
SqlEngine
(
db_url
)
...
...
alphamind/tests/analysis/test_riskanalysis.py
View file @
896a96c9
...
...
@@ -13,6 +13,7 @@ from alphamind.analysis.riskanalysis import risk_analysis
class
TestRiskAnalysis
(
unittest
.
TestCase
):
@
staticmethod
def
test_risk_analysis
(
self
):
n_samples
=
36000
n_dates
=
20
...
...
alphamind/tests/portfolio/test_constraints.py
View file @
896a96c9
...
...
@@ -12,6 +12,7 @@ from alphamind.portfolio.constraints import Constraints
class
TestConstraints
(
unittest
.
TestCase
):
@
staticmethod
def
test_constraints
(
self
):
cons
=
Constraints
()
...
...
alphamind/utilities.py
View file @
896a96c9
...
...
@@ -278,7 +278,3 @@ def aggregate(groups, x, func, ddof=1):
raise
ValueError
(
'({0}) is not recognized as valid functor'
.
format
(
func
))
return
value_data
if
__name__
==
'__main__'
:
pass
\ No newline at end of file
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