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
2387388e
Commit
2387388e
authored
Feb 03, 2022
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added more api
parent
c0494dcc
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
706 additions
and
67 deletions
+706
-67
010 style attribution.ipynb
attribution/010 style attribution.ipynb
+436
-64
020 brison attribution.ipynb
attribution/020 brison attribution.ipynb
+215
-1
utility.py
fof/utility.py
+55
-2
No files found.
attribution/010 style attribution.ipynb
View file @
2387388e
This diff is collapsed.
Click to expand it.
attribution/020 brison attribution.ipynb
View file @
2387388e
...
...
@@ -2,10 +2,224 @@
"cells": [
{
"cell_type": "code",
"execution_count":
null
,
"execution_count":
1
,
"id": "a1fbf6c8-e22a-4d0d-b3d8-c6c54d60bce1",
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"sys.path.append(\"../\")\n",
"from fof.utility import *"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "21a0b455-1eb3-47f0-8a9c-15533dd12939",
"metadata": {},
"outputs": [],
"source": [
"df = fd_skdetail(\"1030000006\", trade_dt=\"20210630\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "82ca3a10-45e2-4b49-8be1-1e77104a1a52",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>trade_date</th>\n",
" <th>security_code</th>\n",
" <th>sname</th>\n",
" <th>weighing</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>115</th>\n",
" <td>2021-06-30</td>\n",
" <td>2010000001</td>\n",
" <td>浦发银行</td>\n",
" <td>0.55</td>\n",
" </tr>\n",
" <tr>\n",
" <th>116</th>\n",
" <td>2021-06-30</td>\n",
" <td>2010000010</td>\n",
" <td>上海机场</td>\n",
" <td>0.22</td>\n",
" </tr>\n",
" <tr>\n",
" <th>117</th>\n",
" <td>2021-06-30</td>\n",
" <td>2010000011</td>\n",
" <td>包钢股份</td>\n",
" <td>0.17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>118</th>\n",
" <td>2021-06-30</td>\n",
" <td>2010000012</td>\n",
" <td>华能国际</td>\n",
" <td>0.09</td>\n",
" </tr>\n",
" <tr>\n",
" <th>119</th>\n",
" <td>2021-06-30</td>\n",
" <td>2010000014</td>\n",
" <td>华夏银行</td>\n",
" <td>0.18</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>296</th>\n",
" <td>2021-06-30</td>\n",
" <td>2010032227</td>\n",
" <td>沪硅产业</td>\n",
" <td>0.07</td>\n",
" </tr>\n",
" <tr>\n",
" <th>278</th>\n",
" <td>2021-06-30</td>\n",
" <td>2010032240</td>\n",
" <td>万泰生物</td>\n",
" <td>0.08</td>\n",
" </tr>\n",
" <tr>\n",
" <th>191</th>\n",
" <td>2021-06-30</td>\n",
" <td>2010032306</td>\n",
" <td>中泰证券</td>\n",
" <td>0.04</td>\n",
" </tr>\n",
" <tr>\n",
" <th>270</th>\n",
" <td>2021-06-30</td>\n",
" <td>2010032493</td>\n",
" <td>甘李药业</td>\n",
" <td>0.03</td>\n",
" </tr>\n",
" <tr>\n",
" <th>267</th>\n",
" <td>2021-06-30</td>\n",
" <td>2010033291</td>\n",
" <td>中金公司</td>\n",
" <td>0.08</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>300 rows × 4 columns</p>\n",
"</div>"
],
"text/plain": [
" trade_date security_code sname weighing\n",
"115 2021-06-30 2010000001 浦发银行 0.55\n",
"116 2021-06-30 2010000010 上海机场 0.22\n",
"117 2021-06-30 2010000011 包钢股份 0.17\n",
"118 2021-06-30 2010000012 华能国际 0.09\n",
"119 2021-06-30 2010000014 华夏银行 0.18\n",
".. ... ... ... ...\n",
"296 2021-06-30 2010032227 沪硅产业 0.07\n",
"278 2021-06-30 2010032240 万泰生物 0.08\n",
"191 2021-06-30 2010032306 中泰证券 0.04\n",
"270 2021-06-30 2010032493 甘李药业 0.03\n",
"267 2021-06-30 2010033291 中金公司 0.08\n",
"\n",
"[300 rows x 4 columns]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"index_component(\"2070000060\", trade_dt=\"20210630\")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "6d57d8f9-6c1c-4a41-ae64-87763648a22b",
"metadata": {},
"outputs": [],
"source": [
"res = sw_industry_daily(df.SKCODE, \"20210630\", 2)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "6883105d-9a59-4e08-847c-a9c056826fd1",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"39"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"len(res.industry_name.unique())"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "fa17cc0d-61ad-4958-bf01-7cdc1c17230d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Wall time: 44.6 s\n"
]
}
],
"source": [
"%%time\n",
"rtns = stk_return_range(df.SKCODE, \"20210630\", \"20211231\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7743d37c-eb35-4294-95ef-da1007e3c175",
"metadata": {},
"outputs": [],
"source": []
}
],
...
...
fof/utility.py
View file @
2387388e
...
...
@@ -256,7 +256,7 @@ def risk_exposure(security_ids, trade_dt):
sec_id_strs
=
","
.
join
([
"'"
+
s
+
"'"
for
s
in
security_ids
])
query
=
f
"""
SELECT
*
FROM risk_exposure
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
...
...
@@ -291,4 +291,57 @@ def special_risk(security_ids, trade_dt, model="short"):
flag = 1 AND
security_code IN ({sec_id_strs})
"""
return
read_sql
(
query
,
source
=
"mysql"
)
.
sort_values
(
"security_code"
)
\ No newline at end of file
return
read_sql
(
query
,
source
=
"mysql"
)
.
sort_values
(
"security_code"
)
def
index_component
(
index_code
,
trade_dt
):
query
=
f
"""
SELECT index_component.trade_date, index_component.security_code, `index`.sname, `index`.weighing FROM `index`
JOIN index_component ON
`index`.trade_date = index_component.trade_date AND
`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`.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"
)
def
sw_industry_daily
(
security_ids
,
trade_dt
,
level
=
1
):
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, 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
flag = 1 AND
security_code IN ({sec_id_strs})
"""
return
read_sql
(
query
,
source
=
"mysql"
)
.
sort_values
(
"security_code"
)
def
stk_return_range
(
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
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"
)
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