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
04f81b19
Commit
04f81b19
authored
Mar 17, 2018
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update er analysis api
parent
aebfe089
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
5 deletions
+24
-5
factoranalysis.py
alphamind/analysis/factoranalysis.py
+23
-4
meanvariancebuilder.py
alphamind/portfolio/meanvariancebuilder.py
+1
-1
No files found.
alphamind/analysis/factoranalysis.py
View file @
04f81b19
...
@@ -18,6 +18,7 @@ from alphamind.portfolio.longshortbulder import long_short_build
...
@@ -18,6 +18,7 @@ from alphamind.portfolio.longshortbulder import long_short_build
from
alphamind.portfolio.rankbuilder
import
rank_build
from
alphamind.portfolio.rankbuilder
import
rank_build
from
alphamind.portfolio.linearbuilder
import
linear_build
from
alphamind.portfolio.linearbuilder
import
linear_build
from
alphamind.portfolio.meanvariancebuilder
import
mean_variance_builder
from
alphamind.portfolio.meanvariancebuilder
import
mean_variance_builder
from
alphamind.portfolio.meanvariancebuilder
import
target_vol_builder
from
alphamind.data.processing
import
factor_processing
from
alphamind.data.processing
import
factor_processing
from
alphamind.settlement.simplesettle
import
simple_settle
from
alphamind.settlement.simplesettle
import
simple_settle
...
@@ -33,7 +34,6 @@ def factor_analysis(factors: pd.DataFrame,
...
@@ -33,7 +34,6 @@ def factor_analysis(factors: pd.DataFrame,
constraints
:
Optional
[
Constraints
]
=
None
,
constraints
:
Optional
[
Constraints
]
=
None
,
method
=
'risk_neutral'
,
method
=
'risk_neutral'
,
**
kwargs
)
->
Tuple
[
pd
.
DataFrame
,
Optional
[
pd
.
DataFrame
]]:
**
kwargs
)
->
Tuple
[
pd
.
DataFrame
,
Optional
[
pd
.
DataFrame
]]:
if
'pre_process'
in
kwargs
:
if
'pre_process'
in
kwargs
:
pre_process
=
kwargs
[
'pre_process'
]
pre_process
=
kwargs
[
'pre_process'
]
del
kwargs
[
'pre_process'
]
del
kwargs
[
'pre_process'
]
...
@@ -62,13 +62,12 @@ def factor_analysis(factors: pd.DataFrame,
...
@@ -62,13 +62,12 @@ def factor_analysis(factors: pd.DataFrame,
def
er_portfolio_analysis
(
er
:
np
.
ndarray
,
def
er_portfolio_analysis
(
er
:
np
.
ndarray
,
industry
:
np
.
ndarray
,
industry
:
np
.
ndarray
,
dx_return
:
np
.
ndarray
,
dx_return
:
np
.
ndarray
,
constraints
:
Optional
[
Union
[
LinearConstraints
,
Constraints
]]
=
None
,
constraints
:
Optional
[
Union
[
LinearConstraints
,
Constraints
]]
=
None
,
detail_analysis
=
True
,
detail_analysis
=
True
,
benchmark
:
Optional
[
np
.
ndarray
]
=
None
,
benchmark
:
Optional
[
np
.
ndarray
]
=
None
,
is_tradable
:
Optional
[
np
.
ndarray
]
=
None
,
is_tradable
:
Optional
[
np
.
ndarray
]
=
None
,
method
=
'risk_neutral'
,
method
=
'risk_neutral'
,
**
kwargs
)
->
Tuple
[
pd
.
DataFrame
,
Optional
[
pd
.
DataFrame
]]:
**
kwargs
)
->
Tuple
[
pd
.
DataFrame
,
Optional
[
pd
.
DataFrame
]]:
er
=
er
.
flatten
()
er
=
er
.
flatten
()
def
create_constraints
(
benchmark
,
**
kwargs
):
def
create_constraints
(
benchmark
,
**
kwargs
):
...
@@ -107,7 +106,8 @@ def er_portfolio_analysis(er: np.ndarray,
...
@@ -107,7 +106,8 @@ def er_portfolio_analysis(er: np.ndarray,
raise
ValueError
(
'linear programming optimizer in status: {0}'
.
format
(
status
))
raise
ValueError
(
'linear programming optimizer in status: {0}'
.
format
(
status
))
elif
method
==
'rank'
:
elif
method
==
'rank'
:
weights
=
rank_build
(
er
,
use_rank
=
kwargs
[
'use_rank'
],
masks
=
is_tradable
)
.
flatten
()
*
benchmark
.
sum
()
/
kwargs
[
'use_rank'
]
weights
=
rank_build
(
er
,
use_rank
=
kwargs
[
'use_rank'
],
masks
=
is_tradable
)
.
flatten
()
*
benchmark
.
sum
()
/
kwargs
[
'use_rank'
]
elif
method
==
'ls'
or
method
==
'long_short'
:
elif
method
==
'ls'
or
method
==
'long_short'
:
weights
=
long_short_build
(
er
)
.
flatten
()
weights
=
long_short_build
(
er
)
.
flatten
()
elif
method
==
'mv'
or
method
==
'mean_variance'
:
elif
method
==
'mv'
or
method
==
'mean_variance'
:
...
@@ -129,6 +129,25 @@ def er_portfolio_analysis(er: np.ndarray,
...
@@ -129,6 +129,25 @@ def er_portfolio_analysis(er: np.ndarray,
lam
=
lam
)
lam
=
lam
)
if
status
!=
'optimal'
:
if
status
!=
'optimal'
:
raise
ValueError
(
'mean variance optimizer in status: {0}'
.
format
(
status
))
raise
ValueError
(
'mean variance optimizer in status: {0}'
.
format
(
status
))
elif
method
==
'tv'
or
method
==
'target_vol'
:
lbound
,
ubound
,
cons_exp
,
risk_lbound
,
risk_ubound
=
create_constraints
(
benchmark
,
**
kwargs
)
cov
=
kwargs
[
'cov'
]
if
'target_vol'
in
kwargs
:
target_vol
=
kwargs
[
'target_vol'
]
else
:
target_vol
=
1.
status
,
_
,
weights
=
target_vol_builder
(
er
,
cov
=
cov
,
bm
=
benchmark
,
lbound
=
lbound
,
ubound
=
ubound
,
risk_exposure
=
cons_exp
,
risk_target
=
(
risk_lbound
,
risk_ubound
),
vol_low
=
0
,
vol_high
=
target_vol
)
else
:
else
:
raise
ValueError
(
"Unknown building type ({0})"
.
format
(
method
))
raise
ValueError
(
"Unknown building type ({0})"
.
format
(
method
))
...
...
alphamind/portfolio/meanvariancebuilder.py
View file @
04f81b19
...
@@ -74,7 +74,7 @@ def target_vol_builder(er: np.ndarray,
...
@@ -74,7 +74,7 @@ def target_vol_builder(er: np.ndarray,
risk_exposure
:
Optional
[
np
.
ndarray
],
risk_exposure
:
Optional
[
np
.
ndarray
],
risk_target
:
Optional
[
Tuple
[
np
.
ndarray
,
np
.
ndarray
]],
risk_target
:
Optional
[
Tuple
[
np
.
ndarray
,
np
.
ndarray
]],
vol_low
:
float
=
0.
,
vol_low
:
float
=
0.
,
vol_high
:
float
=
1.
):
vol_high
:
float
=
1.
)
->
Tuple
[
str
,
float
,
np
.
ndarray
]
:
lbound
,
ubound
,
cons_mat
,
clbound
,
cubound
=
_create_bounds
(
lbound
,
ubound
,
bm
,
risk_exposure
,
risk_target
)
lbound
,
ubound
,
cons_mat
,
clbound
,
cubound
=
_create_bounds
(
lbound
,
ubound
,
bm
,
risk_exposure
,
risk_target
)
optimizer
=
CVOptimizer
(
er
,
optimizer
=
CVOptimizer
(
er
,
...
...
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