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
6f03cfe2
Commit
6f03cfe2
authored
May 10, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added linear model
parent
0afa057f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
40 additions
and
6 deletions
+40
-6
cyimpl.pyx
alphamind/cyimpl.pyx
+1
-1
neutralize.py
alphamind/data/neutralize.py
+1
-1
linearmodel.py
alphamind/model/linearmodel.py
+34
-0
percentbuilder.py
alphamind/portfolio/percentbuilder.py
+2
-2
rankbuilder.py
alphamind/portfolio/rankbuilder.py
+2
-2
No files found.
alphamind/cyimpl.pyx
View file @
6f03cfe2
...
@@ -34,4 +34,4 @@ cpdef groupby(long[:] groups):
...
@@ -34,4 +34,4 @@ cpdef groupby(long[:] groups):
group_ids[curr_tag] = [i]
group_ids[curr_tag] = [i]
else:
else:
deref(it).second.push_back(i)
deref(it).second.push_back(i)
return [np.array(v) for v in group_ids.values()]
return {k: np.array(v) for k, v in group_ids.items()}
\ No newline at end of file
\ No newline at end of file
alphamind/data/neutralize.py
View file @
6f03cfe2
...
@@ -37,7 +37,7 @@ def neutralize(x: np.ndarray, y: np.ndarray, groups: np.ndarray=None, output_exp
...
@@ -37,7 +37,7 @@ def neutralize(x: np.ndarray, y: np.ndarray, groups: np.ndarray=None, output_exp
groups_ids
=
groupby
(
groups
)
groups_ids
=
groupby
(
groups
)
for
curr_idx
in
groups_ids
:
for
curr_idx
in
groups_ids
.
values
()
:
curr_x
=
x
[
curr_idx
]
curr_x
=
x
[
curr_idx
]
curr_y
=
y
[
curr_idx
]
curr_y
=
y
[
curr_idx
]
b
=
ls_fit
(
curr_x
,
curr_y
)
b
=
ls_fit
(
curr_x
,
curr_y
)
...
...
alphamind/model/linearmodel.py
0 → 100644
View file @
6f03cfe2
# -*- coding: utf-8 -*-
"""
Created on 2017-5-10
@author: cheng.li
"""
from
typing
import
Union
import
numpy
as
np
from
alphamind.cyimpl
import
groupby
from
alphamind.data.neutralize
import
ls_fit
def
_train
(
x
:
np
.
ndarray
,
y
:
np
.
ndarray
,
groups
:
np
.
ndarray
=
None
)
->
Union
[
np
.
ndarray
,
dict
]:
if
groups
is
None
:
return
ls_fit
(
x
,
y
)
else
:
groups_ids
=
groupby
(
groups
)
res_beta
=
{}
for
k
,
curr_idx
in
groups_ids
.
items
():
curr_x
=
x
[
curr_idx
]
curr_y
=
y
[
curr_idx
]
res_beta
[
k
]
=
ls_fit
(
curr_x
,
curr_y
)
return
res_beta
if
__name__
==
'__main__'
:
x
=
np
.
random
.
randn
(
3000
,
10
)
y
=
np
.
random
.
randn
(
3000
)
groups
=
np
.
random
.
randint
(
30
,
size
=
3000
)
print
(
_train
(
x
,
y
,
groups
))
\ No newline at end of file
alphamind/portfolio/percentbuilder.py
View file @
6f03cfe2
...
@@ -21,7 +21,7 @@ def percent_build(er: np.ndarray, percent: float, groups: np.ndarray=None) -> np
...
@@ -21,7 +21,7 @@ def percent_build(er: np.ndarray, percent: float, groups: np.ndarray=None) -> np
weights
=
zeros
((
length
,
1
))
weights
=
zeros
((
length
,
1
))
if
groups
is
not
None
:
if
groups
is
not
None
:
group_ids
=
groupby
(
groups
)
group_ids
=
groupby
(
groups
)
for
current_index
in
group_ids
:
for
current_index
in
group_ids
.
values
()
:
current_ordering
=
neg_er
[
current_index
]
.
argsort
()
current_ordering
=
neg_er
[
current_index
]
.
argsort
()
current_ordering
.
shape
=
-
1
,
1
current_ordering
.
shape
=
-
1
,
1
use_rank
=
int
(
percent
*
len
(
current_index
))
use_rank
=
int
(
percent
*
len
(
current_index
))
...
@@ -37,7 +37,7 @@ def percent_build(er: np.ndarray, percent: float, groups: np.ndarray=None) -> np
...
@@ -37,7 +37,7 @@ def percent_build(er: np.ndarray, percent: float, groups: np.ndarray=None) -> np
if
groups
is
not
None
:
if
groups
is
not
None
:
group_ids
=
groupby
(
groups
)
group_ids
=
groupby
(
groups
)
for
current_index
in
group_ids
:
for
current_index
in
group_ids
.
values
()
:
current_ordering
=
neg_er
[
current_index
]
.
argsort
(
axis
=
0
)
current_ordering
=
neg_er
[
current_index
]
.
argsort
(
axis
=
0
)
use_rank
=
int
(
percent
*
len
(
current_index
))
use_rank
=
int
(
percent
*
len
(
current_index
))
set_value
(
weights
,
current_index
[
current_ordering
[:
use_rank
]],
1
)
set_value
(
weights
,
current_index
[
current_ordering
[:
use_rank
]],
1
)
...
...
alphamind/portfolio/rankbuilder.py
View file @
6f03cfe2
...
@@ -21,7 +21,7 @@ def rank_build(er: np.ndarray, use_rank: int, groups: np.ndarray=None) -> np.nda
...
@@ -21,7 +21,7 @@ def rank_build(er: np.ndarray, use_rank: int, groups: np.ndarray=None) -> np.nda
weights
=
zeros
((
length
,
1
))
weights
=
zeros
((
length
,
1
))
if
groups
is
not
None
:
if
groups
is
not
None
:
group_ids
=
groupby
(
groups
)
group_ids
=
groupby
(
groups
)
for
current_index
in
group_ids
:
for
current_index
in
group_ids
.
values
()
:
current_ordering
=
neg_er
[
current_index
]
.
argsort
()
current_ordering
=
neg_er
[
current_index
]
.
argsort
()
current_ordering
.
shape
=
-
1
,
1
current_ordering
.
shape
=
-
1
,
1
set_value
(
weights
,
current_index
[
current_ordering
[:
use_rank
]],
1.
)
set_value
(
weights
,
current_index
[
current_ordering
[:
use_rank
]],
1.
)
...
@@ -35,7 +35,7 @@ def rank_build(er: np.ndarray, use_rank: int, groups: np.ndarray=None) -> np.nda
...
@@ -35,7 +35,7 @@ def rank_build(er: np.ndarray, use_rank: int, groups: np.ndarray=None) -> np.nda
if
groups
is
not
None
:
if
groups
is
not
None
:
group_ids
=
groupby
(
groups
)
group_ids
=
groupby
(
groups
)
for
current_index
in
group_ids
:
for
current_index
in
group_ids
.
values
()
:
current_ordering
=
neg_er
[
current_index
]
.
argsort
(
axis
=
0
)
current_ordering
=
neg_er
[
current_index
]
.
argsort
(
axis
=
0
)
set_value
(
weights
,
current_index
[
current_ordering
[:
use_rank
]],
1
)
set_value
(
weights
,
current_index
[
current_ordering
[:
use_rank
]],
1
)
else
:
else
:
...
...
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