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
94e941a0
Commit
94e941a0
authored
Feb 26, 2022
by
Dr.李
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added manager
parent
041faa29
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
106 additions
and
8 deletions
+106
-8
utility.py
fof/utility.py
+29
-8
010 fund manager.ipynb
manager/010 fund manager.ipynb
+77
-0
No files found.
fof/utility.py
View file @
94e941a0
...
...
@@ -243,11 +243,18 @@ def _to_yyyy_mm_dd(trade_dt):
return
trade_dt
else
:
return
f
"{trade_dt[0:4]}-{trade_dt[4:6]}-{trade_dt[6:8]}"
def
_to_yyyymmdd
(
trade_dt
):
if
len
(
trade_dt
)
==
8
:
return
trade_dt
else
:
return
f
"{trade_dt[0:4]}{trade_dt[5:7]}{trade_dt[8:10]}"
def
_
security
_ids
(
security_ids
):
def
_
join
_ids
(
security_ids
):
if
isinstance
(
security_ids
,
str
):
sec_id_strs
=
security_ids
sec_id_strs
=
"'"
+
security_ids
+
"'"
elif
security_ids
is
None
:
sec_id_strs
=
None
else
:
...
...
@@ -256,7 +263,7 @@ def _security_ids(security_ids):
def
fd_skdetail
(
security_ids
,
trade_dt
):
p_id_strs
=
_
security
_ids
(
security_ids
)
p_id_strs
=
_
join
_ids
(
security_ids
)
query
=
f
"""
SELECT SECODE as pid, SKCODE as security_code, SKNAME, HOLDMKTCAP, HOLDAMT, NAVRTO FROM TQ_FD_SKDETAIL
...
...
@@ -272,7 +279,7 @@ def fd_skdetail(security_ids, trade_dt):
def
risk_exposure
(
start_date
,
end_date
,
security_ids
=
None
):
sec_id_strs
=
_
security
_ids
(
security_ids
)
sec_id_strs
=
_
join
_ids
(
security_ids
)
if
sec_id_strs
:
query
=
f
"""
...
...
@@ -306,7 +313,7 @@ def risk_return(start_date, end_date):
def
specific_return
(
start_date
,
end_date
,
security_ids
=
None
):
sec_id_strs
=
_
security
_ids
(
security_ids
)
sec_id_strs
=
_
join
_ids
(
security_ids
)
if
sec_id_strs
:
query
=
f
"""
...
...
@@ -340,7 +347,7 @@ def risk_cov(start_date, end_date, model="short"):
def
special_risk
(
start_date
,
end_date
,
model
=
"short"
,
security_ids
=
None
):
sec_id_strs
=
_
security
_ids
(
security_ids
)
sec_id_strs
=
_
join
_ids
(
security_ids
)
if
sec_id_strs
:
query
=
f
"""
...
...
@@ -380,7 +387,7 @@ def index_component(index_code, start_date, end_date):
def
sw_industry_daily
(
start_date
,
end_date
,
level
=
1
,
security_ids
=
None
):
sec_id_strs
=
_
security
_ids
(
security_ids
)
sec_id_strs
=
_
join
_ids
(
security_ids
)
if
sec_id_strs
:
query
=
f
"""
SELECT trade_date, security_code, industry_code{level} as industry_code, industry_name{level} as industry_name FROM sw_industry_daily
...
...
@@ -402,7 +409,7 @@ def sw_industry_daily(start_date, end_date, level=1, security_ids=None):
def
stk_return
(
start_date
,
end_date
,
security_ids
=
None
):
sec_id_strs
=
_
security
_ids
(
security_ids
)
sec_id_strs
=
_
join
_ids
(
security_ids
)
if
sec_id_strs
:
query
=
f
"""
SELECT security_code, min(trade_date) as start_date, max(trade_date) as end_date, exp(sum(log(1.0 + change_pct / 100.))) AS chg_pct FROM stk_daily_price_pro
...
...
@@ -423,3 +430,17 @@ def stk_return(start_date, end_date, security_ids=None):
GROUP BY security_code;
"""
return
read_sql
(
query
,
source
=
"mysql"
)
.
sort_values
(
"security_code"
)
.
reset_index
(
drop
=
True
)
def
fd_manager
(
manager_ids
,
start_date
,
end_date
):
manager_ids
=
_join_ids
(
manager_ids
)
query
=
f
"""
SELECT MANAGERCODE, MANAGERNAME, COMPCODE, COMPNAME, SECODE as SECURITYID, BEGINDATE, ENDDATE FROM TQ_FD_MGPERFORMANCE
WHERE
BEGINDATE <= '{_to_yyyymmdd(end_date)}' AND
ENDDATE >= '{_to_yyyymmdd(start_date)}' AND
MANAGERCODE in ({manager_ids}) AND
ISVALID = 1
"""
return
read_sql
(
query
)
.
sort_values
(
"MANAGERCODE"
)
.
reset_index
(
drop
=
True
)
manager/010 fund manager.ipynb
0 → 100644
View file @
94e941a0
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "ca389ee5-b800-4682-bfab-a22a6247bd67",
"metadata": {},
"outputs": [],
"source": [
"import sys\n",
"sys.path.append(\"../\")\n",
"import datetime as dt\n",
"from fof.utility import fd_manager\n",
"from PyFin.api import *"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "008213ed-f569-4535-8519-7a5b1b06503c",
"metadata": {},
"outputs": [],
"source": [
"trade_dt = adjustDateByCalendar(\"china.sse\", \"2015-01-01\").strftime(\"%Y%m%d\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "be10d317-bca6-41db-9b54-56573cd564a6",
"metadata": {},
"outputs": [],
"source": [
"funds = fd_manager(\"30057809\", start_date='20100101', end_date='20220226')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "44022a45-2da2-4ee9-a107-f842f396317f",
"metadata": {},
"outputs": [],
"source": [
"funds"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "321f0f1d-c5c9-4591-8b67-e3ab9dbd1a11",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
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