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
108d2d78
Commit
108d2d78
authored
Aug 21, 2017
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added one more example
parent
ca79db7e
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
93 additions
and
1 deletion
+93
-1
sqlengine.py
alphamind/data/engines/sqlengine.py
+2
-1
plot_quantile_res.py
alphamind/examples/plot_quantile_res.py
+91
-0
No files found.
alphamind/data/engines/sqlengine.py
View file @
108d2d78
...
...
@@ -23,6 +23,7 @@ from alphamind.data.dbmodel.models import IndexComponent
from
alphamind.data.dbmodel.models
import
Uqer
from
alphamind.data.dbmodel.models
import
Tiny
from
alphamind.data.dbmodel.models
import
LegacyFactor
from
alphamind.data.dbmodel.models
import
Experimental
from
alphamind.data.dbmodel.models
import
SpecificRiskDay
from
alphamind.data.dbmodel.models
import
SpecificRiskShort
from
alphamind.data.dbmodel.models
import
SpecificRiskLong
...
...
@@ -79,7 +80,7 @@ macro_styles = ['COUNTRY']
total_risk_factors
=
risk_styles
+
industry_styles
+
macro_styles
factor_tables
=
[
Uqer
,
Tiny
,
LegacyFactor
]
factor_tables
=
[
Uqer
,
Tiny
,
LegacyFactor
,
Experimental
]
def
append_industry_info
(
df
):
...
...
alphamind/examples/plot_quantile_res.py
0 → 100644
View file @
108d2d78
# -*- coding: utf-8 -*-
"""
Created on 2017-8-16
@author: cheng.li
"""
import
datetime
as
dt
import
numpy
as
np
import
pandas
as
pd
from
PyFin.api
import
*
from
alphamind.api
import
*
from
matplotlib
import
pyplot
as
plt
start
=
dt
.
datetime
.
now
()
engine
=
SqlEngine
(
"mssql+pymssql://licheng:A12345678!@10.63.6.220/alpha"
)
universe
=
Universe
(
'custom'
,
[
'zz500'
])
neutralize_risk
=
[
'SIZE'
]
+
industry_styles
n_bins
=
5
factor_weights
=
np
.
array
([
1.
])
freq
=
'1w'
if
freq
==
'1m'
:
horizon
=
21
elif
freq
==
'1w'
:
horizon
=
4
elif
freq
==
'1d'
:
horizon
=
0
start_date
=
'2016-04-01'
end_date
=
'2017-08-17'
dates
=
makeSchedule
(
start_date
,
end_date
,
tenor
=
freq
,
calendar
=
'china.sse'
)
prod_factors
=
[
'IVR'
,
'RVOL'
]
all_data
=
engine
.
fetch_data_range
(
universe
,
prod_factors
,
dates
=
dates
,
benchmark
=
905
)
factor_all_data
=
all_data
[
'factor'
]
total_df
=
pd
.
DataFrame
()
for
factor
in
prod_factors
:
factors
=
[
factor
]
final_res
=
np
.
zeros
((
len
(
dates
),
n_bins
))
factor_groups
=
factor_all_data
.
groupby
(
'Date'
)
for
i
,
value
in
enumerate
(
factor_groups
):
date
=
value
[
0
]
data
=
value
[
1
][[
'Code'
,
factor
,
'isOpen'
,
'weight'
]
+
neutralize_risk
]
codes
=
data
.
Code
.
tolist
()
ref_date
=
value
[
0
]
.
strftime
(
'
%
Y-
%
m-
%
d'
)
returns
=
engine
.
fetch_dx_return
(
date
,
codes
,
horizon
=
horizon
)
total_data
=
pd
.
merge
(
data
,
returns
,
on
=
[
'Code'
])
.
dropna
()
risk_exp
=
total_data
[
neutralize_risk
]
.
values
.
astype
(
float
)
dx_return
=
total_data
.
dx
.
values
benchmark
=
total_data
.
weight
.
values
f_data
=
total_data
[
factors
]
try
:
res
=
quantile_analysis
(
f_data
,
factor_weights
,
dx_return
,
risk_exp
=
risk_exp
,
n_bins
=
n_bins
,
benchmark
=
benchmark
)
except
Exception
as
e
:
print
(
e
)
res
=
np
.
zeros
(
n_bins
)
final_res
[
i
]
=
res
/
benchmark
.
sum
()
df
=
pd
.
DataFrame
(
final_res
,
index
=
dates
)
start_date
=
advanceDateByCalendar
(
'china.sse'
,
dates
[
0
],
'-1w'
)
df
.
loc
[
start_date
]
=
0.
df
.
sort_index
(
inplace
=
True
)
df
=
df
.
cumsum
()
.
plot
()
plt
.
title
(
'{0} weekly re-balance'
.
format
(
factors
[
0
]))
plt
.
savefig
(
'{0}_big_universe_20170814.png'
.
format
(
factors
[
0
]))
print
(
'{0} is finished'
.
format
(
factor
))
print
(
dt
.
datetime
.
now
()
-
start
)
plt
.
show
()
\ No newline at end of file
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