Commit e75c5c34 authored by Dr.李's avatar Dr.李

more notebooks

parent cc5d32ca
This diff is collapsed.
......@@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 1,
"id": "25a5db3d-4c9d-46e8-bd5a-88cca84280ba",
"metadata": {},
"outputs": [],
......@@ -18,7 +18,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 2,
"id": "329e6a8c-4e60-43d7-8314-63cee4f9196a",
"metadata": {},
"outputs": [],
......@@ -33,7 +33,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 3,
"id": "74246462-2676-4817-8c89-3a024ed8e412",
"metadata": {},
"outputs": [],
......@@ -56,7 +56,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 4,
"id": "61270089-05d5-4396-829e-651118231b60",
"metadata": {},
"outputs": [],
......@@ -77,7 +77,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 5,
"id": "73250ba3-83f4-41fe-8e61-2869f7db8662",
"metadata": {},
"outputs": [],
......@@ -91,17 +91,17 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 7,
"id": "87566cc8-5684-4c03-b247-3fb9abf72cf6",
"metadata": {},
"outputs": [],
"source": [
"agg_port = pd.merge(agg_port, fd_basicinfo(agg_port.SECURITYID, current_date))"
"agg_port = pd.merge(agg_port, fd_basicinfo(agg_port.SECURITYID.tolist(), current_date))"
]
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 8,
"id": "89e23e81-3398-40ab-a410-584b659f5db1",
"metadata": {},
"outputs": [
......@@ -132,6 +132,8 @@
" <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",
......@@ -143,6 +145,8 @@
" <td>大成财富管理2020生命周期证券投资基金</td>\n",
" <td>None</td>\n",
" <td>090006</td>\n",
" <td>证券投资基金</td>\n",
" <td>稳健成长型</td>\n",
" </tr>\n",
" <tr>\n",
" <th>54</th>\n",
......@@ -152,6 +156,8 @@
" <td>国投瑞银融华债券型证券投资基金</td>\n",
" <td>None</td>\n",
" <td>121001</td>\n",
" <td>证券投资基金</td>\n",
" <td>收益型</td>\n",
" </tr>\n",
" <tr>\n",
" <th>62</th>\n",
......@@ -161,6 +167,8 @@
" <td>银河收益证券投资基金</td>\n",
" <td>None</td>\n",
" <td>151002</td>\n",
" <td>证券投资基金</td>\n",
" <td>稳健成长型</td>\n",
" </tr>\n",
" <tr>\n",
" <th>94</th>\n",
......@@ -170,6 +178,8 @@
" <td>南方宝元债券型基金</td>\n",
" <td>南方宝元债券</td>\n",
" <td>202101</td>\n",
" <td>证券投资基金</td>\n",
" <td>稳健成长型</td>\n",
" </tr>\n",
" <tr>\n",
" <th>95</th>\n",
......@@ -179,6 +189,8 @@
" <td>鹏华弘泰灵活配置混合型证券投资基金</td>\n",
" <td>鹏华弘泰灵活配置混合</td>\n",
" <td>206001</td>\n",
" <td>证券投资基金</td>\n",
" <td>稳健成长型</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
......@@ -188,6 +200,8 @@
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2067</th>\n",
......@@ -197,6 +211,8 @@
" <td>东方价值挖掘灵活配置混合型证券投资基金</td>\n",
" <td>东方价值挖掘灵活配置混合</td>\n",
" <td>004166</td>\n",
" <td>证券投资基金</td>\n",
" <td>稳健成长型</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2070</th>\n",
......@@ -206,6 +222,8 @@
" <td>易方达瑞富灵活配置混合型证券投资基金</td>\n",
" <td>易方达瑞富混合</td>\n",
" <td>001745</td>\n",
" <td>证券投资基金</td>\n",
" <td>稳健成长型</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2071</th>\n",
......@@ -215,6 +233,8 @@
" <td>易方达瑞富灵活配置混合型证券投资基金</td>\n",
" <td>易方达瑞富混合</td>\n",
" <td>001746</td>\n",
" <td>证券投资基金</td>\n",
" <td>稳健成长型</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2072</th>\n",
......@@ -224,6 +244,8 @@
" <td>南方安康混合型证券投资基金</td>\n",
" <td>None</td>\n",
" <td>004517</td>\n",
" <td>证券投资基金</td>\n",
" <td>稳健成长型</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2081</th>\n",
......@@ -233,10 +255,12 @@
" <td>易方达裕惠回报定期开放式混合型发起式证券投资基金</td>\n",
" <td>None</td>\n",
" <td>000436</td>\n",
" <td>证券投资基金</td>\n",
" <td>稳健成长型</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>508 rows × 6 columns</p>\n",
"<p>508 rows × 8 columns</p>\n",
"</div>"
],
"text/plain": [
......@@ -253,23 +277,23 @@
"2072 1030009813 21.400833 低权益仓位混合型基金 南方安康混合型证券投资基金 \n",
"2081 1030013275 7.011667 低权益仓位混合型基金 易方达裕惠回报定期开放式混合型发起式证券投资基金 \n",
"\n",
" SNAMECOMP FSYMBOL \n",
"40 None 090006 \n",
"54 None 121001 \n",
"62 None 151002 \n",
"94 南方宝元债券 202101 \n",
"95 鹏华弘泰灵活配置混合 206001 \n",
"... ... ... \n",
"2067 东方价值挖掘灵活配置混合 004166 \n",
"2070 易方达瑞富混合 001745 \n",
"2071 易方达瑞富混合 001746 \n",
"2072 None 004517 \n",
"2081 None 000436 \n",
" SNAMECOMP FSYMBOL FDNATURE INVESTSTYLE \n",
"40 None 090006 证券投资基金 稳健成长型 \n",
"54 None 121001 证券投资基金 收益型 \n",
"62 None 151002 证券投资基金 稳健成长型 \n",
"94 南方宝元债券 202101 证券投资基金 稳健成长型 \n",
"95 鹏华弘泰灵活配置混合 206001 证券投资基金 稳健成长型 \n",
"... ... ... ... ... \n",
"2067 东方价值挖掘灵活配置混合 004166 证券投资基金 稳健成长型 \n",
"2070 易方达瑞富混合 001745 证券投资基金 稳健成长型 \n",
"2071 易方达瑞富混合 001746 证券投资基金 稳健成长型 \n",
"2072 None 004517 证券投资基金 稳健成长型 \n",
"2081 None 000436 证券投资基金 稳健成长型 \n",
"\n",
"[508 rows x 6 columns]"
"[508 rows x 8 columns]"
]
},
"execution_count": 13,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
......@@ -280,7 +304,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 9,
"id": "a27e2473-ddf5-4883-bb50-6fe46914d3da",
"metadata": {},
"outputs": [
......@@ -342,7 +366,7 @@
"高权益仓位混合型基金 1205"
]
},
"execution_count": 14,
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
......
{
"cells": [
{
"cell_type": "code",
"execution_count": 4,
"id": "51382765-24b4-4e5e-a118-077b276e0774",
"metadata": {},
"outputs": [],
"source": [
"import datetime as dt\n",
"from utility import (\n",
" read_sql,\n",
" fd_basicinfo,\n",
" fd_typeclass,\n",
" nearest_report_date\n",
")\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "47939edc-07d2-4c8e-b061-187806e124ea",
"metadata": {},
"outputs": [],
"source": [
"# 获取回溯的报告日\n",
"\n",
"today = dt.datetime.today().strftime(\"%Y%m%d\")"
]
},
{
"cell_type": "code",
"execution_count": 11,
"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()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "7e1a0517-e3de-4ea7-ae3c-9c2292c63260",
"metadata": {},
"outputs": [],
"source": [
"basic_info = fd_basicinfo(security_ids)\n",
"type_info = fd_typeclass(security_ids)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "b0d0d48b-708b-447a-922b-500fbfb97600",
"metadata": {},
"outputs": [],
"source": [
"df = pd.merge(type_info[[\"SECURITYID\"]], basic_info, on=\"SECURITYID\")"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "5ccf2dc7-fea9-4d52-b15d-e8ff55fac3dc",
"metadata": {},
"outputs": [],
"source": [
"# 分类\n",
"df.loc[(df[\"FDNATURE\"] == \"ETF\"), \"货币型(子类)\"] = \"场内货币型基金\"\n",
"df.loc[(df[\"FDNATURE\"] != \"ETF\"), \"货币型(子类)\"] = \"场外货币型基金\""
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "9d34507e-9efd-479a-8b25-a095de5a552c",
"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",
" </tr>\n",
" <tr>\n",
" <th>货币型(子类)</th>\n",
" <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>44</td>\n",
" <td>44</td>\n",
" <td>42</td>\n",
" <td>44</td>\n",
" <td>44</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",
" </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"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.groupby(\"货币型(子类)\").count()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c46e44f3-62a7-4409-a276-e7493cbb98aa",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "7e30b869-ddb2-4b75-9918-6931b7c00b05",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:root] *",
"language": "python",
"name": "conda-root-py"
},
"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.8.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "76b46662-651d-4bcd-b554-f116051cf297",
"metadata": {},
"outputs": [],
"source": [
"import datetime as dt\n",
"from utility import (\n",
" read_sql,\n",
" fd_basicinfo,\n",
" fd_typeclass,\n",
" nearest_report_date\n",
")\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "f5d4b805-d5a3-4b4c-8429-7044e9bef831",
"metadata": {},
"outputs": [],
"source": [
"# 获取回溯的报告日\n",
"\n",
"today = dt.datetime.today().strftime(\"%Y%m%d\")"
]
},
{
"cell_type": "code",
"execution_count": 46,
"id": "72d3f785-aee7-44d9-a393-3abbdb4d60a4",
"metadata": {},
"outputs": [],
"source": [
"# 获取所有目标基金(清算结束日期晚于当前日)\n",
"\n",
"security_ids = read_sql(f\"\"\"\n",
"select SECURITYID from TQ_FD_TYPECLASS \n",
"WHERE\n",
" ISVALID = 1 AND\n",
" (ENDDATE>='{today}' or ENDDATE = '19000101') \n",
"ORDER BY SECURITYID;\n",
"\"\"\")[\"SECURITYID\"].unique().tolist()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "f5f5cc7d-c2d4-4c7f-b8a9-dd133407f9c6",
"metadata": {},
"outputs": [],
"source": [
"basic_info = fd_basicinfo(security_ids)\n",
"type_info = fd_typeclass(security_ids)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "52607b95-9d62-4f68-8256-984827dd0bea",
"metadata": {},
"outputs": [],
"source": [
"df = pd.merge(type_info, basic_info, on=\"SECURITYID\")"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "60fe66ee-a8d3-4a33-8c5a-555f68d9758c",
"metadata": {},
"outputs": [],
"source": [
"# 分类\n",
"df.loc[(df[\"INVESTSTYLE\"] == \"商品型\") & (df[\"L1CODE\"] != 6), \"另类投资型(子类)\"] = \"商品型基金\"\n",
"df.loc[(df[\"L3NAME\"] == \"对冲策略基金\"), \"另类投资型(子类)\"] = \"量化对冲基金\""
]
},
{
"cell_type": "code",
"execution_count": 45,
"id": "1bb62bc7-2515-415a-8eec-087d2d1787b6",
"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>L1CODE</th>\n",
" <th>L1NAME</th>\n",
" <th>L2CODE</th>\n",
" <th>L2NAME</th>\n",
" <th>L3CODE</th>\n",
" <th>L3NAME</th>\n",
" <th>FDNAME</th>\n",
" <th>SNAMECOMP</th>\n",
" <th>FSYMBOL</th>\n",
" <th>FDNATURE</th>\n",
" <th>INVESTSTYLE</th>\n",
" </tr>\n",
" <tr>\n",
" <th>另类投资型(子类)</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <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>29</td>\n",
" <td>29</td>\n",
" <td>29</td>\n",
" <td>29</td>\n",
" <td>29</td>\n",
" <td>29</td>\n",
" <td>29</td>\n",
" <td>29</td>\n",
" <td>17</td>\n",
" <td>29</td>\n",
" <td>29</td>\n",
" <td>29</td>\n",
" </tr>\n",
" <tr>\n",
" <th>量化对冲基金</th>\n",
" <td>17</td>\n",
" <td>17</td>\n",
" <td>17</td>\n",
" <td>17</td>\n",
" <td>17</td>\n",
" <td>17</td>\n",
" <td>17</td>\n",
" <td>17</td>\n",
" <td>9</td>\n",
" <td>17</td>\n",
" <td>17</td>\n",
" <td>17</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" SECURITYID L1CODE L1NAME L2CODE L2NAME L3CODE L3NAME FDNAME \\\n",
"另类投资型(子类) \n",
"商品型基金 29 29 29 29 29 29 29 29 \n",
"量化对冲基金 17 17 17 17 17 17 17 17 \n",
"\n",
" SNAMECOMP FSYMBOL FDNATURE INVESTSTYLE \n",
"另类投资型(子类) \n",
"商品型基金 17 29 29 29 \n",
"量化对冲基金 9 17 17 17 "
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.groupby(\"另类投资型(子类)\").count()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3ba8793e-d648-4dc0-99ef-731a8c97f50e",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:root] *",
"language": "python",
"name": "conda-root-py"
},
"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.8.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "b81e5b9e-b8f5-4198-b98c-2e26f025875c",
"metadata": {},
"outputs": [],
"source": [
"import datetime as dt\n",
"from utility import (\n",
" read_sql,\n",
" fd_basicinfo,\n",
" fd_typeclass,\n",
" nearest_report_date\n",
")\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "8bf4331c-c1db-47b4-b72d-10d5ccb72657",
"metadata": {},
"outputs": [],
"source": [
"# 获取回溯的报告日\n",
"\n",
"today = dt.datetime.today().strftime(\"%Y%m%d\")"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "d228ec88-a55b-4451-8a69-1a0e490b9161",
"metadata": {},
"outputs": [],
"source": [
"# 获取所有目标QDII基金(清算结束日期晚于当前日)\n",
"\n",
"security_ids = read_sql(f\"\"\"\n",
"select SECURITYID from TQ_FD_TYPECLASS \n",
"WHERE\n",
" ISVALID = 1 AND\n",
" L1CODE = 6 AND\n",
" (ENDDATE>='{today}' or ENDDATE = '19000101') \n",
"ORDER BY SECURITYID;\n",
"\"\"\")[\"SECURITYID\"].unique().tolist()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "7763ee34-dbba-4297-b2d8-16fc98be8a3b",
"metadata": {},
"outputs": [],
"source": [
"basic_info = fd_basicinfo(security_ids)\n",
"type_info = fd_typeclass(security_ids)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "e12d8f3b-0570-40db-9ec3-d6804b78c686",
"metadata": {},
"outputs": [],
"source": [
"df = pd.merge(type_info, basic_info, on=\"SECURITYID\")"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "b3f87023-d068-4014-975c-22db615c3273",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array(['QDII股票型基金', 'QDII混合基金', 'QDII全球股票型基金', 'QDII债券基金', 'QDII指数股票型基金',\n",
" 'QDII商品基金', 'QDII房地产信托基金', 'QDII分级子基金'], dtype=object)"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.L3NAME.unique()"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "0efd51eb-a03c-440b-b083-a36df52f9185",
"metadata": {},
"outputs": [],
"source": [
"# 分类\n",
"df.loc[(df[\"L3NAME\"].isin([\"QDII股票型基金\", \"QDII全球股票型基金\", \"QDII指数股票型基金\"])), \"QDII型(子类)\"] = \"QDII股票型基金\"\n",
"df.loc[df[\"L3NAME\"] == \"QDII债券基金\", \"QDII型(子类)\"] = \"QDII债券型基金\"\n",
"df.loc[(df[\"L3NAME\"].isin([\"QDII商品基金\", \"QDII房地产信托基金\"])), \"QDII型(子类)\"] = \"QDII另类投资基金\"\n",
"df.loc[(df[\"L3NAME\"].isin([\"QDII混合基金\", \"QDII分级子基金\"])), \"QDII型(子类)\"] = \"QDII混合型基金\""
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "850b9707-8849-48b5-9b39-9111ab78ccc1",
"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>L1CODE</th>\n",
" <th>L1NAME</th>\n",
" <th>L2CODE</th>\n",
" <th>L2NAME</th>\n",
" <th>L3CODE</th>\n",
" <th>L3NAME</th>\n",
" <th>FDNAME</th>\n",
" <th>SNAMECOMP</th>\n",
" <th>FSYMBOL</th>\n",
" <th>FDNATURE</th>\n",
" <th>INVESTSTYLE</th>\n",
" </tr>\n",
" <tr>\n",
" <th>QDII型(子类)</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>QDII债券型基金</th>\n",
" <td>39</td>\n",
" <td>39</td>\n",
" <td>39</td>\n",
" <td>39</td>\n",
" <td>39</td>\n",
" <td>39</td>\n",
" <td>39</td>\n",
" <td>39</td>\n",
" <td>38</td>\n",
" <td>39</td>\n",
" <td>39</td>\n",
" <td>39</td>\n",
" </tr>\n",
" <tr>\n",
" <th>QDII另类投资基金</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>19</td>\n",
" <td>19</td>\n",
" <td>9</td>\n",
" <td>19</td>\n",
" <td>19</td>\n",
" <td>19</td>\n",
" </tr>\n",
" <tr>\n",
" <th>QDII混合型基金</th>\n",
" <td>31</td>\n",
" <td>31</td>\n",
" <td>31</td>\n",
" <td>31</td>\n",
" <td>31</td>\n",
" <td>31</td>\n",
" <td>31</td>\n",
" <td>31</td>\n",
" <td>13</td>\n",
" <td>31</td>\n",
" <td>31</td>\n",
" <td>31</td>\n",
" </tr>\n",
" <tr>\n",
" <th>QDII股票型基金</th>\n",
" <td>87</td>\n",
" <td>87</td>\n",
" <td>87</td>\n",
" <td>87</td>\n",
" <td>87</td>\n",
" <td>87</td>\n",
" <td>87</td>\n",
" <td>87</td>\n",
" <td>55</td>\n",
" <td>87</td>\n",
" <td>87</td>\n",
" <td>87</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" SECURITYID L1CODE L1NAME L2CODE L2NAME L3CODE L3NAME \\\n",
"QDII型(子类) \n",
"QDII债券型基金 39 39 39 39 39 39 39 \n",
"QDII另类投资基金 19 19 19 19 19 19 19 \n",
"QDII混合型基金 31 31 31 31 31 31 31 \n",
"QDII股票型基金 87 87 87 87 87 87 87 \n",
"\n",
" FDNAME SNAMECOMP FSYMBOL FDNATURE INVESTSTYLE \n",
"QDII型(子类) \n",
"QDII债券型基金 39 38 39 39 39 \n",
"QDII另类投资基金 19 9 19 19 19 \n",
"QDII混合型基金 31 13 31 31 31 \n",
"QDII股票型基金 87 55 87 87 87 "
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.groupby(\"QDII型(子类)\").count()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0f3aec26-468c-4b17-b9c5-75119afcf005",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:root] *",
"language": "python",
"name": "conda-root-py"
},
"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.8.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
This diff is collapsed.
......@@ -24,25 +24,35 @@ def nearest_report_date(date):
return dt.date(last_year, q, last).strftime("%Y%m%d")
def fd_basicinfo(security_ids, trade_dt=None):
def fd_basicinfo(security_ids=None, trade_dt=None):
if not trade_dt:
trade_dt = dt.datetime.today().strftime("%Y%m%d")
else:
trade_dt = trade_dt.replace("-", "")
if isinstance(security_ids, str):
sec_id_strs = security_ids.split(",")
sec_id_strs = security_ids
elif not security_ids:
sec_id_strs = None
else:
sec_id_strs = ",".join(["'" + s + "'" for s in security_ids])
engine = sa.create_engine(CONN, connect_args={"charset": "GBK"})
query = f"""
select SECURITYID, FDNAME, SNAMECOMP, FSYMBOL from TQ_FD_BASICINFO
WHERE
ISVALID = 1 AND
SECURITYID in ({sec_id_strs}) AND
(LIQUENDDATE >= '{trade_dt}' or LIQUENDDATE = '19000101')
"""
if sec_id_strs:
query = f"""
select SECURITYID, FDNAME, SNAMECOMP, FSYMBOL, FDNATURE, INVESTSTYLE from TQ_FD_BASICINFO
WHERE
ISVALID = 1 AND
SECURITYID 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
WHERE
ISVALID = 1 AND
(LIQUENDDATE >= '{trade_dt}' or LIQUENDDATE = '19000101')
"""
return pd.read_sql(query, con=engine)
......@@ -53,13 +63,13 @@ def fd_typeclass(security_ids, trade_dt=None):
trade_dt = trade_dt.replace("-", "")
if isinstance(security_ids, str):
sec_id_strs = security_ids.split(",")
sec_id_strs = security_ids
else:
sec_id_strs = ",".join(["'" + s + "'" for s in security_ids])
engine = sa.create_engine(CONN, connect_args={"charset": "GBK"})
query = f"""
select SECURITYID, L1CODE, L1NAME, L2CODE, L2NAME from TQ_FD_TYPECLASS
select SECURITYID, L1CODE, L1NAME, L2CODE, L2NAME, L3CODE, L3NAME from TQ_FD_TYPECLASS
WHERE
ISVALID = 1 AND
SECURITYID in ({sec_id_strs})
......
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