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
933560a7
Commit
933560a7
authored
Jul 21, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added constraints class
parent
6f5267fd
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
0 deletions
+41
-0
constraints.py
alphamind/portfolio/constraints.py
+41
-0
No files found.
alphamind/portfolio/constraints.py
0 → 100644
View file @
933560a7
# -*- coding: utf-8 -*-
"""
Created on 2017-7-21
@author: cheng.li
"""
from
math
import
inf
import
numpy
as
np
from
typing
import
Tuple
class
Constraints
(
object
):
def
__init__
(
self
,
risk_exp
:
np
.
ndarray
,
risk_names
:
np
.
ndarray
):
self
.
risk_exp
=
risk_exp
self
.
risk_names
=
risk_names
self
.
risk_maps
=
dict
(
zip
(
risk_names
,
range
(
len
(
risk_names
))))
self
.
lower_bounds
=
-
inf
*
np
.
ones
(
len
(
risk_names
))
self
.
upper_bounds
=
inf
*
np
.
ones
(
len
(
risk_names
))
def
set_constraints
(
self
,
tag
:
str
,
lower_bound
:
float
,
upper_bound
:
float
):
index
=
self
.
risk_maps
[
tag
]
self
.
lower_bounds
[
index
]
=
lower_bound
self
.
upper_bounds
[
index
]
=
upper_bound
def
risk_targets
(
self
)
->
Tuple
[
np
.
ndarray
,
np
.
ndarray
]:
return
self
.
lower_bounds
,
self
.
upper_bounds
if
__name__
==
'__main__'
:
risk_exp
=
np
.
array
([[
1.0
,
2.0
],
[
3.0
,
4.0
]])
risk_names
=
np
.
array
([
'a'
,
'b'
])
cons
=
Constraints
(
risk_exp
,
risk_names
)
cons
.
set_constraints
(
'b'
,
0.0
,
0.1
)
print
(
cons
.
risk_targets
())
\ No newline at end of file
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