Commit 43955e6c authored by Dr.李's avatar Dr.李

update

parent fa4f0b67
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -2,14 +2,14 @@ ...@@ -2,14 +2,14 @@
"cells": [ "cells": [
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 1,
"id": "51382765-24b4-4e5e-a118-077b276e0774", "id": "51382765-24b4-4e5e-a118-077b276e0774",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"import datetime as dt\n", "import datetime as dt\n",
"from utility import (\n", "from utility import (\n",
" read_sql,\n", " fd_alive_funds,\n",
" fd_basicinfo,\n", " fd_basicinfo,\n",
" fd_typeclass,\n", " fd_typeclass,\n",
" nearest_report_date\n", " nearest_report_date\n",
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 2,
"id": "47939edc-07d2-4c8e-b061-187806e124ea", "id": "47939edc-07d2-4c8e-b061-187806e124ea",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
...@@ -31,26 +31,19 @@ ...@@ -31,26 +31,19 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": 3,
"id": "9a596482-dd98-49dc-b717-c17177f2cd64", "id": "9a596482-dd98-49dc-b717-c17177f2cd64",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"# 获取所有目标货币型基金(清算结束日期晚于当前日)\n", "# 获取所有目标货币型基金(清算结束日期晚于当前日)\n",
"\n", "\n",
"security_ids = read_sql(f\"\"\"\n", "security_ids = fd_alive_funds(today, 204)"
"select SECURITYID from TQ_FD_TYPECLASS \n",
"WHERE\n",
" ISVALID = 1 AND\n",
" L1CODE = 5 AND\n",
" (ENDDATE>='{today}' or ENDDATE = '19000101') \n",
"ORDER BY SECURITYID;\n",
"\"\"\")[\"SECURITYID\"].unique().tolist()"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12, "execution_count": 4,
"id": "7e1a0517-e3de-4ea7-ae3c-9c2292c63260", "id": "7e1a0517-e3de-4ea7-ae3c-9c2292c63260",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
...@@ -61,7 +54,7 @@ ...@@ -61,7 +54,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 13, "execution_count": 5,
"id": "b0d0d48b-708b-447a-922b-500fbfb97600", "id": "b0d0d48b-708b-447a-922b-500fbfb97600",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
...@@ -71,7 +64,7 @@ ...@@ -71,7 +64,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 14, "execution_count": 6,
"id": "5ccf2dc7-fea9-4d52-b15d-e8ff55fac3dc", "id": "5ccf2dc7-fea9-4d52-b15d-e8ff55fac3dc",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
...@@ -83,7 +76,7 @@ ...@@ -83,7 +76,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 15, "execution_count": 7,
"id": "9d34507e-9efd-479a-8b25-a095de5a552c", "id": "9d34507e-9efd-479a-8b25-a095de5a552c",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
...@@ -113,6 +106,7 @@ ...@@ -113,6 +106,7 @@
" <th>SNAMECOMP</th>\n", " <th>SNAMECOMP</th>\n",
" <th>FSYMBOL</th>\n", " <th>FSYMBOL</th>\n",
" <th>FDNATURE</th>\n", " <th>FDNATURE</th>\n",
" <th>INVESTSTYLE</th>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>货币型(子类)</th>\n", " <th>货币型(子类)</th>\n",
...@@ -121,37 +115,40 @@ ...@@ -121,37 +115,40 @@
" <th></th>\n", " <th></th>\n",
" <th></th>\n", " <th></th>\n",
" <th></th>\n", " <th></th>\n",
" <th></th>\n",
" </tr>\n", " </tr>\n",
" </thead>\n", " </thead>\n",
" <tbody>\n", " <tbody>\n",
" <tr>\n", " <tr>\n",
" <th>场内货币型基金</th>\n", " <th>场内货币型基金</th>\n",
" <td>44</td>\n", " <td>19</td>\n",
" <td>44</td>\n", " <td>19</td>\n",
" <td>42</td>\n", " <td>19</td>\n",
" <td>44</td>\n", " <td>19</td>\n",
" <td>44</td>\n", " <td>19</td>\n",
" <td>19</td>\n",
" </tr>\n", " </tr>\n",
" <tr>\n", " <tr>\n",
" <th>场外货币型基金</th>\n", " <th>场外货币型基金</th>\n",
" <td>549</td>\n", " <td>542</td>\n",
" <td>549</td>\n", " <td>542</td>\n",
" <td>503</td>\n", " <td>496</td>\n",
" <td>549</td>\n", " <td>542</td>\n",
" <td>549</td>\n", " <td>542</td>\n",
" <td>542</td>\n",
" </tr>\n", " </tr>\n",
" </tbody>\n", " </tbody>\n",
"</table>\n", "</table>\n",
"</div>" "</div>"
], ],
"text/plain": [ "text/plain": [
" SECURITYID FDNAME SNAMECOMP FSYMBOL FDNATURE\n", " SECURITYID FDNAME SNAMECOMP FSYMBOL FDNATURE INVESTSTYLE\n",
"货币型(子类) \n", "货币型(子类) \n",
"场内货币型基金 44 44 42 44 44\n", "场内货币型基金 19 19 19 19 19 19\n",
"场外货币型基金 549 549 503 549 549" "场外货币型基金 542 542 496 542 542 542"
] ]
}, },
"execution_count": 15, "execution_count": 7,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -24,17 +24,28 @@ def nearest_report_date(date): ...@@ -24,17 +24,28 @@ def nearest_report_date(date):
return dt.date(last_year, q, last).strftime("%Y%m%d") return dt.date(last_year, q, last).strftime("%Y%m%d")
def fd_alive_funds(trade_dt, type_style, class_code): def fd_alive_funds(trade_dt, class_code=None):
sec_codes = read_sql(f""" if class_code:
select SECODE from TQ_FD_TYPE query = f"""
WHERE select SECODE from TQ_FD_TYPE
ISVALID = 1 AND WHERE
TYPESTYLE = '{type_style}' AND ISVALID = 1 AND
CLASSCODE = '{class_code}' AND TYPESTYLE = '{str(class_code)[0]}' AND
BEGINDATE <= '{trade_dt}' AND CLASSCODE = '{class_code}' AND
(ENDDATE>='{trade_dt}' or ENDDATE = '19000101') BEGINDATE <= '{trade_dt}' AND
ORDER BY SECODE; (ENDDATE>='{trade_dt}' or ENDDATE = '19000101')
""")["SECODE"].unique().tolist() ORDER BY SECODE;
"""
else:
query = f"""
select SECODE from TQ_FD_TYPE
WHERE
ISVALID = 1 AND
BEGINDATE <= '{trade_dt}' AND
(ENDDATE>='{trade_dt}' or ENDDATE = '19000101')
ORDER BY SECODE;
"""
sec_codes = read_sql(query)["SECODE"].unique().tolist()
return sec_codes return sec_codes
...@@ -53,15 +64,15 @@ def fd_basicinfo(security_ids=None, trade_dt=None): ...@@ -53,15 +64,15 @@ def fd_basicinfo(security_ids=None, trade_dt=None):
if sec_id_strs: if sec_id_strs:
query = f""" query = f"""
select SECURITYID, FDNAME, SNAMECOMP, FSYMBOL, FDNATURE, INVESTSTYLE from TQ_FD_BASICINFO select SECODE as SECURITYID, FDNAME, SNAMECOMP, FSYMBOL, FDNATURE, INVESTSTYLE from TQ_FD_BASICINFO
WHERE WHERE
ISVALID = 1 AND ISVALID = 1 AND
SECURITYID in ({sec_id_strs}) AND SECODE in ({sec_id_strs}) AND
(LIQUENDDATE >= '{trade_dt}' or LIQUENDDATE = '19000101') (LIQUENDDATE >= '{trade_dt}' or LIQUENDDATE = '19000101')
""" """
else: else:
query = f""" query = f"""
select SECURITYID, FDNAME, SNAMECOMP, FSYMBOL, FDNATURE, INVESTSTYLE from TQ_FD_BASICINFO select SECODE as SECURITYID, FDNAME, SNAMECOMP, FSYMBOL, FDNATURE, INVESTSTYLE from TQ_FD_BASICINFO
WHERE WHERE
ISVALID = 1 AND ISVALID = 1 AND
(LIQUENDDATE >= '{trade_dt}' or LIQUENDDATE = '19000101') (LIQUENDDATE >= '{trade_dt}' or LIQUENDDATE = '19000101')
...@@ -127,35 +138,35 @@ def fd_assetportfolio(security_ids, report_dates_begin, report_dates_end=None): ...@@ -127,35 +138,35 @@ def fd_assetportfolio(security_ids, report_dates_begin, report_dates_end=None):
sec_id_strs = ",".join(["'" + s + "'" for s in security_ids]) sec_id_strs = ",".join(["'" + s + "'" for s in security_ids])
if report_dates_end: if report_dates_end:
query = f""" query = f"""
SELECT SECURITYID, REPORTDATE, BDRTO, CONVBDRTO, EQUITYINVERTO from TQ_FD_ASSETPORTFOLIO SELECT SECODE as SECURITYID, REPORTDATE, BDRTO, CONVBDRTO, EQUITYINVERTO from TQ_FD_ASSETPORTFOLIO
WHERE WHERE
REPORTDATE >= '{report_dates_begin}' AND REPORTDATE >= '{report_dates_begin}' AND
REPORTDATE <= '{report_dates_end}' AND REPORTDATE <= '{report_dates_end}' AND
ISVALID = 1 AND ISVALID = 1 AND
SECURITYID in ({sec_id_strs}) SECODE in ({sec_id_strs})
""" """
else: else:
query = f""" query = f"""
SELECT SECURITYID, REPORTDATE, BDRTO, CONVBDRTO, EQUITYINVERTO from TQ_FD_ASSETPORTFOLIO SELECT SECODE as SECURITYID, REPORTDATE, BDRTO, CONVBDRTO, EQUITYINVERTO from TQ_FD_ASSETPORTFOLIO
WHERE WHERE
REPORTDATE >= '{report_dates_begin}' AND REPORTDATE >= '{report_dates_begin}' AND
ISVALID = 1 AND ISVALID = 1 AND
SECURITYID in ({sec_id_strs}) SECODE in ({sec_id_strs})
""" """
return read_sql(query).sort_values("SECURITYID") return read_sql(query).sort_values("SECURITYID")
def fd_derieden(security_ids, trade_dt): def fd_qtfdnav(security_ids, trade_dt):
if isinstance(security_ids, str): if isinstance(security_ids, str):
sec_id_strs = security_ids sec_id_strs = security_ids
else: else:
sec_id_strs = ",".join(["'" + s + "'" for s in security_ids]) sec_id_strs = ",".join(["'" + s + "'" for s in security_ids])
query = f""" query = f"""
SELECT SECURITYID, UNITNAV, UNITACCNAV, REPAIRUNITNAV, NAVGRTD from TQ_FD_DERIVEDN SELECT SECODE as SECURITYID, UNITNAV, ACCUNITNAV from TQ_QT_FDNAV
WHERE WHERE
ENDDATE = '{trade_dt}' AND NAVDATE = '{trade_dt}' AND
ISVALID = 1 AND ISVALID = 1 AND
SECURITYID in ({sec_id_strs}) SECODE in ({sec_id_strs})
""" """
return read_sql(query).sort_values("SECURITYID") return read_sql(query).sort_values("SECURITYID")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment