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
d1774a67
Commit
d1774a67
authored
Mar 16, 2018
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added tests from cvoptimizer
parent
6af6574d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
85 additions
and
0 deletions
+85
-0
test_optimizers.py
alphamind/tests/cython/test_optimizers.py
+85
-0
No files found.
alphamind/tests/cython/test_optimizers.py
View file @
d1774a67
...
...
@@ -9,6 +9,7 @@ import unittest
import
numpy
as
np
from
alphamind.cython.optimizers
import
LPOptimizer
from
alphamind.cython.optimizers
import
QPOptimizer
from
alphamind.cython.optimizers
import
CVOptimizer
class
TestOptimizers
(
unittest
.
TestCase
):
...
...
@@ -69,6 +70,90 @@ class TestOptimizers(unittest.TestCase):
[
-
0.02
,
0.01
,
0.03
],
8
)
def
test_cvoptimizer_without_cons
(
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
,
None
,
None
,
None
,
target_vol
,
target_vol
)
# check against known good result
np
.
testing
.
assert_array_almost_equal
(
optimizer
.
x_value
(),
[
.0231776
,
0.1274768
,
0.30130881
],
4
)
def
test_cvoptimizer_with_cons
(
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
,
target_vol
)
# 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_cons_and_ieq
(
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
,
0.
,
target_vol
)
# check against known good result
np
.
testing
.
assert_array_almost_equal
(
optimizer
.
x_value
(),
[
-
0.3
,
-
0.10919033
,
0.40919033
],
4
)
if
__name__
==
'__main__'
:
unittest
.
main
()
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