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
4182e1a8
Commit
4182e1a8
authored
Sep 22, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added execution module
parent
9f2cbc30
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
121 additions
and
1 deletion
+121
-1
__init__.py
alphamind/execution/__init__.py
+0
-0
baseexecutor.py
alphamind/execution/baseexecutor.py
+20
-0
nativeexecutor.py
alphamind/execution/nativeexecutor.py
+18
-0
thresholdexecutor.py
alphamind/execution/thresholdexecutor.py
+35
-0
__init__.py
alphamind/tests/execution/__init__.py
+0
-0
test_thresholdexecutor.py
alphamind/tests/execution/test_thresholdexecutor.py
+45
-0
test_suite.py
alphamind/tests/test_suite.py
+3
-1
No files found.
alphamind/execution/__init__.py
0 → 100644
View file @
4182e1a8
alphamind/execution/baseexecutor.py
0 → 100644
View file @
4182e1a8
# -*- coding: utf-8 -*-
"""
Created on 2017-9-22
@author: cheng.li
"""
import
abc
import
pandas
as
pd
class
ExecutorBase
(
metaclass
=
abc
.
ABCMeta
):
def
__init__
(
self
):
pass
@
abc
.
abstractmethod
def
execute
(
self
,
target_pos
:
pd
.
DataFrame
)
->
pd
.
DataFrame
:
pass
\ No newline at end of file
alphamind/execution/nativeexecutor.py
0 → 100644
View file @
4182e1a8
# -*- coding: utf-8 -*-
"""
Created on 2017-9-22
@author: cheng.li
"""
import
pandas
as
pd
from
alphamind.execution.baseexecutor
import
ExecutorBase
class
NativeExecutor
(
ExecutorBase
):
def
__init__
(
self
):
super
()
.
__init__
()
def
execute
(
self
,
target_pos
:
pd
.
DataFrame
)
->
pd
.
DataFrame
:
return
target_pos
.
copy
()
alphamind/execution/thresholdexecutor.py
0 → 100644
View file @
4182e1a8
# -*- coding: utf-8 -*-
"""
Created on 2017-9-22
@author: cheng.li
"""
import
numpy
as
np
import
pandas
as
pd
from
alphamind.execution.baseexecutor
import
ExecutorBase
class
ThresholdExecutor
(
ExecutorBase
):
def
__init__
(
self
,
turn_over_threshold
:
float
):
super
()
.
__init__
()
self
.
threshold
=
turn_over_threshold
self
.
current_pos
=
pd
.
DataFrame
()
def
execute
(
self
,
target_pos
:
pd
.
DataFrame
)
->
pd
.
DataFrame
:
if
self
.
current_pos
.
empty
:
self
.
current_pos
=
target_pos
.
copy
()
return
target_pos
.
copy
()
else
:
pos_merged
=
pd
.
merge
(
target_pos
,
self
.
current_pos
,
on
=
[
'code'
],
how
=
'outer'
)
pos_merged
.
fillna
(
0
,
inplace
=
True
)
pos_merged
[
'industry'
]
=
pos_merged
[
'industry_x'
]
.
where
(
pos_merged
[
'industry_x'
]
!=
0
,
pos_merged
[
'industry_y'
])
turn_over
=
np
.
abs
(
pos_merged
.
weight_x
-
pos_merged
.
weight_y
)
.
sum
()
if
turn_over
>=
self
.
threshold
:
self
.
current_pos
=
target_pos
.
copy
()
return
self
.
current_pos
.
copy
()
else
:
return
self
.
current_pos
.
copy
()
alphamind/tests/execution/__init__.py
0 → 100644
View file @
4182e1a8
alphamind/tests/execution/test_thresholdexecutor.py
0 → 100644
View file @
4182e1a8
# -*- coding: utf-8 -*-
"""
Created on 2017-9-22
@author: cheng.li
"""
import
unittest
import
pandas
as
pd
from
alphamind.execution.thresholdexecutor
import
ThresholdExecutor
class
TestThresholdExecutor
(
unittest
.
TestCase
):
def
test_threshold_executor
(
self
):
target_pos
=
pd
.
DataFrame
({
'code'
:
[
1
,
2
,
3
],
'weight'
:
[
0.2
,
0.3
,
0.5
],
'industry'
:
[
'a'
,
'b'
,
'c'
]})
executor
=
ThresholdExecutor
(
turn_over_threshold
=
0.5
)
# 1st round
executed_pos
=
executor
.
execute
(
target_pos
)
self
.
assertTrue
(
target_pos
.
equals
(
executed_pos
))
# 2nd round
target_pos
=
pd
.
DataFrame
({
'code'
:
[
1
,
2
,
4
],
'weight'
:
[
0.3
,
0.2
,
0.5
],
'industry'
:
[
'a'
,
'b'
,
'd'
]})
executed_pos
=
executor
.
execute
(
target_pos
)
self
.
assertTrue
(
target_pos
.
equals
(
executed_pos
))
self
.
assertTrue
(
executed_pos
.
equals
(
executor
.
current_pos
))
# 3nd round
target_pos
=
pd
.
DataFrame
({
'code'
:
[
1
,
3
,
4
],
'weight'
:
[
0.3
,
0.2
,
0.5
],
'industry'
:
[
'a'
,
'c'
,
'd'
]})
executed_pos2
=
executor
.
execute
(
target_pos
)
self
.
assertTrue
(
executed_pos
.
equals
(
executed_pos2
))
if
__name__
==
'__main__'
:
unittest
.
main
()
alphamind/tests/test_suite.py
View file @
4182e1a8
...
@@ -28,6 +28,7 @@ from alphamind.tests.analysis.test_factoranalysis import TestFactorAnalysis
...
@@ -28,6 +28,7 @@ from alphamind.tests.analysis.test_factoranalysis import TestFactorAnalysis
from
alphamind.tests.analysis.test_quantilieanalysis
import
TestQuantileAnalysis
from
alphamind.tests.analysis.test_quantilieanalysis
import
TestQuantileAnalysis
from
alphamind.tests.model.test_linearmodel
import
TestLinearModel
from
alphamind.tests.model.test_linearmodel
import
TestLinearModel
from
alphamind.tests.model.test_loader
import
TestLoader
from
alphamind.tests.model.test_loader
import
TestLoader
from
alphamind.tests.execution.test_thresholdexecutor
import
TestThresholdExecutor
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
@@ -47,6 +48,7 @@ if __name__ == '__main__':
...
@@ -47,6 +48,7 @@ if __name__ == '__main__':
TestFactorAnalysis
,
TestFactorAnalysis
,
TestQuantileAnalysis
,
TestQuantileAnalysis
,
TestLinearModel
,
TestLinearModel
,
TestLoader
],
TestLoader
,
TestThresholdExecutor
],
alpha_logger
)
alpha_logger
)
runner
.
run
()
runner
.
run
()
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