Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
F
fof
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.李
fof
Commits
e41f62d2
Commit
e41f62d2
authored
Feb 03, 2022
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update api
parent
2387388e
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
766 additions
and
643 deletions
+766
-643
010 style attribution.ipynb
attribution/010 style attribution.ipynb
+494
-542
020 brison attribution.ipynb
attribution/020 brison attribution.ipynb
+216
-74
utility.py
fof/utility.py
+56
-27
No files found.
attribution/010 style attribution.ipynb
View file @
e41f62d2
This diff is collapsed.
Click to expand it.
attribution/020 brison attribution.ipynb
View file @
e41f62d2
This diff is collapsed.
Click to expand it.
fof/utility.py
View file @
e41f62d2
...
...
@@ -239,7 +239,10 @@ def fd_skdetail(security_ids, trade_dt):
ISVALID = 1 AND
SECODE in ({sec_id_strs})
"""
return
read_sql
(
query
)
.
sort_values
(
"SECURITYID"
)
df
=
read_sql
(
query
)
.
sort_values
(
"SECURITYID"
)
total_value
=
df
.
HOLDMKTCAP
.
sum
()
df
[
"pct"
]
=
df
.
HOLDMKTCAP
/
total_value
return
df
def
_to_yyyy_mm_dd
(
trade_dt
):
...
...
@@ -249,7 +252,7 @@ def _to_yyyy_mm_dd(trade_dt):
return
f
"{trade_dt[0:4]}-{trade_dt[4:6]}-{trade_dt[6:8]}"
def
risk_exposure
(
security_ids
,
trade_dt
):
def
risk_exposure
(
security_ids
,
start_date
,
end_date
):
if
isinstance
(
security_ids
,
str
):
sec_id_strs
=
security_ids
else
:
...
...
@@ -258,26 +261,54 @@ def risk_exposure(security_ids, trade_dt):
query
=
f
"""
SELECT trade_date, security_code, {','.join(RISK_STYLES)}, {','.join(INDUSTRY_STYLES)} FROM risk_exposure
WHERE
trade_date
= '{_to_yyyy_mm_dd(trade_dt
)}' AND
is_verify = 1 AND
trade_date
>= '{_to_yyyy_mm_dd(start_date
)}' AND
trade_date <= '{_to_yyyy_mm_dd(end_date)}' AND
flag = 1 AND
security_code IN ({sec_id_strs})
"""
return
read_sql
(
query
,
source
=
"mysql"
)
.
sort_values
(
"security_code"
)
return
read_sql
(
query
,
source
=
"mysql"
)
.
sort_values
([
"trade_date"
,
"security_code"
])
def
risk_return
(
start_date
,
end_date
):
query
=
f
"""
SELECT trade_date, {','.join(RISK_STYLES)}, {','.join(INDUSTRY_STYLES)} FROM risk_return
WHERE
trade_date >= '{_to_yyyy_mm_dd(start_date)}' AND
trade_date <= '{_to_yyyy_mm_dd(end_date)}' AND
flag = 1
"""
return
read_sql
(
query
,
source
=
"mysql"
)
.
sort_values
([
"trade_date"
])
def
specific_return
(
security_ids
,
start_date
,
end_date
):
if
isinstance
(
security_ids
,
str
):
sec_id_strs
=
security_ids
else
:
sec_id_strs
=
","
.
join
([
"'"
+
s
+
"'"
for
s
in
security_ids
])
query
=
f
"""
SELECT trade_date, security_code, secShortName, symbol, spret FROM specific_return
WHERE
trade_date >= '{_to_yyyy_mm_dd(start_date)}' AND
trade_date <= '{_to_yyyy_mm_dd(end_date)}' AND
flag = 1 AND
security_code IN ({sec_id_strs})
"""
return
read_sql
(
query
,
source
=
"mysql"
)
.
sort_values
([
"trade_date"
,
"security_code"
])
def
risk_cov
(
trade_dt
,
model
=
"short"
):
def
risk_cov
(
start_date
,
end_date
,
model
=
"short"
):
query
=
f
"""
SELECT
*
FROM risk_cov_{model}
SELECT
trade_date, FactorID, {','.join(RISK_STYLES)}, {','.join(INDUSTRY_STYLES)}
FROM risk_cov_{model}
WHERE
trade_date
= '{_to_yyyy_mm_dd(trade_dt
)}' AND
is_verify = 1 AND
trade_date
>= '{_to_yyyy_mm_dd(start_date
)}' AND
trade_date <= '{_to_yyyy_mm_dd(end_date)}' AND
flag = 1
"""
return
read_sql
(
query
,
source
=
"mysql"
)
.
sort_values
(
"FactorID"
)
return
read_sql
(
query
,
source
=
"mysql"
)
.
sort_values
(
[
"trade_date"
,
"FactorID"
]
)
def
special_risk
(
security_ids
,
trade_dt
,
model
=
"short"
):
def
special_risk
(
security_ids
,
start_date
,
end_date
,
model
=
"short"
):
if
isinstance
(
security_ids
,
str
):
sec_id_strs
=
security_ids
else
:
...
...
@@ -286,15 +317,15 @@ def special_risk(security_ids, trade_dt, model="short"):
query
=
f
"""
SELECT trade_date, security_code, secShortName, symbol, SRISK FROM specific_risk_{model}
WHERE
trade_date
= '{_to_yyyy_mm_dd(trade_dt
)}' AND
is_verify = 1 AND
trade_date
>= '{_to_yyyy_mm_dd(start_date
)}' AND
trade_date <= '{_to_yyyy_mm_dd(end_date)}' AND
flag = 1 AND
security_code IN ({sec_id_strs})
"""
return
read_sql
(
query
,
source
=
"mysql"
)
.
sort_values
(
"security_code"
)
return
read_sql
(
query
,
source
=
"mysql"
)
.
sort_values
(
[
"trade_date"
,
"security_code"
]
)
def
index_component
(
index_code
,
trade_dt
):
def
index_component
(
index_code
,
start_date
,
end_date
):
query
=
f
"""
SELECT index_component.trade_date, index_component.security_code, `index`.sname, `index`.weighing FROM `index`
JOIN index_component ON
...
...
@@ -302,17 +333,16 @@ def index_component(index_code, trade_dt):
`index`.isymbol = index_component.isymbol AND
`index`.symbol = index_component.symbol
WHERE
`index`.trade_date
= '{_to_yyyy_mm_dd(trade_dt
)}' AND
`index`.
is_verify = 1
AND
`index`.trade_date
>= '{_to_yyyy_mm_dd(start_date
)}' AND
`index`.
trade_date <= '{_to_yyyy_mm_dd(end_date)}'
AND
`index`.flag = 1 AND
index_component.is_verify = 1 AND
index_component.flag = 1 AND
index_component.isecurity_code = '{index_code}';
"""
return
read_sql
(
query
,
source
=
"mysql"
)
.
sort_values
(
"security_code"
)
return
read_sql
(
query
,
source
=
"mysql"
)
.
sort_values
(
[
"trade_date"
,
"security_code"
]
)
def
sw_industry_daily
(
security_ids
,
trade_dt
,
level
=
1
):
def
sw_industry_daily
(
security_ids
,
start_date
,
end_date
,
level
=
1
):
if
isinstance
(
security_ids
,
str
):
sec_id_strs
=
security_ids
else
:
...
...
@@ -321,27 +351,26 @@ def sw_industry_daily(security_ids, trade_dt, level=1):
query
=
f
"""
SELECT trade_date, security_code, industry_code{level} as industry_code, industry_name{level} as industry_name FROM sw_industry_daily
WHERE
trade_date
= '{_to_yyyy_mm_dd(trade_dt
)}' AND
is_verify = 1
AND
trade_date
>= '{_to_yyyy_mm_dd(start_date
)}' AND
trade_date <= '{_to_yyyy_mm_dd(end_date)}'
AND
flag = 1 AND
security_code IN ({sec_id_strs})
"""
return
read_sql
(
query
,
source
=
"mysql"
)
.
sort_values
(
"security_code"
)
return
read_sql
(
query
,
source
=
"mysql"
)
.
sort_values
(
[
"trade_date"
,
"security_code"
]
)
def
stk_return
_range
(
security_ids
,
start_date
,
end_date
):
def
stk_return
(
security_ids
,
start_date
,
end_date
):
if
isinstance
(
security_ids
,
str
):
sec_id_strs
=
security_ids
else
:
sec_id_strs
=
","
.
join
([
"'"
+
s
+
"'"
for
s
in
security_ids
])
query
=
f
"""
SELECT
security_code, min(trade_date) as start_date, max(trade_date) as end_date, exp(sum(log(change_pct / 100.0 + 1.0))) - 1.0 as rtn
FROM stk_daily_price_pro
SELECT
trade_date, security_code, change_pct / 100.
FROM stk_daily_price_pro
WHERE
trade_date >= '{_to_yyyy_mm_dd(start_date)}' AND
trade_date <= '{_to_yyyy_mm_dd(end_date)}' AND
security_code IN ({sec_id_strs}) AND
flag = 1
GROUP BY security_code;
"""
return
read_sql
(
query
,
source
=
"mysql"
)
.
sort_values
(
"security_code"
)
return
read_sql
(
query
,
source
=
"mysql"
)
.
sort_values
(
[
"trade_date"
,
"security_code"
]
)
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