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
64406a81
Commit
64406a81
authored
Feb 27, 2022
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added manager more info
parent
52149dd6
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
39 deletions
+61
-39
utility.py
fof/utility.py
+26
-3
010 基金经理指数.ipynb
manager/010 基金经理指数.ipynb
+35
-36
020 基金经理穿透.ipynb
manager/020 基金经理穿透.ipynb
+0
-0
No files found.
fof/utility.py
View file @
64406a81
...
...
@@ -52,6 +52,9 @@ INDUSTRY_STYLES = [
]
BOND_CLASSES
=
[
"990301"
,
"990302"
,
"990303"
,
"990304"
,
"990305"
,
"990306"
,
"990399"
,
"990501"
,
"990502"
,
"990205"
,
"990402"
,
"990603"
]
def
read_sql
(
query
,
source
=
"mssql"
):
if
source
==
"mssql"
:
engine
=
sa
.
create_engine
(
MSSQL_CONN
,
encoding
=
"utf8"
,
connect_args
=
{
"charset"
:
"GBK"
})
...
...
@@ -60,15 +63,22 @@ def read_sql(query, source="mssql"):
return
pd
.
read_sql
(
query
,
con
=
engine
)
def
nearest_report_date
(
date
):
def
nearest_report_date
(
date
,
freq
=
"Q"
):
if
len
(
date
)
==
10
:
date
=
date
.
replace
(
"-"
,
""
)
mm
=
int
(
date
[
4
:
6
])
year
=
int
(
date
[
0
:
4
])
last_year
=
year
q
=
(
mm
//
3
+
1
)
*
3
if
freq
==
"Q"
:
q
=
(
mm
//
3
+
1
)
*
3
-
3
else
:
q
=
(
mm
//
6
+
1
)
*
6
-
6
if
q
<=
0
:
q
+=
12
last_year
-=
1
last
=
calendar
.
monthrange
(
last_year
,
q
)[
1
]
return
dt
.
date
(
last_year
,
q
,
last
)
.
strftime
(
"
%
Y
%
m
%
d"
)
...
...
@@ -497,3 +507,16 @@ def fd_rl_classification(security_ids, trade_dt):
flag = 1
"""
return
read_sql
(
query
,
source
=
"mysql"
)
.
sort_values
(
"SECURITYID"
)
.
reset_index
(
drop
=
True
)
def
read_factors
(
security_ids
,
trade_dt
,
factors
):
sec_id_strs
=
_join_ids
(
security_ids
)
query
=
f
"""
SELECT security_code, trade_date, {','.join(factors)} FROM factor_valuation_estimation
WHERE
trade_date = '{_to_yyyymmdd(trade_dt)}' AND
security_code in ({sec_id_strs}) AND
flag = 1
"""
return
read_sql
(
query
,
source
=
"mysql"
)
.
sort_values
(
"security_code"
)
.
reset_index
(
drop
=
True
)
manager/010 基金经理指数.ipynb
View file @
64406a81
...
...
@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count":
1
,
"execution_count":
3
,
"id": "ca389ee5-b800-4682-bfab-a22a6247bd67",
"metadata": {},
"outputs": [],
...
...
@@ -13,7 +13,8 @@
"from fof.utility import (\n",
" fd_manager,\n",
" fd_fund_mktv,\n",
" fd_rl_classification\n",
" fd_rl_classification,\n",
" BOND_CLASSES\n",
")\n",
"import pandas as pd\n",
"from PyFin.api import *"
...
...
@@ -30,7 +31,7 @@
},
{
"cell_type": "code",
"execution_count":
2
,
"execution_count":
4
,
"id": "008213ed-f569-4535-8519-7a5b1b06503c",
"metadata": {},
"outputs": [],
...
...
@@ -40,7 +41,7 @@
},
{
"cell_type": "code",
"execution_count":
3
,
"execution_count":
5
,
"id": "be10d317-bca6-41db-9b54-56573cd564a6",
"metadata": {},
"outputs": [
...
...
@@ -145,7 +146,7 @@
"4 19000101 "
]
},
"execution_count":
3
,
"execution_count":
5
,
"metadata": {},
"output_type": "execute_result"
}
...
...
@@ -158,7 +159,7 @@
},
{
"cell_type": "code",
"execution_count":
4
,
"execution_count":
6
,
"id": "ffbac3af-39d6-4cd3-95cb-705c32380985",
"metadata": {},
"outputs": [
...
...
@@ -196,40 +197,40 @@
" <td>1030000867</td>\n",
" <td>1.9650</td>\n",
" <td>1.708075</td>\n",
" <td>1.
38508
3e+08</td>\n",
" <td>
2.721688
e+08</td>\n",
" <td>1.
94091
3e+08</td>\n",
" <td>
3.813894
e+08</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>1030004356</td>\n",
" <td>1.5530</td>\n",
" <td>1.569653</td>\n",
" <td>
1.991231
e+08</td>\n",
" <td>
3.092382
e+08</td>\n",
" <td>
3.329090
e+08</td>\n",
" <td>
5.170077
e+08</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>1030005207</td>\n",
" <td>1.8904</td>\n",
" <td>1.689080</td>\n",
" <td>
2.636247e+08
</td>\n",
" <td>
4.983561
e+08</td>\n",
" <td>
8.860713e+07
</td>\n",
" <td>
1.675029
e+08</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>1030007006</td>\n",
" <td>1.1860</td>\n",
" <td>0.168919</td>\n",
" <td>
5.582928
e+08</td>\n",
" <td>
6.62135
2e+08</td>\n",
" <td>
4.971115
e+08</td>\n",
" <td>
5.89574
2e+08</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>1030008874</td>\n",
" <td>1.7560</td>\n",
" <td>1.679213</td>\n",
" <td>
3.007749e+06
</td>\n",
" <td>
5.281608e+06
</td>\n",
" <td>
1.152421e+07
</td>\n",
" <td>
2.023652e+07
</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
...
...
@@ -237,14 +238,14 @@
],
"text/plain": [
" SECURITYID UNITNAV NAVGRTD ENDFDSHARE MKTV\n",
"0 1030000867 1.9650 1.708075 1.
385083e+08 2.721688
e+08\n",
"1 1030004356 1.5530 1.569653
1.991231e+08 3.092382
e+08\n",
"2 1030005207 1.8904 1.689080
2.636247e+08 4.983561
e+08\n",
"3 1030007006 1.1860 0.168919
5.582928e+08 6.62135
2e+08\n",
"4 1030008874 1.7560 1.679213
3.007749e+06 5.281608e+06
"
"0 1030000867 1.9650 1.708075 1.
940913e+08 3.813894
e+08\n",
"1 1030004356 1.5530 1.569653
3.329090e+08 5.170077
e+08\n",
"2 1030005207 1.8904 1.689080
8.860713e+07 1.675029
e+08\n",
"3 1030007006 1.1860 0.168919
4.971115e+08 5.89574
2e+08\n",
"4 1030008874 1.7560 1.679213
1.152421e+07 2.023652e+07
"
]
},
"execution_count":
4
,
"execution_count":
6
,
"metadata": {},
"output_type": "execute_result"
}
...
...
@@ -257,7 +258,7 @@
},
{
"cell_type": "code",
"execution_count":
5
,
"execution_count":
7
,
"id": "3dc7be9d-e8c2-4566-bf14-d617ea230c14",
"metadata": {},
"outputs": [
...
...
@@ -343,21 +344,20 @@
"4 1030008874 9902 混合型基金 990202 高权益仓位混合型基金"
]
},
"execution_count":
5
,
"execution_count":
7
,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 获取基金分类信息\n",
"bonds_class_codes = [\"990301\", \"990302\", \"990303\", \"990304\", \"990305\", \"990306\", \"990399\", \"990501\", \"990502\", \"990205\", \"990402\", \"990603\"]\n",
"funds_rl_classification = fd_rl_classification(funds_mktv.SECURITYID, trade_dt)\n",
"funds_rl_classification.head()"
]
},
{
"cell_type": "code",
"execution_count":
6
,
"execution_count":
8
,
"id": "1055c68c-3875-489b-acaa-a9046d98a2c1",
"metadata": {},
"outputs": [],
...
...
@@ -368,13 +368,13 @@
},
{
"cell_type": "code",
"execution_count":
7
,
"execution_count":
9
,
"id": "00d6c888-682e-43c5-8c57-420a279effa3",
"metadata": {},
"outputs": [],
"source": [
"market_manager_index_ret = total_df.MKTV @ total_df.NAVGRTD / (1e-10 + total_df.MKTV.sum()) / 100.0\n",
"flags = total_df.rl_sub_class.isin(
bonds_class_codes
)\n",
"flags = total_df.rl_sub_class.isin(
BOND_CLASSES
)\n",
"bond_market_manager_index_ret = total_df[flags].MKTV @ total_df[flags].NAVGRTD / (1e-10 + total_df[flags].MKTV.sum()) / 100.0\n",
"equity_market_manager_index_ret = total_df[~flags].MKTV @ total_df[~flags].NAVGRTD / (1e-10 + total_df[~flags].MKTV.sum()) / 100.0"
]
...
...
@@ -389,7 +389,7 @@
},
{
"cell_type": "code",
"execution_count":
8
,
"execution_count":
10
,
"id": "e1817df4-ce3f-48ca-b656-2a17abc18f8e",
"metadata": {},
"outputs": [],
...
...
@@ -398,7 +398,6 @@
" funds = fd_manager(manager_ids, start_date=trade_dt, end_date=trade_dt)\n",
" funds_mktv = fd_fund_mktv(funds.SECURITYID.unique(), trade_dt=trade_dt)\n",
" \n",
" bonds_class_codes = [\"990301\", \"990302\", \"990303\", \"990304\", \"990305\", \"990306\", \"990399\", \"990501\", \"990502\", \"990205\", \"990402\", \"990603\"]\n",
" funds_rl_classification = fd_rl_classification(funds_mktv.SECURITYID, trade_dt)\n",
" \n",
" total_df = pd.merge(funds, funds_mktv, on=\"SECURITYID\")\n",
...
...
@@ -406,7 +405,7 @@
" \n",
" def calc(g):\n",
" market_manager_index_ret = g.MKTV @ g.NAVGRTD / (1e-10 + g.MKTV.sum()) / 100.0\n",
" flags = g.rl_sub_class.isin(
bonds_class_codes
)\n",
" flags = g.rl_sub_class.isin(
BOND_CLASSES
)\n",
" bond_market_manager_index_ret = g[flags].MKTV @ g[flags].NAVGRTD / (1e-10 + g[flags].MKTV.sum()) / 100.0\n",
" equity_market_manager_index_ret = g[~flags].MKTV @ g[~flags].NAVGRTD / (1e-10 + g[~flags].MKTV.sum()) / 100.0\n",
" return pd.Series(\n",
...
...
@@ -417,7 +416,7 @@
},
{
"cell_type": "code",
"execution_count":
9
,
"execution_count":
11
,
"id": "3225d437-56a8-4fc6-80bc-22456a356754",
"metadata": {},
"outputs": [
...
...
@@ -464,9 +463,9 @@
" <th>1</th>\n",
" <td>30322345</td>\n",
" <td>左金保</td>\n",
" <td>0.0
09627
</td>\n",
" <td>0.0
11596
</td>\n",
" <td>0.0</td>\n",
" <td>0.0
09627
</td>\n",
" <td>0.0
11596
</td>\n",
" <td>20220207</td>\n",
" </tr>\n",
" </tbody>\n",
...
...
@@ -476,10 +475,10 @@
"text/plain": [
" MANAGERCODE MANAGERNAME all bond equity trade_date\n",
"0 30189744 张坤 0.039522 0.0 0.039522 20220207\n",
"1 30322345 左金保 0.0
09627 0.0 0.009627
20220207"
"1 30322345 左金保 0.0
11596 0.0 0.011596
20220207"
]
},
"execution_count":
9
,
"execution_count":
11
,
"metadata": {},
"output_type": "execute_result"
}
...
...
manager/020 基金经理穿透.ipynb
0 → 100644
View file @
64406a81
This diff is collapsed.
Click to expand it.
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