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
4e2a6b04
Commit
4e2a6b04
authored
May 07, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow lower bound and upper bound on risk exposure
parent
69289f41
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
2500 additions
and
83 deletions
+2500
-83
linearbuild.py
alphamind/benchmarks/portfolio/linearbuild.py
+1
-1
linearbuilder.py
alphamind/portfolio/linearbuilder.py
+15
-10
factor analysis.ipynb
notebooks/factor analysis.ipynb
+2484
-72
No files found.
alphamind/benchmarks/portfolio/linearbuild.py
View file @
4e2a6b04
...
@@ -62,4 +62,4 @@ def benchmark_build_linear(n_samples: int, n_risks: int, n_loop: int) -> None:
...
@@ -62,4 +62,4 @@ def benchmark_build_linear(n_samples: int, n_risks: int, n_loop: int) -> None:
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
benchmark_build_linear
(
500
,
30
,
10
)
benchmark_build_linear
(
2000
,
30
,
10
)
\ No newline at end of file
\ No newline at end of file
alphamind/portfolio/linearbuilder.py
View file @
4e2a6b04
...
@@ -19,22 +19,27 @@ def linear_build(er: np.ndarray,
...
@@ -19,22 +19,27 @@ def linear_build(er: np.ndarray,
ubound
:
np
.
ndarray
,
ubound
:
np
.
ndarray
,
risk_exposure
:
np
.
ndarray
,
risk_exposure
:
np
.
ndarray
,
bm
:
np
.
ndarray
,
bm
:
np
.
ndarray
,
risk_target
:
np
.
ndarray
=
None
,
risk_target
:
Tuple
[
np
.
ndarray
,
np
.
ndarray
]
=
None
,
solver
:
str
=
None
)
->
Tuple
[
str
,
np
.
ndarray
,
np
.
ndarray
]:
solver
:
str
=
None
)
->
Tuple
[
str
,
np
.
ndarray
,
np
.
ndarray
]:
n
,
m
=
risk_exposure
.
shape
n
,
m
=
risk_exposure
.
shape
w
=
cvxpy
.
Variable
(
n
)
w
=
cvxpy
.
Variable
(
n
)
if
risk_target
is
None
:
risk_target
=
np
.
zeros
(
m
)
curr_risk_exposure
=
risk_exposure
.
T
*
(
w
-
bm
)
curr_risk_exposure
=
risk_exposure
.
T
*
(
w
-
bm
)
objective
=
cvxpy
.
Minimize
(
-
w
.
T
*
er
)
if
not
risk_target
:
risk_eq_target
=
np
.
zeros
(
m
)
constraints
=
[
w
>=
lbound
,
w
<=
ubound
,
curr_risk_exposure
==
risk_eq_target
,
cvxpy
.
sum_entries
(
w
)
==
1.
]
else
:
constraints
=
[
w
>=
lbound
,
constraints
=
[
w
>=
lbound
,
w
<=
ubound
,
w
<=
ubound
,
curr_risk_exposure
==
risk_target
,
curr_risk_exposure
>=
risk_target
[
0
],
curr_risk_exposure
<=
risk_target
[
1
],
cvxpy
.
sum_entries
(
w
)
==
1.
]
cvxpy
.
sum_entries
(
w
)
==
1.
]
objective
=
cvxpy
.
Minimize
(
-
w
.
T
*
er
)
prob
=
cvxpy
.
Problem
(
objective
,
constraints
)
prob
=
cvxpy
.
Problem
(
objective
,
constraints
)
prob
.
solve
(
solver
=
solver
)
prob
.
solve
(
solver
=
solver
)
return
prob
.
status
,
prob
.
value
,
np
.
array
(
w
.
value
)
.
flatten
()
return
prob
.
status
,
prob
.
value
,
np
.
array
(
w
.
value
)
.
flatten
()
...
@@ -46,7 +51,7 @@ if __name__ == '__main__':
...
@@ -46,7 +51,7 @@ if __name__ == '__main__':
bm
=
np
.
ones
(
300
)
*
0.00333333333
bm
=
np
.
ones
(
300
)
*
0.00333333333
risk_exposure
=
np
.
random
.
randn
(
300
,
10
)
risk_exposure
=
np
.
random
.
randn
(
300
,
10
)
s
,
v
,
x
=
linear_build
(
er
,
0.
,
0.01
,
risk_exposure
,
bm
)
s
,
v
,
x
=
linear_build
(
er
,
0.
,
0.01
,
risk_exposure
,
bm
,
[
-
0.01
*
np
.
ones
(
10
),
0.01
*
np
.
ones
(
10
)]
)
print
(
s
)
print
(
s
)
print
(
x
.
sum
())
print
(
x
.
sum
())
print
(
x
.
min
(),
','
,
x
.
max
())
print
(
x
.
min
(),
','
,
x
.
max
())
...
...
notebooks/factor analysis.ipynb
View file @
4e2a6b04
This source diff could not be displayed because it is too large. You can
view the blob
instead.
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