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
0591851d
Commit
0591851d
authored
Sep 25, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
https://github.com/wegamekinglc/alpha-mind
parents
ff2d52f4
45eabfc1
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
159 additions
and
30 deletions
+159
-30
baseexecutor.py
alphamind/execution/baseexecutor.py
+3
-0
naiveexecutor.py
alphamind/execution/naiveexecutor.py
+1
-1
targetvolexecutor.py
alphamind/execution/targetvolexecutor.py
+32
-0
thresholdexecutor.py
alphamind/execution/thresholdexecutor.py
+2
-5
test_naiveexecutor.py
alphamind/tests/execution/test_naiveexecutor.py
+3
-0
test_targetvolexecutor.py
alphamind/tests/execution/test_targetvolexecutor.py
+19
-0
test_thresholdexecutor.py
alphamind/tests/execution/test_thresholdexecutor.py
+3
-0
executor_example.ipynb
notebooks/executor_example.ipynb
+96
-24
No files found.
alphamind/execution/baseexecutor.py
View file @
0591851d
...
...
@@ -27,3 +27,6 @@ class ExecutorBase(metaclass=abc.ABCMeta):
pos_merged
.
fillna
(
0
,
inplace
=
True
)
turn_over
=
np
.
abs
(
pos_merged
.
weight_x
-
pos_merged
.
weight_y
)
.
sum
()
return
turn_over
def
set_current
(
self
,
current_pos
:
pd
.
DataFrame
):
self
.
current_pos
=
current_pos
.
copy
()
alphamind/execution/naiveexecutor.py
View file @
0591851d
...
...
@@ -21,4 +21,4 @@ class NaiveExecutor(ExecutorBase):
else
:
turn_over
=
self
.
calc_turn_over
(
target_pos
,
self
.
current_pos
)
self
.
current_pos
=
target_pos
.
copy
()
return
turn_over
,
target_pos
.
copy
()
return
turn_over
,
target_pos
alphamind/execution/targetvolexecutor.py
0 → 100644
View file @
0591851d
# -*- coding: utf-8 -*-
"""
Created on 2017-9-22
@author: cheng.li
"""
from
typing
import
Tuple
import
pandas
as
pd
from
PyFin.Math.Accumulators
import
MovingStandardDeviation
from
alphamind.execution.baseexecutor
import
ExecutorBase
class
TargetVolExecutor
(
ExecutorBase
):
def
__init__
(
self
,
window
=
30
,
target_vol
=
0.01
):
super
()
.
__init__
()
self
.
m_vol
=
MovingStandardDeviation
(
window
=
window
,
dependency
=
'return'
)
self
.
target_vol
=
target_vol
self
.
multiplier
=
1.
def
execute
(
self
,
target_pos
:
pd
.
DataFrame
)
->
Tuple
[
float
,
pd
.
DataFrame
]:
if
not
self
.
m_vol
.
isFull
():
turn_over
=
self
.
calc_turn_over
(
target_pos
,
self
.
current_pos
)
return
turn_over
,
target_pos
else
:
c_vol
=
self
.
m_vol
.
result
()
self
.
multiplier
=
c_vol
/
self
.
target_vol
candidate_pos
=
target_pos
.
copy
()
candidate_pos
[
'weight'
]
=
candidate_pos
.
weight
*
self
.
multiplier
turn_over
=
self
.
calc_turn_over
(
candidate_pos
,
self
.
current_pos
)
return
turn_over
,
candidate_pos
alphamind/execution/thresholdexecutor.py
View file @
0591851d
...
...
@@ -15,18 +15,15 @@ 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
)
->
Tuple
[
float
,
pd
.
DataFrame
]:
if
self
.
current_pos
.
empty
:
self
.
current_pos
=
target_pos
.
copy
()
return
target_pos
.
weight
.
sum
(),
target_pos
.
copy
()
return
target_pos
.
weight
.
sum
(),
target_pos
else
:
turn_over
=
self
.
calc_turn_over
(
target_pos
,
self
.
current_pos
)
if
turn_over
>=
self
.
threshold
*
self
.
current_pos
.
weight
.
sum
():
self
.
current_pos
=
target_pos
.
copy
()
return
turn_over
,
self
.
current_pos
.
copy
()
return
turn_over
,
target_pos
else
:
return
0.
,
self
.
current_pos
.
copy
()
alphamind/tests/execution/test_naiveexecutor.py
View file @
0591851d
...
...
@@ -20,6 +20,7 @@ class TestNaiveExecutor(unittest.TestCase):
# 1st round
executor
=
NaiveExecutor
()
turn_over
,
executed_pos
=
executor
.
execute
(
target_pos
)
executor
.
set_current
(
executed_pos
)
self
.
assertAlmostEqual
(
turn_over
,
1.0
)
# 2nd round
...
...
@@ -28,6 +29,7 @@ class TestNaiveExecutor(unittest.TestCase):
'industry'
:
[
'a'
,
'b'
,
'd'
]})
turn_over
,
executed_pos
=
executor
.
execute
(
target_pos
)
executor
.
set_current
(
executed_pos
)
self
.
assertAlmostEqual
(
turn_over
,
1.2
)
# 3rd round
...
...
@@ -35,6 +37,7 @@ class TestNaiveExecutor(unittest.TestCase):
'weight'
:
[
0.3
,
0.2
,
0.5
],
'industry'
:
[
'a'
,
'c'
,
'd'
]})
turn_over
,
executed_pos
=
executor
.
execute
(
target_pos
)
executor
.
set_current
(
executed_pos
)
self
.
assertAlmostEqual
(
turn_over
,
0.4
)
...
...
alphamind/tests/execution/test_targetvolexecutor.py
0 → 100644
View file @
0591851d
# -*- coding: utf-8 -*-
"""
Created on 2017-9-22
@author: cheng.li
"""
import
unittest
from
alphamind.execution.targetvolexecutor
import
TargetVolExecutor
class
TestTargetVolExecutor
(
unittest
.
TestCase
):
def
test_target_vol_executor
(
self
):
if
__name__
==
'__main__'
:
unittest
.
main
()
\ No newline at end of file
alphamind/tests/execution/test_thresholdexecutor.py
View file @
0591851d
...
...
@@ -21,6 +21,7 @@ class TestThresholdExecutor(unittest.TestCase):
# 1st round
turn_over
,
executed_pos
=
executor
.
execute
(
target_pos
)
executor
.
set_current
(
executed_pos
)
self
.
assertTrue
(
target_pos
.
equals
(
executed_pos
))
self
.
assertAlmostEqual
(
turn_over
,
target_pos
.
weight
.
sum
())
...
...
@@ -30,6 +31,7 @@ class TestThresholdExecutor(unittest.TestCase):
'industry'
:
[
'a'
,
'b'
,
'd'
]})
turn_over
,
executed_pos
=
executor
.
execute
(
target_pos
)
executor
.
set_current
(
executed_pos
)
self
.
assertTrue
(
target_pos
.
equals
(
executed_pos
))
self
.
assertTrue
(
executed_pos
.
equals
(
executor
.
current_pos
))
self
.
assertAlmostEqual
(
turn_over
,
1.2
)
...
...
@@ -39,6 +41,7 @@ class TestThresholdExecutor(unittest.TestCase):
'weight'
:
[
0.3
,
0.2
,
0.5
],
'industry'
:
[
'a'
,
'c'
,
'd'
]})
turn_over
,
executed_pos2
=
executor
.
execute
(
target_pos
)
executor
.
set_current
(
executed_pos2
)
self
.
assertTrue
(
executed_pos
.
equals
(
executed_pos2
))
self
.
assertAlmostEqual
(
turn_over
,
0.
)
...
...
notebooks/executor_example.ipynb
View file @
0591851d
This source diff could not be displayed because it is too large. You can
view the blob
instead.
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