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
3a75d3cf
Commit
3a75d3cf
authored
Feb 06, 2018
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed error
parent
4b1287b6
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
5 deletions
+19
-5
factoranalysis.py
alphamind/analysis/factoranalysis.py
+3
-1
api.py
alphamind/api.py
+8
-0
constraints.py
alphamind/portfolio/constraints.py
+8
-4
No files found.
alphamind/analysis/factoranalysis.py
View file @
3a75d3cf
...
...
@@ -7,11 +7,13 @@ Created on 2017-5-25
from
typing
import
Optional
from
typing
import
Tuple
from
typing
import
Union
import
numpy
as
np
import
pandas
as
pd
from
alphamind.data.standardize
import
standardize
from
alphamind.data.winsorize
import
winsorize_normal
from
alphamind.portfolio.constraints
import
Constraints
from
alphamind.portfolio.constraints
import
LinearConstraints
from
alphamind.portfolio.longshortbulder
import
long_short_build
from
alphamind.portfolio.rankbuilder
import
rank_build
from
alphamind.portfolio.linearbuilder
import
linear_build
...
...
@@ -60,7 +62,7 @@ def factor_analysis(factors: pd.DataFrame,
def
er_portfolio_analysis
(
er
:
np
.
ndarray
,
industry
:
np
.
ndarray
,
dx_return
:
np
.
ndarray
,
constraints
:
Optional
[
Constraints
]
=
None
,
constraints
:
Optional
[
Union
[
LinearConstraints
,
Constraints
]
]
=
None
,
detail_analysis
=
True
,
benchmark
:
Optional
[
np
.
ndarray
]
=
None
,
is_tradable
:
Optional
[
np
.
ndarray
]
=
None
,
...
...
alphamind/api.py
View file @
3a75d3cf
...
...
@@ -14,6 +14,10 @@ from alphamind.data.engines.universe import Universe
from
alphamind.data.processing
import
factor_processing
from
alphamind.portfolio.constraints
import
Constraints
from
alphamind.portfolio.constraints
import
LinearConstraints
from
alphamind.portfolio.constraints
import
BoundaryType
from
alphamind.portfolio.constraints
import
BoundaryDirection
from
alphamind.portfolio.constraints
import
create_box_bounds
from
alphamind.portfolio.evolver
import
evolve_positions
from
alphamind.data.engines.sqlengine
import
risk_styles
...
...
@@ -58,6 +62,10 @@ __all__ = [
'Universe'
,
'factor_processing'
,
'Constraints'
,
'LinearConstraints'
,
'BoundaryType'
,
'BoundaryDirection'
,
'create_box_bounds'
,
'evolve_positions'
,
'risk_styles'
,
'industry_styles'
,
...
...
alphamind/portfolio/constraints.py
View file @
3a75d3cf
...
...
@@ -53,7 +53,7 @@ class BoundaryImpl(object):
if
self
.
b_type
==
BoundaryType
.
ABSOLUTE
:
return
self
.
val
+
center
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
...
...
@@ -72,7 +72,7 @@ class BoxBoundary(object):
def
create_box_bounds
(
names
:
List
[
str
],
b_type
:
BoundaryType
,
b_type
:
Union
[
Iterable
[
BoundaryType
],
BoundaryType
]
,
l_val
:
Union
[
Iterable
[
float
],
float
],
u_val
:
Union
[
Iterable
[
float
],
float
])
->
Dict
[
str
,
BoxBoundary
]:
"""
...
...
@@ -80,6 +80,9 @@ def create_box_bounds(names: List[str],
"""
bounds
=
dict
()
if
not
hasattr
(
b_type
,
'__iter__'
):
b_type
=
np
.
array
([
b_type
]
*
len
(
names
))
if
not
hasattr
(
l_val
,
'__iter__'
):
l_val
=
np
.
array
([
l_val
]
*
len
(
names
))
...
...
@@ -88,10 +91,10 @@ def create_box_bounds(names: List[str],
for
i
,
name
in
enumerate
(
names
):
lower
=
BoundaryImpl
(
BoundaryDirection
.
LOWER
,
b_type
,
b_type
[
i
]
,
l_val
[
i
])
upper
=
BoundaryImpl
(
BoundaryDirection
.
UPPER
,
b_type
,
b_type
[
i
]
,
u_val
[
i
])
bounds
[
name
]
=
BoxBoundary
(
lower
,
upper
)
return
bounds
...
...
@@ -122,6 +125,7 @@ class LinearConstraints(object):
upper_bounds
.
append
(
u
)
return
np
.
array
(
lower_bounds
),
np
.
array
(
upper_bounds
)
@
property
def
risk_exp
(
self
)
->
np
.
ndarray
:
return
self
.
cons_mat
[
self
.
names
]
.
values
...
...
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