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
4e86d506
Commit
4e86d506
authored
Jul 11, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added one more std step to factor analysis
parent
6a7a551c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
3 deletions
+67
-3
factoranalysis.py
alphamind/analysis/factoranalysis.py
+1
-1
sqlengine.py
alphamind/data/engines/sqlengine.py
+6
-2
example2.py
alphamind/examples/example2.py
+60
-0
No files found.
alphamind/analysis/factoranalysis.py
View file @
4e86d506
...
...
@@ -33,7 +33,7 @@ def factor_processing(raw_factors: np.ndarray,
if
risk_factors
is
not
None
:
new_factors
=
neutralize
(
risk_factors
,
new_factors
)
return
new_factors
return
standardize
(
new_factors
)
def
build_portfolio
(
er
:
np
.
ndarray
,
...
...
alphamind/data/engines/sqlengine.py
View file @
4e86d506
...
...
@@ -174,13 +174,17 @@ if __name__ == '__main__':
engine
=
SqlEngine
(
db_url
)
ref_date
=
'2017-07-04'
factors
=
engine
.
fetch_factors_meta
()[[
'factor'
,
'source'
]]
factors
[
'factor'
]
=
factors
.
factor
.
str
.
strip
()
factors
[
'source'
]
=
factors
.
source
.
str
.
strip
()
import
datetime
as
dt
start
=
dt
.
datetime
.
now
()
for
i
in
range
(
1
0
):
for
i
in
range
(
1
):
factors
=
engine
.
fetch_factors_meta
()
codes
=
engine
.
fetch_codes
(
'2017-07-04'
,
universe
)
total_data
=
engine
.
fetch_data
(
ref_date
,
[
'EPS'
,
'DROEAfterNonRecurring'
]
,
[
1
,
5
],
905
)
total_data
=
engine
.
fetch_data
(
ref_date
,
factors
.
factor
.
tolist
()
,
[
1
,
5
],
905
)
print
(
dt
.
datetime
.
now
()
-
start
)
...
...
alphamind/examples/example2.py
0 → 100644
View file @
4e86d506
# -*- coding: utf-8 -*-
"""
Created on 2017-7-10
@author: cheng.li
"""
import
pandas
as
pd
from
alphamind.analysis.factoranalysis
import
factor_analysis
from
alphamind.data.engines.sqlengine
import
SqlEngine
from
alphamind.data.engines.universe
import
Universe
from
alphamind.data.engines.sqlengine
import
risk_styles
from
alphamind.data.engines.sqlengine
import
industry_styles
from
PyFin.api
import
bizDatesList
engine
=
SqlEngine
(
'mssql+pymssql://licheng:A12345678!@10.63.6.220/alpha'
)
universe
=
Universe
(
'custom'
,
[
'zz500'
])
total_risks
=
risk_styles
+
industry_styles
type
=
'risk_neutral'
def
calculate_one_day
(
ref_date
,
factors
,
weights
):
print
(
ref_date
)
codes
=
engine
.
fetch_codes
(
ref_date
,
universe
)
total_data
=
engine
.
fetch_data
(
ref_date
,
factors
,
codes
,
905
)
factor_data
=
total_data
[
'factor'
]
factor_df
=
factor_data
[[
'Code'
,
'industry'
,
'd1'
,
'weight'
,
'isOpen'
]
+
total_risks
+
factors
]
.
dropna
()
weights
,
_
=
factor_analysis
(
factor_df
[
factors
],
weights
,
factor_df
.
industry
.
values
,
factor_df
.
d1
.
values
,
detail_analysis
=
False
,
benchmark
=
factor_df
.
weight
.
values
,
risk_exp
=
factor_df
[
total_risks
]
.
values
,
is_tradable
=
factor_df
.
isOpen
.
values
,
method
=
type
)
return
ref_date
,
(
weights
.
weight
-
factor_df
.
weight
)
.
dot
(
factor_df
.
d1
)
if
__name__
==
'__main__'
:
from
matplotlib
import
pyplot
as
plt
factors
=
[
'EPS'
]
#, 'FY12P', 'VAL', 'CFinc1', 'BDTO', 'RVOL']
weights
=
[
1.
]
#, 1., 1., 1., 0.5, 0.5]
biz_dates
=
bizDatesList
(
'china.sse'
,
'2013-01-01'
,
'2017-07-05'
)
ers
=
[]
dates
=
[]
for
ref_date
in
biz_dates
:
ref_date
,
er
=
calculate_one_day
(
ref_date
,
factors
,
weights
)
dates
.
append
(
ref_date
)
ers
.
append
(
er
)
res
=
pd
.
Series
(
ers
,
index
=
dates
)
res
.
cumsum
()
.
plot
()
plt
.
show
()
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