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
8abb8331
Commit
8abb8331
authored
Sep 15, 2018
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
small modification to mean variance builder interface
parent
e007f467
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
4 deletions
+36
-4
meanvariancebuilder.py
alphamind/portfolio/meanvariancebuilder.py
+8
-4
test_optimizers.py
alphamind/tests/cython/test_optimizers.py
+28
-0
No files found.
alphamind/portfolio/meanvariancebuilder.py
View file @
8abb8331
...
@@ -52,7 +52,8 @@ def mean_variance_builder(er: np.ndarray,
...
@@ -52,7 +52,8 @@ def mean_variance_builder(er: np.ndarray,
ubound
:
Union
[
np
.
ndarray
,
float
],
ubound
:
Union
[
np
.
ndarray
,
float
],
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
]],
lam
:
float
=
1.
)
->
Tuple
[
str
,
float
,
np
.
ndarray
]:
lam
:
float
=
1.
,
linear_solver
:
str
=
'ma27'
)
->
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
)
if
np
.
all
(
lbound
==
-
np
.
inf
)
and
np
.
all
(
ubound
==
np
.
inf
)
and
cons_mat
is
None
:
if
np
.
all
(
lbound
==
-
np
.
inf
)
and
np
.
all
(
ubound
==
np
.
inf
)
and
cons_mat
is
None
:
...
@@ -87,7 +88,8 @@ def mean_variance_builder(er: np.ndarray,
...
@@ -87,7 +88,8 @@ def mean_variance_builder(er: np.ndarray,
lam
,
lam
,
risk_model
[
'factor_cov'
],
risk_model
[
'factor_cov'
],
risk_model
[
'factor_loading'
],
risk_model
[
'factor_loading'
],
risk_model
[
'idsync'
])
risk_model
[
'idsync'
],
linear_solver
=
linear_solver
)
return
_create_result
(
optimizer
,
bm
)
return
_create_result
(
optimizer
,
bm
)
...
@@ -99,7 +101,8 @@ def target_vol_builder(er: np.ndarray,
...
@@ -99,7 +101,8 @@ def target_vol_builder(er: np.ndarray,
ubound
:
Union
[
np
.
ndarray
,
float
],
ubound
:
Union
[
np
.
ndarray
,
float
],
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_target
:
float
=
1.
)
->
Tuple
[
str
,
float
,
np
.
ndarray
]:
vol_target
:
float
=
1.
,
linear_solver
:
str
=
'ma27'
)
->
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
,
...
@@ -112,7 +115,8 @@ def target_vol_builder(er: np.ndarray,
...
@@ -112,7 +115,8 @@ def target_vol_builder(er: np.ndarray,
vol_target
,
vol_target
,
risk_model
[
'factor_cov'
],
risk_model
[
'factor_cov'
],
risk_model
[
'factor_loading'
],
risk_model
[
'factor_loading'
],
risk_model
[
'idsync'
])
risk_model
[
'idsync'
],
linear_solver
=
linear_solver
)
return
_create_result
(
optimizer
,
bm
)
return
_create_result
(
optimizer
,
bm
)
...
...
alphamind/tests/cython/test_optimizers.py
View file @
8abb8331
...
@@ -150,6 +150,34 @@ class TestOptimizers(unittest.TestCase):
...
@@ -150,6 +150,34 @@ class TestOptimizers(unittest.TestCase):
[
-
0.3
,
-
0.10919033
,
0.40919033
],
[
-
0.3
,
-
0.10919033
,
0.40919033
],
4
)
4
)
def
test_cvoptimizer_with_cons_with_different_solver
(
self
):
objective
=
np
.
array
([
0.1
,
0.2
,
0.3
])
cov
=
np
.
array
([[
0.05
,
0.01
,
0.02
],
[
0.01
,
0.06
,
0.03
],
[
0.02
,
0.03
,
0.07
]])
lbound
=
np
.
array
([
-
0.3
,
-
0.3
,
-
0.3
])
ubound
=
np
.
array
([
0.5
,
0.5
,
0.5
])
cons
=
np
.
array
([[
1.
,
1.
,
1.
]])
clbound
=
np
.
array
([
0.
])
cubound
=
np
.
array
([
0.
])
target_vol
=
0.1
optimizer
=
CVOptimizer
(
objective
,
cov
,
lbound
,
ubound
,
cons
,
clbound
,
cubound
,
target_vol
,
linear_solver
=
'ma97'
)
# check against known good result
np
.
testing
.
assert_array_almost_equal
(
optimizer
.
x_value
(),
[
-
0.3
,
-
0.10919033
,
0.40919033
],
4
)
def
test_cvoptimizer_with_factor_model
(
self
):
def
test_cvoptimizer_with_factor_model
(
self
):
objective
=
np
.
array
([
0.1
,
0.2
,
0.3
])
objective
=
np
.
array
([
0.1
,
0.2
,
0.3
])
lbound
=
np
.
array
([
0.0
,
0.0
,
0.0
])
lbound
=
np
.
array
([
0.0
,
0.0
,
0.0
])
...
...
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