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
fbfa9fd2
Commit
fbfa9fd2
authored
Nov 23, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added evolver
parent
e01c676b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
59 additions
and
1 deletion
+59
-1
formula_expression.py
alphamind/examples/formula_expression.py
+1
-1
evolver.py
alphamind/portfolio/evolver.py
+19
-0
test_evolver.py
alphamind/tests/portfolio/test_evolver.py
+37
-0
test_suite.py
alphamind/tests/test_suite.py
+2
-0
No files found.
alphamind/examples/formula_expression.py
View file @
fbfa9fd2
...
...
@@ -35,7 +35,7 @@ n_bins = 5
horizon
=
map_freq
(
freq
)
start_date
=
'2012-01-01'
end_date
=
'2017-11-2
0
'
end_date
=
'2017-11-2
1
'
dates
=
makeSchedule
(
start_date
,
end_date
,
...
...
alphamind/portfolio/evolver.py
0 → 100644
View file @
fbfa9fd2
# -*- coding: utf-8 -*-
"""
Created on 2017-11-23
@author: cheng.li
"""
import
numpy
as
np
def
evolve_positions
(
positions
:
np
.
ndarray
,
dx_ret
:
np
.
ndarray
)
->
np
.
ndarray
:
# assume return is log return
simple_return
=
np
.
exp
(
dx_ret
)
evolved_positions
=
positions
*
simple_return
leverage
=
np
.
abs
(
positions
)
.
sum
()
evolved_positions
=
evolved_positions
*
leverage
/
np
.
abs
(
evolved_positions
)
.
sum
()
return
evolved_positions
alphamind/tests/portfolio/test_evolver.py
0 → 100644
View file @
fbfa9fd2
# -*- coding: utf-8 -*-
"""
Created on 2017-11-23
@author: cheng.li
"""
import
unittest
import
numpy
as
np
from
alphamind.portfolio.evolver
import
evolve_positions
class
TestEvolver
(
unittest
.
TestCase
):
def
test_evolve_positions_with_all_positive_position
(
self
):
positions
=
np
.
array
([
0.2
,
0.2
,
0.8
])
dx_returns
=
np
.
array
([
0.06
,
0.04
,
-
0.10
])
simple_return
=
np
.
exp
(
dx_returns
)
curr_pos
=
positions
*
simple_return
expected_pos
=
curr_pos
/
curr_pos
.
sum
()
*
positions
.
sum
()
calculated_pos
=
evolve_positions
(
positions
,
dx_returns
)
np
.
testing
.
assert_array_almost_equal
(
expected_pos
,
calculated_pos
)
def
test_evolve_positions_with_negative_position
(
self
):
positions
=
np
.
array
([
0.2
,
0.3
,
-
0.8
])
dx_returns
=
np
.
array
([
0.06
,
0.04
,
-
0.10
])
simple_return
=
np
.
exp
(
dx_returns
)
curr_pos
=
positions
*
simple_return
expected_pos
=
curr_pos
/
np
.
abs
(
curr_pos
)
.
sum
()
*
np
.
abs
(
positions
)
.
sum
()
calculated_pos
=
evolve_positions
(
positions
,
dx_returns
)
np
.
testing
.
assert_array_almost_equal
(
expected_pos
,
calculated_pos
)
\ No newline at end of file
alphamind/tests/test_suite.py
View file @
fbfa9fd2
...
...
@@ -16,6 +16,7 @@ from alphamind.tests.data.test_standardize import TestStandardize
from
alphamind.tests.data.test_winsorize
import
TestWinsorize
from
alphamind.tests.data.test_quantile
import
TestQuantile
from
alphamind.tests.portfolio.test_constraints
import
TestConstraints
from
alphamind.tests.portfolio.test_evolver
import
TestEvolver
from
alphamind.tests.portfolio.test_longshortbuild
import
TestLongShortBuild
from
alphamind.tests.portfolio.test_rankbuild
import
TestRankBuild
from
alphamind.tests.portfolio.test_percentbuild
import
TestPercentBuild
...
...
@@ -41,6 +42,7 @@ if __name__ == '__main__':
TestWinsorize
,
TestQuantile
,
TestConstraints
,
TestEvolver
,
TestLongShortBuild
,
TestRankBuild
,
TestPercentBuild
,
...
...
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