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
741b2f62
Commit
741b2f62
authored
May 19, 2018
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modified constraints
parent
a6557ea9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
2 deletions
+28
-2
constraints.py
alphamind/portfolio/constraints.py
+0
-2
test_constraints.py
alphamind/tests/portfolio/test_constraints.py
+28
-0
No files found.
alphamind/portfolio/constraints.py
View file @
741b2f62
...
...
@@ -57,7 +57,6 @@ class BoundaryImpl(object):
elif
self
.
b_type
==
BoundaryType
.
MAXABSREL
:
abs_threshold
=
self
.
val
[
0
]
rel_threshold
=
self
.
val
[
1
]
pyFinAssert
(
rel_threshold
>=
0.
,
ValueError
,
"relative bounds only support positive value"
)
if
self
.
direction
==
BoundaryDirection
.
LOWER
:
rel_bound
=
center
-
abs
(
center
)
*
rel_threshold
abs_bound
=
center
-
abs_threshold
...
...
@@ -69,7 +68,6 @@ class BoundaryImpl(object):
elif
self
.
b_type
==
BoundaryType
.
MINABSREL
:
abs_threshold
=
self
.
val
[
0
]
rel_threshold
=
self
.
val
[
1
]
pyFinAssert
(
rel_threshold
>=
0.
,
ValueError
,
"relative bounds only support positive value"
)
if
self
.
direction
==
BoundaryDirection
.
LOWER
:
rel_bound
=
center
-
abs
(
center
)
*
rel_threshold
abs_bound
=
center
-
abs_threshold
...
...
alphamind/tests/portfolio/test_constraints.py
View file @
741b2f62
...
...
@@ -78,6 +78,34 @@ class TestConstraints(unittest.TestCase):
self
.
assertAlmostEqual
(
l
,
1.76
)
self
.
assertAlmostEqual
(
u
,
2.42
)
def
test_max_abs_relative_boundary
(
self
):
lower
=
BoundaryImpl
(
BoundaryDirection
.
LOWER
,
BoundaryType
.
MAXABSREL
,
(
0.02
,
0.2
))
upper
=
BoundaryImpl
(
BoundaryDirection
.
UPPER
,
BoundaryType
.
MAXABSREL
,
(
0.02
,
0.2
))
bound
=
BoxBoundary
(
lower
,
upper
)
center
=
2.2
l
,
u
=
bound
.
bounds
(
center
)
self
.
assertAlmostEqual
(
l
,
1.76
)
self
.
assertAlmostEqual
(
u
,
2.64
)
def
test_min_abs_relative_boundary
(
self
):
lower
=
BoundaryImpl
(
BoundaryDirection
.
LOWER
,
BoundaryType
.
MINABSREL
,
(
0.02
,
0.2
))
upper
=
BoundaryImpl
(
BoundaryDirection
.
UPPER
,
BoundaryType
.
MINABSREL
,
(
0.02
,
0.2
))
bound
=
BoxBoundary
(
lower
,
upper
)
center
=
2.2
l
,
u
=
bound
.
bounds
(
center
)
self
.
assertAlmostEqual
(
l
,
2.18
)
self
.
assertAlmostEqual
(
u
,
2.22
)
def
test_create_box_bounds_single_value
(
self
):
names
=
[
'a'
,
'b'
,
'c'
]
b_type
=
BoundaryType
.
RELATIVE
...
...
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