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