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
a6557ea9
Commit
a6557ea9
authored
May 18, 2018
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added more constraints type
parent
89ecac54
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
2 deletions
+28
-2
constraints.py
alphamind/portfolio/constraints.py
+28
-2
No files found.
alphamind/portfolio/constraints.py
View file @
a6557ea9
...
@@ -27,6 +27,8 @@ class BoundaryDirection(IntEnum):
...
@@ -27,6 +27,8 @@ class BoundaryDirection(IntEnum):
class
BoundaryType
(
IntEnum
):
class
BoundaryType
(
IntEnum
):
ABSOLUTE
=
0
ABSOLUTE
=
0
RELATIVE
=
1
RELATIVE
=
1
MAXABSREL
=
2
MINABSREL
=
3
class
BoundaryImpl
(
object
):
class
BoundaryImpl
(
object
):
...
@@ -34,14 +36,14 @@ class BoundaryImpl(object):
...
@@ -34,14 +36,14 @@ class BoundaryImpl(object):
def
__init__
(
self
,
def
__init__
(
self
,
direction
:
BoundaryDirection
,
direction
:
BoundaryDirection
,
b_type
:
BoundaryType
,
b_type
:
BoundaryType
,
val
:
float
):
val
):
self
.
direction
=
direction
self
.
direction
=
direction
self
.
b_type
=
b_type
self
.
b_type
=
b_type
self
.
val
=
val
self
.
val
=
val
self
.
_validation
()
self
.
_validation
()
def
_validation
(
self
):
def
_validation
(
self
):
pyFinAssert
(
self
.
b_type
==
BoundaryType
.
ABSOLUTE
or
self
.
b_type
==
BoundaryType
.
RELATIVE
,
pyFinAssert
(
self
.
b_type
in
[
BoundaryType
.
ABSOLUTE
,
BoundaryType
.
RELATIVE
,
BoundaryType
.
MAXABSREL
,
BoundaryType
.
MINABSREL
]
,
ValueError
,
ValueError
,
"Boundary Type {0} is not recognized"
.
format
(
self
.
b_type
))
"Boundary Type {0} is not recognized"
.
format
(
self
.
b_type
))
...
@@ -52,6 +54,30 @@ class BoundaryImpl(object):
...
@@ -52,6 +54,30 @@ class BoundaryImpl(object):
def
__call__
(
self
,
center
:
float
):
def
__call__
(
self
,
center
:
float
):
if
self
.
b_type
==
BoundaryType
.
ABSOLUTE
:
if
self
.
b_type
==
BoundaryType
.
ABSOLUTE
:
return
self
.
val
+
center
return
self
.
val
+
center
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
return
min
(
rel_bound
,
abs_bound
)
elif
self
.
direction
==
BoundaryDirection
.
UPPER
:
rel_bound
=
center
+
abs
(
center
)
*
rel_threshold
abs_bound
=
center
+
abs_threshold
return
max
(
rel_bound
,
abs_bound
)
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
return
max
(
rel_bound
,
abs_bound
)
elif
self
.
direction
==
BoundaryDirection
.
UPPER
:
rel_bound
=
center
+
abs
(
center
)
*
rel_threshold
abs_bound
=
center
+
abs_threshold
return
min
(
rel_bound
,
abs_bound
)
else
:
else
:
pyFinAssert
(
center
>=
0.
,
ValueError
,
"relative bounds only support positive back bone value"
)
pyFinAssert
(
center
>=
0.
,
ValueError
,
"relative bounds only support positive back bone value"
)
return
self
.
val
*
center
return
self
.
val
*
center
...
...
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