Commit 041faa29 authored by Dr.李's avatar Dr.李

change category codes

parent 382ae34b
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 2,
"id": "51382765-24b4-4e5e-a118-077b276e0774",
"metadata": {},
"outputs": [],
......@@ -21,7 +21,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 3,
"id": "47939edc-07d2-4c8e-b061-187806e124ea",
"metadata": {},
"outputs": [],
......@@ -33,52 +33,32 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 4,
"id": "9a596482-dd98-49dc-b717-c17177f2cd64",
"metadata": {},
"outputs": [],
"source": [
"# 获取所有目标货币型基金(清算结束日期晚于当前日)\n",
"\n",
"security_ids = fd_alive_funds(today, 204)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "7e1a0517-e3de-4ea7-ae3c-9c2292c63260",
"metadata": {},
"outputs": [],
"source": [
"basic_info = fd_basicinfo(security_ids)\n",
"type_info = fd_typeclass(security_ids)"
"security_info = fd_alive_funds(today, 2205)\n",
"security_ids = security_info.SECURITYID.unique().tolist()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "b0d0d48b-708b-447a-922b-500fbfb97600",
"metadata": {},
"outputs": [],
"source": [
"df = pd.merge(type_info[[\"SECURITYID\"]], basic_info, on=\"SECURITYID\")"
]
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 9,
"id": "5ccf2dc7-fea9-4d52-b15d-e8ff55fac3dc",
"metadata": {},
"outputs": [],
"source": [
"# 分类\n",
"df.loc[(df[\"FDNATURE\"] == \"ETF\"), \"货币型(子类)\"] = \"场内货币型基金\"\n",
"df.loc[(df[\"FDNATURE\"] != \"ETF\"), \"货币型(子类)\"] = \"场外货币型基金\""
"security_info.loc[(security_info.CLASSCODE.str.startswith(\"220502\")), \"货币型(子类)\"] = \"场内货币型基金\"\n",
"security_info.loc[(~security_info.CLASSCODE.str.startswith(\"220502\")), \"货币型(子类)\"] = \"场外货币型基金\""
]
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 10,
"id": "9d34507e-9efd-479a-8b25-a095de5a552c",
"metadata": {},
"outputs": [
......@@ -104,11 +84,9 @@
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>SECURITYID</th>\n",
" <th>FDNAME</th>\n",
" <th>SNAMECOMP</th>\n",
" <th>FSYMBOL</th>\n",
" <th>FDNATURE</th>\n",
" <th>INVESTSTYLE</th>\n",
" <th>BEGINDATE</th>\n",
" <th>ENDDATE</th>\n",
" <th>CLASSCODE</th>\n",
" </tr>\n",
" <tr>\n",
" <th>货币型(子类)</th>\n",
......@@ -116,57 +94,43 @@
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>场内货币型基金</th>\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",
" <td>41</td>\n",
" <td>41</td>\n",
" <td>41</td>\n",
" <td>41</td>\n",
" </tr>\n",
" <tr>\n",
" <th>场外货币型基金</th>\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",
" <td>622</td>\n",
" <td>622</td>\n",
" <td>622</td>\n",
" <td>622</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" SECURITYID FDNAME SNAMECOMP FSYMBOL FDNATURE INVESTSTYLE\n",
"货币型(子类) \n",
"场内货币型基金 19 19 19 19 19 19\n",
"场外货币型基金 542 542 496 542 542 542"
" SECURITYID BEGINDATE ENDDATE CLASSCODE\n",
"货币型(子类) \n",
"场内货币型基金 41 41 41 41\n",
"场外货币型基金 622 622 622 622"
]
},
"execution_count": 14,
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.groupby(\"货币型(子类)\").count()"
"security_info.groupby(\"货币型(子类)\").count()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c46e44f3-62a7-4409-a276-e7493cbb98aa",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
......
This diff is collapsed.
This diff is collapsed.
......@@ -33,232 +33,60 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": 4,
"id": "004a8f9f-4011-48c6-a5dd-327cce42de51",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"13"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 获取所有目标基金(清算结束日期晚于当前日)\n",
"\n",
"security_ids = fd_alive_funds(today, \"2210\")"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "acf00858-6782-4ecb-8a87-9045810ce589",
"metadata": {},
"outputs": [],
"source": [
"basic_info = fd_basicinfo(security_ids)"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "08bfc149-90e5-405d-a1f2-6ec750c26f9e",
"metadata": {},
"outputs": [],
"source": [
"df = basic_info[basic_info.FDNATURE == 'FOF']"
"security_info = fd_alive_funds(today, 2210)\n",
"security_ids = security_info.SECURITYID.unique().tolist()\n",
"len(security_ids)"
]
},
{
"cell_type": "code",
"execution_count": 32,
"execution_count": 7,
"id": "fc897e0e-46f1-48a2-be9a-6381086c94bf",
"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>SECURITYID</th>\n",
" <th>FDNAME</th>\n",
" <th>SNAMECOMP</th>\n",
" <th>FSYMBOL</th>\n",
" <th>FDNATURE</th>\n",
" <th>INVESTSTYLE</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1030010449</td>\n",
" <td>南方全天候策略混合型基金中基金(FOF)</td>\n",
" <td>南方全天候策略混合(FOF)</td>\n",
" <td>005215</td>\n",
" <td>FOF</td>\n",
" <td>稳健成长型</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>1030010450</td>\n",
" <td>南方全天候策略混合型基金中基金(FOF)</td>\n",
" <td>南方全天候策略混合(FOF)</td>\n",
" <td>005216</td>\n",
" <td>FOF</td>\n",
" <td>稳健成长型</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>1030010443</td>\n",
" <td>华夏聚惠稳健目标风险混合型基金中基金(FOF)</td>\n",
" <td>华夏聚惠(FOF)</td>\n",
" <td>005218</td>\n",
" <td>FOF</td>\n",
" <td>稳健成长型</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>1030010444</td>\n",
" <td>华夏聚惠稳健目标风险混合型基金中基金(FOF)</td>\n",
" <td>华夏聚惠(FOF)</td>\n",
" <td>005219</td>\n",
" <td>FOF</td>\n",
" <td>稳健成长型</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>1030010446</td>\n",
" <td>嘉实领航资产配置混合型基金中基金(FOF)</td>\n",
" <td>嘉实领航资产配置混合(FOF)</td>\n",
" <td>005156</td>\n",
" <td>FOF</td>\n",
" <td>稳健成长型</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>1030010447</td>\n",
" <td>嘉实领航资产配置混合型基金中基金(FOF)</td>\n",
" <td>嘉实领航资产配置混合(FOF)</td>\n",
" <td>005157</td>\n",
" <td>FOF</td>\n",
" <td>稳健成长型</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>1030010441</td>\n",
" <td>海富通聚优精选混合型基金中基金(FOF)</td>\n",
" <td>None</td>\n",
" <td>005220</td>\n",
" <td>FOF</td>\n",
" <td>稳健成长型</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>1030010451</td>\n",
" <td>建信福泽安泰混合型基金中基金(FOF)</td>\n",
" <td>None</td>\n",
" <td>005217</td>\n",
" <td>FOF</td>\n",
" <td>稳健成长型</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>1030010459</td>\n",
" <td>泰达宏利全能优选混合型基金中基金(FOF)</td>\n",
" <td>泰达宏利全能混合(FOF)</td>\n",
" <td>005221</td>\n",
" <td>FOF</td>\n",
" <td>稳健成长型</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>1030010460</td>\n",
" <td>泰达宏利全能优选混合型基金中基金(FOF)</td>\n",
" <td>泰达宏利全能混合(FOF)</td>\n",
" <td>005222</td>\n",
" <td>FOF</td>\n",
" <td>稳健成长型</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>1030011412</td>\n",
" <td>中融量化精选混合型基金中基金(FOF)</td>\n",
" <td>中融量化精选FOF</td>\n",
" <td>005758</td>\n",
" <td>FOF</td>\n",
" <td>稳健成长型</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>1030011413</td>\n",
" <td>中融量化精选混合型基金中基金(FOF)</td>\n",
" <td>中融量化精选FOF</td>\n",
" <td>005759</td>\n",
" <td>FOF</td>\n",
" <td>稳健成长型</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>1030011474</td>\n",
" <td>前海开源裕源混合型基金中基金(FOF)</td>\n",
" <td>None</td>\n",
" <td>005809</td>\n",
" <td>FOF</td>\n",
" <td>稳健成长型</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" SECURITYID FDNAME SNAMECOMP FSYMBOL FDNATURE \\\n",
"0 1030010449 南方全天候策略混合型基金中基金(FOF) 南方全天候策略混合(FOF) 005215 FOF \n",
"1 1030010450 南方全天候策略混合型基金中基金(FOF) 南方全天候策略混合(FOF) 005216 FOF \n",
"2 1030010443 华夏聚惠稳健目标风险混合型基金中基金(FOF) 华夏聚惠(FOF) 005218 FOF \n",
"3 1030010444 华夏聚惠稳健目标风险混合型基金中基金(FOF) 华夏聚惠(FOF) 005219 FOF \n",
"4 1030010446 嘉实领航资产配置混合型基金中基金(FOF) 嘉实领航资产配置混合(FOF) 005156 FOF \n",
"5 1030010447 嘉实领航资产配置混合型基金中基金(FOF) 嘉实领航资产配置混合(FOF) 005157 FOF \n",
"6 1030010441 海富通聚优精选混合型基金中基金(FOF) None 005220 FOF \n",
"7 1030010451 建信福泽安泰混合型基金中基金(FOF) None 005217 FOF \n",
"8 1030010459 泰达宏利全能优选混合型基金中基金(FOF) 泰达宏利全能混合(FOF) 005221 FOF \n",
"9 1030010460 泰达宏利全能优选混合型基金中基金(FOF) 泰达宏利全能混合(FOF) 005222 FOF \n",
"10 1030011412 中融量化精选混合型基金中基金(FOF) 中融量化精选FOF 005758 FOF \n",
"11 1030011413 中融量化精选混合型基金中基金(FOF) 中融量化精选FOF 005759 FOF \n",
"12 1030011474 前海开源裕源混合型基金中基金(FOF) None 005809 FOF \n",
"\n",
" INVESTSTYLE \n",
"0 稳健成长型 \n",
"1 稳健成长型 \n",
"2 稳健成长型 \n",
"3 稳健成长型 \n",
"4 稳健成长型 \n",
"5 稳健成长型 \n",
"6 稳健成长型 \n",
"7 稳健成长型 \n",
"8 稳健成长型 \n",
"9 稳健成长型 \n",
"10 稳健成长型 \n",
"11 稳健成长型 \n",
"12 稳健成长型 "
"['1030010441',\n",
" '1030010443',\n",
" '1030010444',\n",
" '1030010446',\n",
" '1030010447',\n",
" '1030010449',\n",
" '1030010450',\n",
" '1030010451',\n",
" '1030010459',\n",
" '1030010460',\n",
" '1030011412',\n",
" '1030011413',\n",
" '1030011474']"
]
},
"execution_count": 32,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
"security_ids"
]
},
{
......@@ -286,7 +114,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.12"
"version": "3.9.7"
}
},
"nbformat": 4,
......
......@@ -72,12 +72,24 @@ def nearest_report_date(date):
def fd_alive_funds(trade_dt, class_code=None):
if class_code:
if isinstance(class_code, str) or isinstance(class_code, int):
condition = f" CLASSCODE like '{class_code}%' AND "
else:
condition = []
for c in class_code:
condition.append(f" CLASSCODE like '{c}%' ")
condition = "OR".join(condition)
condition = "(" + condition + ") AND"
query = f"""
select SECODE FROM TQ_FD_TYPE
select SECODE as SECURITYID, BEGINDATE, ENDDATE, CLASSCODE FROM TQ_FD_TYPE
WHERE
ISVALID = 1 AND
CLASSCODE like '{class_code}%' AND
{condition}
TYPESTYLE = '22' AND
BEGINDATE <= '{trade_dt}' AND
(ENDDATE>='{trade_dt}' or ENDDATE = '19000101')
......@@ -85,7 +97,7 @@ def fd_alive_funds(trade_dt, class_code=None):
"""
else:
query = f"""
select SECODE FROM TQ_FD_TYPE
select SECODE as SECURITYID,BEGINDATE, ENDDATE, CLASSCODE FROM TQ_FD_TYPE
WHERE
ISVALID = 1 AND
BEGINDATE <= '{trade_dt}' AND
......@@ -93,8 +105,7 @@ def fd_alive_funds(trade_dt, class_code=None):
(ENDDATE>='{trade_dt}' or ENDDATE = '19000101')
ORDER BY SECODE;
"""
sec_codes = read_sql(query)["SECODE"].unique().tolist()
return sec_codes
return read_sql(query)
def fd_basicinfo(security_ids=None, trade_dt=None):
......
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